Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function CreateRagdoll( victim )
- --Check if they already have a ragdoll
- if victim:GetNetworkedBool( "plyHasRagdoll" ) then
- --Get the ragdoll
- local toremObj = victim:GetNetworkedEntity( "plyRagdoll" )
- --Remove it
- toremObj:Remove()
- victim:SetNetworkedBool( "plyHasRagdoll", false )
- victim:SetNetworkedEntity( "plyRagdoll", 0 )
- end
- --Multiple variables
- local ragModel = victim:GetModel()
- local ragPos = victim:GetPos()
- local ragAng = victim:GetAngles()
- --Create the colliding ragdoll
- local ragObj = ents.Create( "prop_ragdoll" )
- ragObj:SetModel( ragModel )
- --Set other parameters here
- ragObj:SetPos( ragPos )
- ragObj:SetAngles( ragAng )
- --Spawn the ragdoll
- ragObj:Spawn()
- --Get all the bones
- local ragBones = ragObj:GetPhysicsObjectCount()
- --Loop through each bone
- for i = 1, ragBones - 1 do
- --Get the current bone
- local ragBone = ragObj:GetPhysicsObjectNum( i )
- --Check if it's valid
- if ValidEntity( ragBone ) then
- --Get the bone's pos and angle
- local ragBonePos, ragBoneAng = victim:GetBonePosition( ragObj:TranslatePhysBoneToBone( i ) )
- --Set the bone's pos and angle
- ragBone:SetPos( ragBonePos )
- ragBone:SetAngle( ragBoneAng )
- --Set velocity
- ragBone:SetVelocity( ragObj:GetVelocity() )
- end
- end
- --Networked variables
- victim:SetNetworkedBool( "plyHasRagdoll", true )
- victim:SetNetworkedEntity( "plyRagdoll", ragObj )
- --Get their current ragdoll
- local crapDoll = victim:GetRagdollEntity()
- --Delete it
- crapDoll:Remove()
- end
- -------------------------
- function RemoveRagdoll( ply )
- if ply:GetNetworkedBool( "plyHasRagdoll" ) then --Check if they have a ragdoll
- local ragObj = ply:GetNetworkedEntity( "plyRagdoll" ) --Get the ragdoll
- --Set networked variables
- ply:SetNetworkedBool( "plyHasRagdoll", false )
- ply:SetNetworkedEntity( "plyRagdoll", 0 )
- timer.Simple( 10, function() --Create a timer for 10 seconds
- if ValidEntity( ragObj ) then --Make sure it is valid
- ragObj:Remove() --Remove it
- end
- end)
- end
- end
- -------------------------
- function RemoveAllRagdolls()
- for k, v in pairs( player.GetAll() ) do
- if v:GetNetworkedBool( "plyHasRagdoll" ) then --Check if they have a ragdoll
- local ragObj = v:GetNetworkedEntity( "plyRagdoll" ) --Get the ragdoll
- --Set networked variables
- v:SetNetworkedBool( "plyHasRagdoll", false )
- v:SetNetworkedEntity( "plyRagdoll", 0 )
- if ValidEntity( ragObj ) then --Make sure it is valid
- ragObj:Remove() --Remove it
- end
- end
- end
- end
- -------------------------
- --Add the hooks
- hook.Add( "PlayerDeath", "RagmodCreateRagdoll", CreateRagdoll )
- --Add the disconnect hook
- hook.Add( "PlayerDisconnected", "RagmodRemoveRagdollDisconnect", RemoveRagdoll )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement