Garry's Mod Wiki

ClientsideRagdoll

  CSEnt ClientsideRagdoll( string model, number renderGroup = RENDERGROUP_OPAQUE )

Description

Creates a fully clientside ragdoll.

The ragdoll initially starts as hidden and with shadows disabled, see the example for how to enable it.

There's no need to call Entity:Spawn on this entity.

Clientside entities are not garbage-collected, thus you must store a reference to the object and call CSEnt:Remove manually.

Issue Tracker: 1387

Arguments

1 string model
The file path to the model.
2 number renderGroup = RENDERGROUP_OPAQUE
The RENDERGROUP enum to assign.

Returns

1 CSEnt
The newly created client-side only ragdoll. (C_ClientRagdoll)

Example

Creates a new ragdoll with the player model of breen and enables rendering and shadows.

concommand.Add( "test_csragdoll", function( ply ) local ragdoll = ClientsideRagdoll( "models/player/breen.mdl" ) ragdoll:SetNoDraw( false ) ragdoll:DrawShadow( true ) --print( ragdoll ) end )

Example

Example of how to set the ragdoll's position.

local csRag = FindMetaTable( "CSEnt" ) -- csRag:SetPos() doesn't work for C_ClientRagdoll entities. function csRag:SetRagdollPos(pos) for i = 0, self:GetPhysicsObjectCount() - 1 do -- Get the physics object (PhysBone) local phys = self:GetPhysicsObjectNum(i) -- Get the position of the physics object relative to the ragdoll's position local localPos = self:WorldToLocal( phys:GetPos() ) -- Set the physics object's location to the new position using the relative position to it's previous position phys:SetPos( pos + localPos ) end end -- Example usage concommand.Add( "player_csragdoll", function( ply ) local ragdoll = ClientsideRagdoll( ply:GetModel() ) -- Create a ragdoll using the player's model ragdoll:SetNoDraw( false ) ragdoll:DrawShadow( true ) ragdoll:SetRagdollPos( ply:GetPos() ) -- Set the position of the ragdoll to the player's position end )