Advertisement
CapsAdmin

Untitled

Mar 25th, 2013
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.19 KB | None | 0 0
  1. if CLIENT then 
  2.     hook.Add("OnEntityCreated", "server_ragdoll", function(ent)
  3.         if ent and ent:IsValid() and ent:GetClass() == "class C_HL2MPRagdoll" then
  4.             for key, ply in pairs(player.GetAll()) do
  5.                 if ply:GetRagdollEntity() == ent then
  6.                     ent.RenderOverride = function() end
  7.                     break
  8.                 end
  9.             end
  10.         end
  11.     end)
  12.    
  13.     hook.Add("Think", "server_ragdoll", function()
  14.         for key, ply in pairs(player.GetAll()) do
  15.             local rag = ply.server_ragdoll or NULL
  16.             if rag:IsValid() then
  17.                 local csrag = ply:GetRagdollEntity() or NULL
  18.                 if csrag:IsValid() and csrag:GetParent() ~= rag then
  19.                     csrag:SetParent(rag)
  20.                     csrag:AddEffects(EF_BONEMERGE)
  21.                     csrag:AddEffects(EF_BONEMERGE_FASTCULL)
  22.                     csrag:SetSolid(0)
  23.                        
  24.                     rag.RenderOverride = function() end            
  25.                     csrag.RenderOverride = function(self)                  
  26.                         self:DrawModel()
  27.                                                    
  28.                         local pos, ang = rag:GetPos(), rag:GetAngles()
  29.                         csrag:GetPhysicsObject():SetPos(pos)   
  30.                         ply:SetPos(pos)
  31.                         ply:SetAngles(ang)
  32.                     end
  33.                 end
  34.             end
  35.         end
  36.     end)
  37.        
  38.     net.Receive("server_ragdoll", function()
  39.         local ply = net.ReadEntity()
  40.         local id = tonumber(net.ReadString())-- i never got the number stuff here working.. replace
  41.         local rag = Entity(id)
  42.                                        
  43.         if not rag:IsValid() then
  44.             local tag = "server_ragdoll_" .. id
  45.             hook.Add("NetworkEntityCreated", tag, function(ent)
  46.                 if ent:EntIndex() == id then
  47.                     ply.server_ragdoll = ent
  48.                 end
  49.             end)
  50.             timer.Simple(3, function()
  51.                 hook.Remove("NetworkEntityCreated", tag)
  52.             end)
  53.         else
  54.             ply.server_ragdoll = rag
  55.         end
  56.     end)
  57. end
  58.  
  59. if SERVER then
  60.     util.AddNetworkString("server_ragdoll")
  61.    
  62.     hook.Add("PlayerDeath", "server_ragdoll", function(ply)
  63.         local rag = ply.server_ragdoll
  64.        
  65.         if rag:IsValid() then      
  66.             local max = physenv.GetPerformanceSettings().MaxAngularVelocity
  67.                
  68.             for i = 0, rag:GetPhysicsObjectCount() - 1 do  
  69.                 local bone = rag:GetPhysicsObjectNum(i) or NULL
  70.                 if bone:IsValid() then
  71.                     bone:AddAngleVelocity(VectorRand()*max)
  72.                 end
  73.             end
  74.                
  75.             return 
  76.         end
  77.            
  78.         rag = ents.Create( "prop_ragdoll" )
  79.            
  80.         ply.server_ragdoll = rag
  81.         rag.server_ragdoll_owner = ply
  82.         rag:SetOwner(ply)
  83.         rag:SetModel(ply:GetModel())
  84.         rag:SetPos(ply:GetPos())  
  85.         rag:Spawn()
  86.            
  87.         net.Start("server_ragdoll")
  88.             net.WriteEntity(ply)
  89.             net.WriteString(tostring(rag:EntIndex()))
  90.         net.Broadcast()
  91.        
  92.         local bones = rag:GetPhysicsObjectCount()
  93.        
  94.         for i = 0, bones - 1 do
  95.             local bone = rag:GetPhysicsObjectNum(i) or NULL
  96.              
  97.             if bone:IsValid() then  
  98.                 local name = rag:GetBoneName(rag:TranslatePhysBoneToBone(i))
  99.                 local pos, ang = ply:GetBonePosition(ply:LookupBone(name))
  100.                 bone:SetPos( pos )  
  101.                 bone:SetAngle( ang )
  102.                 bone:Wake()
  103.                 bone:SetVelocity(ply:GetVelocity())
  104.             end
  105.         end
  106.     end)
  107.    
  108.     hook.Add("Think", "server_ragdoll", function()
  109.         for key, ent in pairs(ents.FindByClass("prop_ragdoll")) do
  110.             local ply = ent.server_ragdoll_owner
  111.             if ply then                
  112.                 if not ply:IsValid() or ply:Alive() then
  113.                     ent:Remove()   
  114.                 else
  115.                     ply:SetPos(ent:GetPhysicsObject():GetPos())
  116.                     ply:SetMoveType(MOVETYPE_NONE)
  117.                 end
  118.             end
  119.         end
  120.     end)
  121.  
  122. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement