Skip to content

Commit

Permalink
world constraints fix
Browse files Browse the repository at this point in the history
  • Loading branch information
robotboy655 committed Jun 9, 2021
1 parent d3fed58 commit f9d774f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
4 changes: 4 additions & 0 deletions garrysmod/lua/includes/gmsave.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ function gmsave.SaveMap( ply )

end

-- This is to copy the constraints that are applied to the world only (ropes, etc)
-- It will not actually save and then try to restore the world entity, as that would cause issues
table.insert( Ents, game.GetWorld() )

local tab = duplicator.CopyEnts( Ents )
if ( !tab ) then return end

Expand Down
9 changes: 5 additions & 4 deletions garrysmod/lua/includes/modules/constraint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ function RemoveAll( Ent )
v:Remove()
i = i + 1
end

end

-- Update the network var and clear the constraints table.
Expand Down Expand Up @@ -348,7 +349,7 @@ function AddConstraintTable( Ent, Constraint, Ent2, Ent3, Ent4 )

if ( !IsValid( Constraint ) ) then return end

if ( IsValid( Ent ) ) then
if ( IsValid( Ent ) || ( Ent && Ent:IsWorld() ) ) then

Ent.Constraints = Ent.Constraints or {}
table.insert( Ent.Constraints, Constraint )
Expand All @@ -370,7 +371,7 @@ function AddConstraintTableNoDelete( Ent, Constraint, Ent2, Ent3, Ent4 )

if ( !IsValid( Constraint ) ) then return end

if ( IsValid( Ent ) ) then
if ( IsValid( Ent ) || ( Ent && Ent:IsWorld() ) ) then

Ent.Constraints = Ent.Constraints or {}
table.insert( Ent.Constraints, Constraint )
Expand Down Expand Up @@ -1445,7 +1446,7 @@ function Muscle( pl, Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, Length1, Length2, w

if ( fixed == 1 ) then
slider = Slider( Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, 0 )
slider:SetTable( {} ) -- ??
slider:SetTable( {} ) -- Remove data for duplicator
Constraint:DeleteOnRemove( slider )
end

Expand Down Expand Up @@ -1626,7 +1627,7 @@ function GetAllConstrainedEntities( ent, ResultTable )

local ResultTable = ResultTable or {}

if ( !IsValid( ent ) ) then return end
if ( !IsValid( ent ) && !ent:IsWorld() ) then return end
if ( ResultTable[ ent ] ) then return end

ResultTable[ ent ] = ent
Expand Down
24 changes: 14 additions & 10 deletions garrysmod/lua/includes/modules/duplicator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -842,30 +842,30 @@ function ApplyBoneModifiers( Player, Ent )
end


--[[---------------------------------------------------------
Returns all constrained Entities and constraints
This is kind of in the wrong place. No not call this
from outside of this code. It will probably get moved to
constraint.lua soon.
-----------------------------------------------------------]]
--
-- Returns all constrained Entities and constraints
-- This is kind of in the wrong place.
--
-- This function will accept the world entity to save constrains, but will not actually save the world entity itself
--
function GetAllConstrainedEntitiesAndConstraints( ent, EntTable, ConstraintTable )

if ( !IsValid( ent ) ) then return end
if ( !IsValid( ent ) && !ent:IsWorld() ) then return end

-- Translate the class name
local classname = ent:GetClass()
if ( ent.ClassOverride ) then classname = ent.ClassOverride end

-- Is the entity in the dupe whitelist?
if ( !IsAllowed( classname ) ) then
if ( !IsAllowed( classname ) && !ent:IsWorld() ) then
-- MsgN( "duplicator: ", classname, " isn't allowed to be duplicated!" )
return
end

-- Entity doesn't want to be duplicated.
if ( ent.DoNotDuplicate ) then return end

EntTable[ ent:EntIndex() ] = ent
if ( !ent:IsWorld() ) then EntTable[ ent:EntIndex() ] = ent end

if ( !constraint.HasConstraints( ent ) ) then return end

Expand All @@ -883,7 +883,11 @@ function GetAllConstrainedEntitiesAndConstraints( ent, EntTable, ConstraintTable
-- Run the Function for any ents attached to this constraint
for _, ConstrainedEnt in pairs( constr.Entity ) do

GetAllConstrainedEntitiesAndConstraints( ConstrainedEnt.Entity, EntTable, ConstraintTable )
if ( !ConstrainedEnt.Entity:IsWorld() ) then

GetAllConstrainedEntitiesAndConstraints( ConstrainedEnt.Entity, EntTable, ConstraintTable )

end

end

Expand Down

0 comments on commit f9d774f

Please sign in to comment.