Advertisement
Guest User

Untitled

a guest
Feb 1st, 2011
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. function CreateRagdoll( victim )
  2. --Check if they already have a ragdoll
  3. if victim:GetNetworkedBool( "plyHasRagdoll" ) then
  4.  
  5. --Get the ragdoll
  6. local toremObj = victim:GetNetworkedEntity( "plyRagdoll" )
  7.  
  8. --Remove it
  9. toremObj:Remove()
  10. victim:SetNetworkedBool( "plyHasRagdoll", false )
  11. victim:SetNetworkedEntity( "plyRagdoll", 0 )
  12.  
  13. end
  14.  
  15. --Multiple variables
  16. local ragModel = victim:GetModel()
  17. local ragPos = victim:GetPos()
  18. local ragAng = victim:GetAngles()
  19.  
  20. --Create the colliding ragdoll
  21. local ragObj = ents.Create( "prop_ragdoll" )
  22. ragObj:SetModel( ragModel )
  23.  
  24. --Set other parameters here
  25. ragObj:SetPos( ragPos )
  26. ragObj:SetAngles( ragAng )
  27.  
  28. --Spawn the ragdoll
  29. ragObj:Spawn()
  30.  
  31. --Get all the bones
  32. local ragBones = ragObj:GetPhysicsObjectCount()
  33.  
  34. --Loop through each bone
  35. for i = 1, ragBones - 1 do
  36.  
  37. --Get the current bone
  38. local ragBone = ragObj:GetPhysicsObjectNum( i )
  39.  
  40. --Check if it's valid
  41. if ValidEntity( ragBone ) then
  42.  
  43. --Get the bone's pos and angle
  44. local ragBonePos, ragBoneAng = victim:GetBonePosition( ragObj:TranslatePhysBoneToBone( i ) )
  45.  
  46. --Set the bone's pos and angle
  47. ragBone:SetPos( ragBonePos )
  48. ragBone:SetAngle( ragBoneAng )
  49.  
  50. --Set velocity
  51. ragBone:SetVelocity( ragObj:GetVelocity() )
  52.  
  53. end
  54.  
  55. end
  56.  
  57. --Networked variables
  58. victim:SetNetworkedBool( "plyHasRagdoll", true )
  59. victim:SetNetworkedEntity( "plyRagdoll", ragObj )
  60.  
  61. --Get their current ragdoll
  62. local crapDoll = victim:GetRagdollEntity()
  63.  
  64. --Delete it
  65. crapDoll:Remove()
  66.  
  67. end
  68.  
  69. -------------------------
  70.  
  71. function RemoveRagdoll( ply )
  72. if ply:GetNetworkedBool( "plyHasRagdoll" ) then --Check if they have a ragdoll
  73. local ragObj = ply:GetNetworkedEntity( "plyRagdoll" ) --Get the ragdoll
  74. --Set networked variables
  75. ply:SetNetworkedBool( "plyHasRagdoll", false )
  76. ply:SetNetworkedEntity( "plyRagdoll", 0 )
  77. timer.Simple( 10, function() --Create a timer for 10 seconds
  78. if ValidEntity( ragObj ) then --Make sure it is valid
  79. ragObj:Remove() --Remove it
  80. end
  81. end)
  82. end
  83. end
  84. -------------------------
  85. function RemoveAllRagdolls()
  86. for k, v in pairs( player.GetAll() ) do
  87. if v:GetNetworkedBool( "plyHasRagdoll" ) then --Check if they have a ragdoll
  88. local ragObj = v:GetNetworkedEntity( "plyRagdoll" ) --Get the ragdoll
  89. --Set networked variables
  90. v:SetNetworkedBool( "plyHasRagdoll", false )
  91. v:SetNetworkedEntity( "plyRagdoll", 0 )
  92. if ValidEntity( ragObj ) then --Make sure it is valid
  93. ragObj:Remove() --Remove it
  94. end
  95. end
  96. end
  97. end
  98. -------------------------
  99.  
  100. --Add the hooks
  101. hook.Add( "PlayerDeath", "RagmodCreateRagdoll", CreateRagdoll )
  102.  
  103. --Add the disconnect hook
  104. hook.Add( "PlayerDisconnected", "RagmodRemoveRagdollDisconnect", RemoveRagdoll )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement