From 8e27851b9cc9db438203d1ccc436a689aefd22b8 Mon Sep 17 00:00:00 2001 From: Garrett Brown Date: Mon, 28 Sep 2020 13:47:17 -0400 Subject: [PATCH] Some cleanup first --- lua/advdupe2/sv_clipboard.lua | 54 +++++++++++----------- lua/advdupe2/sv_misc.lua | 87 ++++------------------------------- 2 files changed, 35 insertions(+), 106 deletions(-) diff --git a/lua/advdupe2/sv_clipboard.lua b/lua/advdupe2/sv_clipboard.lua index 178e63f..d3543f9 100644 --- a/lua/advdupe2/sv_clipboard.lua +++ b/lua/advdupe2/sv_clipboard.lua @@ -59,9 +59,9 @@ end Returns: enttable ]] -/*--------------------------------------------------------- +--[[--------------------------------------------------------- Returns a copy of the passed entity's table ----------------------------------------------------------*/ +---------------------------------------------------------]] local function CopyEntTable( Ent, Offset ) -- Filter duplicator blocked entities out. if Ent.DoNotDuplicate then return nil end @@ -218,8 +218,8 @@ local function CopyEntTable( Ent, Offset ) Tab.DT = Ent:GetNetworkVars() end - // Make this function on your SENT if you want to modify the - // returned table specifically for your entity. + -- Make this function on your SENT if you want to modify the + -- returned table specifically for your entity. if Ent.OnEntityCopyTableFinish then local status, valid = pcall(Ent.OnEntityCopyTableFinish, Ent, Tab) if(not status)then @@ -428,14 +428,14 @@ function AdvDupe2.duplicator.AreaCopy( Entities, Offset, CopyOutside ) for _, Constraint in pairs( Constraints ) do ConstTable, EntTab = CopyConstraintTable( table.Copy(Constraint:GetTable()), Offset ) - //If the entity is constrained to an entity outside of the area box, don't copy the constraint. + --If the entity is constrained to an entity outside of the area box, don't copy the constraint. if(not CopyOutside)then add = true for k,v in pairs(EntTab)do if(not Entities[v:EntIndex()])then add=false end end if(add)then ConstraintTable[_] = ConstTable end - else //Copy entities and constraints outside of the box that are constrained to entities inside the box + else --Copy entities and constraints outside of the box that are constrained to entities inside the box ConstraintTable[_] = ConstTable for k,v in pairs(EntTab)do Copy(v, EntTable, ConstraintTable, Offset) @@ -459,7 +459,7 @@ local function CreateConstraintFromTable(Constraint, EntityList, EntityTable, Pl local first --Ent1 or Ent in the constraint's table local second --Any other Ent that is not Ent1 or Ent - + -- Build the argument list for the Constraint's spawn function local Args = {} local Val @@ -606,7 +606,7 @@ local function CreateConstraintFromTable(Constraint, EntityList, EntityTable, Pl Ent.BuildDupeInfo = table.Copy(Constraint.BuildDupeInfo) - //Move the entities back after constraining them + --Move the entities back after constraining them if(EntityTable)then if(first~=nil)then first:SetPos(EntityTable[firstindex].BuildDupeInfo.PosReset) @@ -640,7 +640,7 @@ local function CreateConstraintFromTable(Constraint, EntityList, EntityTable, Pl end end - if(Ent and Ent.length)then Ent.length = Constraint["length"] end //Fix for weird bug with ropes + if(Ent and Ent.length)then Ent.length = Constraint["length"] end --Fix for weird bug with ropes return Ent end @@ -799,7 +799,7 @@ local function MakeProp(Player, Pos, Ang, Model, PhysicsObject, Data) Data.Angle = Ang Data.Model = Model Data.Frozen = true - // Make sure this is allowed + -- Make sure this is allowed if( Player )then if ( not gamemode.Call( "PlayerSpawnProp", Player, Model ) ) then return false end end @@ -851,8 +851,8 @@ local function CreateEntityFromTable(EntTable, Player) local status, valid local GENERIC = false - // This class is unregistered. Instead of failing try using a generic - // Duplication function to make a new copy. + -- This class is unregistered. Instead of failing try using a generic + -- Duplication function to make a new copy. if (not EntityClass) then GENERIC = true sent = true @@ -880,13 +880,13 @@ local function CreateEntityFromTable(EntTable, Player) if(not GENERIC)then - // Build the argument list for the Entitie's spawn function + -- Build the argument list for the Entitie's spawn function local ArgList = {} local Arg for iNumber, Key in pairs( EntityClass.Args ) do Arg = nil - // Translate keys from old system + -- Translate keys from old system if ( Key == "pos" or Key == "position" ) then Key = "Pos" end if ( Key == "ang" or Key == "Ang" or Key == "angle" ) then Key = "Angle" end if ( Key == "model" ) then Key = "Model" end @@ -896,21 +896,21 @@ local function CreateEntityFromTable(EntTable, Player) Arg = EntTable[ Key ] - // Special keys + -- Special keys if ( Key == "Data" ) then Arg = EntTable end ArgList[ iNumber ] = Arg end - // Create and return the entity + -- Create and return the entity if(EntTable.Class=="prop_physics")then - valid = MakeProp(Player, unpack(ArgList, 1, #EntityClass.Args)) //Create prop_physics like this because if the model doesn't exist it will cause + valid = MakeProp(Player, unpack(ArgList, 1, #EntityClass.Args)) --Create prop_physics like this because if the model doesn't exist it will cause elseif IsAllowed(Player, EntTable.Class, EntityClass) then - //Create sents using their spawn function with the arguments we stored earlier + --Create sents using their spawn function with the arguments we stored earlier sent = true - if(not EntTable.BuildDupeInfo.IsVehicle and not EntTable.BuildDupeInfo.IsNPC and EntTable.Class ~= "prop_ragdoll" and EntTable.Class ~= "prop_effect") then //These four are auto done + if(not EntTable.BuildDupeInfo.IsVehicle and not EntTable.BuildDupeInfo.IsNPC and EntTable.Class ~= "prop_ragdoll" and EntTable.Class ~= "prop_effect") then --These four are auto done sent = hook.Call("PlayerSpawnSENT", nil, Player, EntTable.Class) end @@ -928,7 +928,7 @@ local function CreateEntityFromTable(EntTable, Player) end end - //If its a valid entity send it back to the entities list so we can constrain it + --If its a valid entity send it back to the entities list so we can constrain it if( status~=false and IsValid(valid) )then if(sent)then local iNumPhysObjects = valid:GetPhysicsObjectCount() @@ -1076,7 +1076,7 @@ function AdvDupe2.duplicator.Paste( Player, EntityList, ConstraintList, Position undo.SetPlayer( Player ) undo.Finish() - //if(Tool)then AdvDupe2.FinishPasting(Player, true) end + --if(Tool)then AdvDupe2.FinishPasting(Player, true) end else for _,v in pairs( CreatedEntities ) do @@ -1246,7 +1246,7 @@ local function AdvDupe2_Spawn() local unfreeze = tobool(Queue.Player:GetInfo("advdupe2_paste_unfreeze")) or false local preservefrozenstate = tobool(Queue.Player:GetInfo("advdupe2_preserve_freeze")) or false - //Remove the undo for stopping pasting + --Remove the undo for stopping pasting local undos = undo.GetTable()[Queue.Player:UniqueID()] local str = "AdvDupe2_"..Queue.Player:UniqueID() for i=#undos, 1, -1 do @@ -1295,7 +1295,7 @@ local function AdvDupe2_Spawn() for i=0, v:GetPhysicsObjectCount() do phys = v:GetPhysicsObjectNum(i) if(IsValid(phys))then - phys:EnableMotion(true) //Unfreeze the entitiy and all of its objects + phys:EnableMotion(true) --Unfreeze the entitiy and all of its objects phys:Wake() end end @@ -1304,7 +1304,7 @@ local function AdvDupe2_Spawn() phys = v:GetPhysicsObjectNum(i) if(IsValid(phys))then if(Queue.EntityList[_].BuildDupeInfo.PhysicsObjects[i].Frozen)then - phys:EnableMotion(true) //Restore the entity and all of its objects to their original frozen state + phys:EnableMotion(true) --Restore the entity and all of its objects to their original frozen state phys:Wake() else Queue.Player:AddFrozenPhysicsObject( v, phys ) @@ -1316,7 +1316,7 @@ local function AdvDupe2_Spawn() phys = v:GetPhysicsObjectNum(i) if(IsValid(phys))then if(phys:IsMoveable())then - phys:EnableMotion(false) //Freeze the entitiy and all of its objects + phys:EnableMotion(false) --Freeze the entitiy and all of its objects Queue.Player:AddFrozenPhysicsObject( v, phys ) end end @@ -1361,7 +1361,7 @@ local function ErrorCatchSpawning() local status, error = pcall(AdvDupe2_Spawn) if(not status)then - //PUT ERROR LOGGING HERE + --PUT ERROR LOGGING HERE if(not AdvDupe2.JobManager.Queue)then print("[AdvDupe2Notify]\t"..error) @@ -1419,7 +1419,7 @@ local function ErrorCatchSpawning() end local function RemoveSpawnedEntities(tbl, i) - if(not AdvDupe2.JobManager.Queue[i])then return end //Without this some errors come up, double check the errors without this line + if(not AdvDupe2.JobManager.Queue[i])then return end --Without this some errors come up, double check the errors without this line for k,v in pairs(AdvDupe2.JobManager.Queue[i].CreatedEntities)do if(IsValid(v))then diff --git a/lua/advdupe2/sv_misc.lua b/lua/advdupe2/sv_misc.lua index 3c831e9..52cf4f8 100644 --- a/lua/advdupe2/sv_misc.lua +++ b/lua/advdupe2/sv_misc.lua @@ -18,13 +18,10 @@ local function SavePositions( Constraint ) if IsValid(Constraint) then - if Constraint.BuildDupeInfo then return end - if not Constraint.BuildDupeInfo then Constraint.BuildDupeInfo = {} end - - local Ent1 - local Ent2 + + local Ent1, Ent2 if IsValid(Constraint.Ent) then Constraint.BuildDupeInfo.Ent1Ang = Constraint.Ent:GetAngles() end @@ -53,82 +50,14 @@ local function SavePositions( Constraint ) Constraint.BuildDupeInfo.Bone2Angle = Constraint.Ent4:GetPhysicsObjectNum(Constraint["Bone4"]):GetAngles() end end - end - end - -end - - -local function FixMagnet(Magnet) - Magnet.Entity = Magnet end -//Find out when a Constraint is created -timer.Simple(0, function() - hook.Add( "OnEntityCreated", "AdvDupe2_SavePositions", function(entity) - - if not IsValid( entity ) then return end - - local a,b = entity:GetClass():match("^(.-)_(.+)") - - if b == "magnet" then - timer.Simple( 0, function() FixMagnet(entity) end) - end - - if a == "phys" then - if(b=="constraintsystem")then return end - timer.Simple( 0, function() SavePositions(entity) end) - end - - end ) - end) - --- Register camera entity class --- fixes key not being saved (Conna) -local function CamRegister(Player, Pos, Ang, Key, Locked, Toggle, Vel, aVel, Frozen, Nocollide) - if (!Key) then return end - - local Camera = ents.Create("gmod_cameraprop") - Camera:SetAngles(Ang) - Camera:SetPos(Pos) - Camera:Spawn() - Camera:SetKey(Key) - Camera:SetPlayer(Player) - Camera:SetLocked(Locked) - Camera.toggle = Toggle - Camera:SetTracking(NULL, Vector(0)) - - if (Toggle == 1) then - numpad.OnDown(Player, Key, "Camera_Toggle", Camera) - else - numpad.OnDown(Player, Key, "Camera_On", Camera) - numpad.OnUp(Player, Key, "Camera_Off", Camera) +hook.Add( "OnEntityCreated", "AdvDupe2_SavePositions", function(ent) + if not IsValid(ent) then return end + local a,b = string.match(ent:GetClass(), "^(.-)_(.+)") + if a == "phys" and b ~= "constraintsystem" then + timer.Simple(0, function() SavePositions(ent) end) end - - if (Nocollide) then Camera:GetPhysicsObject():EnableCollisions(false) end - - -- Merge table - local Table = { - key = Key, - toggle = Toggle, - locked = Locked, - pl = Player, - nocollide = nocollide - } - table.Merge(Camera:GetTable(), Table) - - -- remove any camera that has the same key defined for this player then add the new one - local ID = Player:UniqueID() - GAMEMODE.CameraList[ID] = GAMEMODE.CameraList[ID] or {} - local List = GAMEMODE.CameraList[ID] - if (List[Key] and List[Key] != NULL ) then - local Entity = List[Key] - Entity:Remove() - end - List[Key] = Camera - return Camera - -end -duplicator.RegisterEntityClass("gmod_cameraprop", CamRegister, "Pos", "Ang", "key", "locked", "toggle", "Vel", "aVel", "frozen", "nocollide") \ No newline at end of file +end)