diff --git a/garrysmod/lua/includes/gmsave.lua b/garrysmod/lua/includes/gmsave.lua index fa8b1a1e11..87071b0622 100644 --- a/garrysmod/lua/includes/gmsave.lua +++ b/garrysmod/lua/includes/gmsave.lua @@ -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 diff --git a/garrysmod/lua/includes/modules/constraint.lua b/garrysmod/lua/includes/modules/constraint.lua index b1c3002712..c4bbda13c8 100644 --- a/garrysmod/lua/includes/modules/constraint.lua +++ b/garrysmod/lua/includes/modules/constraint.lua @@ -202,6 +202,7 @@ function RemoveAll( Ent ) v:Remove() i = i + 1 end + end -- Update the network var and clear the constraints table. @@ -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 ) @@ -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 ) @@ -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 @@ -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 diff --git a/garrysmod/lua/includes/modules/duplicator.lua b/garrysmod/lua/includes/modules/duplicator.lua index dc7eb3d0df..bb218ac69d 100644 --- a/garrysmod/lua/includes/modules/duplicator.lua +++ b/garrysmod/lua/includes/modules/duplicator.lua @@ -842,22 +842,22 @@ 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 @@ -865,7 +865,7 @@ function GetAllConstrainedEntitiesAndConstraints( ent, EntTable, ConstraintTable -- 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 @@ -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