Skip to content

Commit

Permalink
Some cleanup first
Browse files Browse the repository at this point in the history
  • Loading branch information
thegrb93 committed Sep 28, 2020
1 parent c6c53cd commit 8e27851
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 106 deletions.
54 changes: 27 additions & 27 deletions lua/advdupe2/sv_clipboard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ end
Returns: <table> 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 )
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
87 changes: 8 additions & 79 deletions lua/advdupe2/sv_misc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
end)

0 comments on commit 8e27851

Please sign in to comment.