CapsAdmin

Untitled

May 7th, 2011
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. if SERVER then
  2. AddCSLuaFile("flyingragdolls.lua")
  3. end
  4.  
  5. hook.Add("PlayerDeath", "OnRagdollController",
  6. function(ply, weapon, killer)
  7.  
  8. if SERVER then
  9.  
  10. local ragdoll_controller = ents.Create("prop_physics")
  11.  
  12. ragdoll_controller:SetModel("models/props_junk/PopCan01a.mdl")
  13. ragdoll_controller:SetPos(ply:GetPos())
  14. ragdoll_controller:Spawn()
  15.  
  16. ply:SetNWEntity("ragdoll_controller", ragdoll_controller)
  17.  
  18.  
  19. local pobj = ragdoll_controller:GetPhysicsObject()
  20.  
  21. if( pobj:IsValid() ) then
  22. pobj:Wake()
  23. end
  24.  
  25. timer.Create(ply:UserID() .. "_dead", 0, 0,
  26. function()
  27.  
  28. if( !ply ) then
  29. return
  30. end
  31.  
  32. if( !ply:IsValid() ) then
  33. return false
  34. end
  35.  
  36. if( ply:Alive() ) then
  37.  
  38. ragdoll_controller:Remove()
  39. ply:SetNWEntity("ragdoll_controller", nil)
  40.  
  41. return false
  42.  
  43. end
  44.  
  45. if( ply:KeyDown(IN_FORWARD) ) then
  46.  
  47. pobj:ApplyForceCenter(ply:GetCursorAimVector() * 100)
  48.  
  49. pobj:AddVelocity(pobj:GetVelocity() * -0.035)
  50.  
  51. end
  52.  
  53. end
  54. )
  55.  
  56. end
  57.  
  58. end
  59. )
  60.  
  61.  
  62. if CLIENT then
  63.  
  64. hook.Add("OnEntityCreated", "OnRagdollCreate",
  65. function(ent)
  66.  
  67. if(!ent) then
  68. return
  69. end
  70.  
  71. local c=ent:GetClass()
  72.  
  73. if c=="class C_HL2MPRagdoll" then
  74.  
  75. print("Death ragdoll: ", ent)
  76.  
  77. local ply = nil
  78.  
  79. for k,v in pairs(player.GetAll()) do
  80.  
  81. if v:GetRagdollEntity() == ent then
  82.  
  83. ply = v
  84.  
  85. end
  86.  
  87. end
  88.  
  89. local timerid = CurTime() + math.random()
  90. local rotation = 0
  91. local bodyparts = {}
  92. bodyparts[10] = 800
  93.  
  94. timer.Create(timerid ,0,0,function()
  95.  
  96. if( !ent:IsValid() ) then
  97. return false
  98. end
  99.  
  100. local ragdoll_controller = ply:GetNWEntity("ragdoll_controller")
  101.  
  102. if( ragdoll_controller == nil ) then
  103. return
  104. end
  105.  
  106. local add = Vector(0,0,0)
  107. local move = false
  108.  
  109. local pos = ragdoll_controller:GetPos()
  110.  
  111. for bodypart, acceleration in pairs(bodyparts) do
  112.  
  113. local pobj = ent:GetPhysicsObjectNum(bodypart)
  114.  
  115. if( pobj:IsValid() ) then
  116.  
  117. pobj:ApplyForceCenter( (pos - pobj:GetPos()) * FrameTime() * 2000 )
  118.  
  119. end
  120.  
  121. end
  122.  
  123. end)
  124.  
  125. end
  126.  
  127. end
  128. )
  129.  
  130. end
Advertisement
Add Comment
Please, Sign In to add comment