Advertisement
Guest User

Untitled

a guest
Nov 25th, 2014
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1. -- Ragdoll Crash Catcher for TTT and any other gamemode
  2. -- By Ambro, DarthTealc, and code_gs
  3. -- Run shared (lua/autorun)
  4.  
  5. -- Config
  6. local EchoFreeze = true -- Tell players when a body is frozen
  7. local EchoRemove = true -- Tell players when a body is removed
  8.  
  9. local FreezeSpeed = 500 -- Velocity ragdoll is frozen at
  10. local RemoveSpeed = 4000 -- Velocity ragdoll is removed at
  11.  
  12. local FreezeTime = 3 -- Time body is frozen for
  13.  
  14. if ( GAMEMODE_NAME == "terrortown" ) then
  15. local IsTTT = true
  16. else
  17. local IsTTT = false
  18. end
  19.  
  20. local function SetSubPhysMotionEnabled( ent, enable )
  21. if not IsValid( ent ) then return end
  22.  
  23. ent:SetVelocity( vector_origin )
  24.  
  25. if ( not enable ) then
  26. ent:SetColor( Color( 255, 0, 255, 255 ) )
  27. if IsValid( ent:GetOwner() ) then
  28. if ( IsTTT ) then
  29. ent:GetOwner():GetWeapon( "weapon_zm_carry" ):Reset( false )
  30. end
  31. end
  32. else
  33. ent:SetColor( Color( 255, 255, 255, 255 ) )
  34. end
  35.  
  36. for i = 0, ent:GetPhysicsObjectCount() - 1 do
  37. local subphys = ent:GetPhysicsObjectNum( i )
  38. if IsValid( subphys ) then
  39. subphys:EnableMotion( enable )
  40. if ( not enable ) then
  41. subphys:SetVelocity( vector_origin )
  42. subphys:SetMass( subphys:GetMass() * 20 )
  43. else
  44. subphys:SetMass( subphys:GetMass() / 20 )
  45. subphys:Wake()
  46. end
  47. end
  48. end
  49.  
  50. ent:SetVelocity( vector_origin )
  51. end
  52.  
  53. local function KillVelocity( ent )
  54. SetSubPhysMotionEnabled( ent, false )
  55.  
  56. if ( EchoFreeze ) then
  57. PrintMessage( HUD_PRINTTALK, "[GS_CRASH] Body frozen for " .. FreezeTime .. " seconds!" )
  58. end
  59.  
  60. timer.Simple( FreezeTime, function()
  61. SetSubPhysMotionEnabled( ent, true )
  62. if ( EchoFreeze ) then
  63. PrintMessage( HUD_PRINTTALK, "[GS_CRASH] Body unfrozen!" )
  64. end
  65. end )
  66. end
  67.  
  68. local function IdentifyCorpse( corpse )
  69. if ( corpse and IsTTT ) then
  70. local ply = player.GetByUniqueID( corpse.uqid )
  71. ply:SetNWBool( "body_found", true )
  72. CORPSE.SetFound( corpse, true )
  73. end
  74. end
  75.  
  76. function GS_CrashCatch()
  77. for k, ent in pairs( ents.FindByClass( "prop_ragdoll" ) ) do
  78. if ( IsValid( ent ) ) then
  79. if ( ent.player_ragdoll ) then
  80. local velo = ent:GetVelocity():Length()
  81. local nick = ent:GetNWString( "nick" )
  82. if ( velo >= RemoveSpeed ) then
  83. ent:Remove()
  84. local message = "[GS_CRASH] Removed body of " .. nick .. " for moving too fast"
  85. ServerLog( message .. " (" .. velo .. ")\n" )
  86. if ( EchoRemove ) then
  87. PrintMessage( HUD_PRINTTALK, message )
  88. end
  89. if ( IsTTT and CORPSE.GetFound( ent, true ) ) then
  90. IdentifyCorpse( ent )
  91. end
  92. elseif ( velo >= FreezeSpeed ) then
  93. KillVelocity( ent )
  94. ServerLog( "[GS_CRASH] Disabling motion for the body of " .. nick .. " (" .. velo .. ") \n" )
  95. end
  96. end
  97. end
  98. end
  99. end
  100.  
  101. hook.Add( "Think", "GS_CrashCatcher", GS_CrashCatch )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement