Permalink
Browse files

Improve properties system

* Now works when you look from camera/driving a vehicle
* Fixed some issues with "Drive" property and cameras.
* Added language string for "Undone_KeepUpright"
* Removed undo from keep upright property. You are supposed to use
properties to disable keep upright.
  • Loading branch information...
1 parent a27fd92 commit b556009b5791f9a21ba7e05b970b08f2c17cc7ed @robotboy655 robotboy655 committed Apr 13, 2014
@@ -144,6 +144,12 @@ if ( SERVER ) then
-- The camera was deleted or something - return false to remove this entry
if ( !IsValid( ent ) ) then return false end
if ( !IsValid( pl ) ) then return false end
+
+ -- Something else changed players view entity
+ if ( pl.UsingCamera && pl.UsingCamera == ent && pl:GetViewEntity() != ent ) then
+ pl.UsingCamera = nil
+ ent.UsingPlayer = nil
+ end
if ( pl.UsingCamera && pl.UsingCamera == ent ) then
@@ -10,8 +10,7 @@ properties.Add( "drive",
Filter = function( self, ent, ply )
if ( !IsValid( ent ) || !IsValid( ply ) ) then return false end
- if ( ent:IsPlayer() ) then return false end
- if ( !IsValid( ent ) ) then return false end
+ if ( ent:IsPlayer() || IsValid( ply:GetVehicle() ) ) then return false end
if ( !gamemode.Call( "CanProperty", ply, "drive", ent ) ) then return false end
if ( !gamemode.Call( "CanDrive", ply, ent ) ) then return false end
@@ -45,4 +44,4 @@ properties.Add( "drive",
end
-});
+})
@@ -34,37 +34,22 @@ properties.Add( "keepupright",
if ( ent:GetClass() != "prop_physics" ) then return false end
if ( ent:GetNWBool( "IsUpright" ) ) then return end
if ( !self:Filter( ent, player ) ) then return end
-
+
local Phys = ent:GetPhysicsObjectNum( 0 )
if ( !IsValid( Phys ) ) then return end
local constraint = constraint.Keepupright( ent, Phys:GetAngles(), 0, 999999 )
if ( constraint ) then
-
- undo.Create( "KeepUpright" )
-
- undo.AddEntity( constraint )
- undo.SetPlayer( player )
-
- undo.AddFunction( function()
-
- if ( IsValid( ent ) ) then
- ent:SetNWBool( "IsUpright", false )
- end
-
- end )
-
- undo.Finish()
-
+
player:AddCleanup( "constraints", constraint )
ent:SetNWBool( "IsUpright", true )
end
end
-});
+})
properties.Add( "keepupright_stop",
@@ -103,4 +88,4 @@ properties.Add( "keepupright_stop",
end
-});
+})
@@ -1,22 +1,22 @@
module( "properties", package.seeall )
-local meta =
-{
- MsgStart = function( self )
+local meta = {
+ MsgStart = function( self )
- net.Start( "properties" )
- net.WriteUInt( util.NetworkStringToID( self.InternalName ), 32 )
- end,
-
- MsgEnd = function( self )
+ net.Start( "properties" )
+ net.WriteUInt( util.NetworkStringToID( self.InternalName ), 32 )
- net.SendToServer()
-
- end
+ end,
+
+ MsgEnd = function( self )
+
+ net.SendToServer()
+
+ end
}
-meta.__index = meta;
+meta.__index = meta
List = {}
-- .MenuLabel [string] Label to show on opened menu
@@ -49,7 +49,7 @@ local function AddToggleOption( data, menu, ent, ply, tr )
local option = menu:AddOption( data.MenuLabel, function() data:Action( ent, tr ) end )
option:SetChecked( data:Checked( ent, ply ) )
option:SetZPos( 501 )
- return option;
+ return option
end
@@ -71,7 +71,7 @@ local function AddOption( data, menu, ent, ply, tr )
data.MenuOpen( data, option, ent, tr )
end
- return option;
+ return option
end
@@ -96,14 +96,15 @@ end
function GetHovered( eyepos, eyevec )
- local trace = util.TraceLine(
- {
- start = eyepos,
- endpos = eyepos + eyevec * 1024,
- filter = LocalPlayer()
- }
- )
-
+ local filter = { LocalPlayer():GetViewEntity() }
+ if ( LocalPlayer():GetViewEntity() == LocalPlayer() && IsValid( LocalPlayer():GetVehicle() ) ) then table.insert( filter, LocalPlayer():GetVehicle() ) end
+
+ local trace = util.TraceLine( {
+ start = eyepos,
+ endpos = eyepos + eyevec * 1024,
+ filter = filter
+ } )
+
if ( !trace.Hit ) then return end
if ( !IsValid( trace.Entity ) ) then return end
@@ -127,19 +128,19 @@ if ( SERVER ) then
util.AddNetworkString( "properties" )
net.Receive( "properties", function( len, client )
+
+ local i = net.ReadUInt( 32 )
+ local name = util.NetworkIDToString( i )
+
+ if ( !name ) then return end
+ if ( !IsValid( client ) ) then return end
+
+ local prop = List[ name ]
+ if ( !prop ) then return end
+ if ( !prop.Receive ) then return end
+
+ prop:Receive( len, client )
- local i = net.ReadUInt( 32 )
- local name = util.NetworkIDToString( i )
-
- if ( !name ) then return end
- if ( !IsValid( client ) ) then return end
-
- local prop = List[ name ]
- if ( !prop ) then return end
- if ( !prop.Receive ) then return end
-
- prop:Receive( len, client );
-
end )
end
@@ -148,7 +149,7 @@ if ( CLIENT ) then
function HaloThink()
- local ent = properties.GetHovered( LocalPlayer():EyePos(), LocalPlayer():GetAimVector() )
+ local ent = properties.GetHovered( EyePos(), LocalPlayer():GetAimVector() )
if ( !IsValid( ent ) ) then return end
local c = Color( 255, 255, 255, 255 )
@@ -170,7 +171,7 @@ if ( CLIENT ) then
OnScreenClick( EyePos(), vector )
end
- end );
+ end )
--
-- Hook the GUIMousePressed call, which is called when the client clicks on the
@@ -198,7 +199,6 @@ if ( CLIENT ) then
end
- end );
-
+ end )
-end
+end
Binary file not shown.

0 comments on commit b556009

Please sign in to comment.