Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if CLIENT then
- hook.Add("OnEntityCreated", "server_ragdoll", function(ent)
- if ent and ent:IsValid() and ent:GetClass() == "class C_HL2MPRagdoll" then
- for key, ply in pairs(player.GetAll()) do
- if ply:GetRagdollEntity() == ent then
- ent.RenderOverride = function() end
- break
- end
- end
- end
- end)
- hook.Add("Think", "server_ragdoll", function()
- for key, ply in pairs(player.GetAll()) do
- local rag = ply.server_ragdoll or NULL
- if rag:IsValid() then
- local csrag = ply:GetRagdollEntity() or NULL
- if csrag:IsValid() and csrag:GetParent() ~= rag then
- csrag:SetParent(rag)
- csrag:AddEffects(EF_BONEMERGE)
- csrag:AddEffects(EF_BONEMERGE_FASTCULL)
- csrag:SetSolid(0)
- rag.RenderOverride = function() end
- csrag.RenderOverride = function(self)
- self:DrawModel()
- local pos, ang = rag:GetPos(), rag:GetAngles()
- csrag:GetPhysicsObject():SetPos(pos)
- ply:SetPos(pos)
- ply:SetAngles(ang)
- end
- end
- end
- end
- end)
- net.Receive("server_ragdoll", function()
- local ply = net.ReadEntity()
- local id = tonumber(net.ReadString())-- i never got the number stuff here working.. replace
- local rag = Entity(id)
- if not rag:IsValid() then
- local tag = "server_ragdoll_" .. id
- hook.Add("NetworkEntityCreated", tag, function(ent)
- if ent:EntIndex() == id then
- ply.server_ragdoll = ent
- end
- end)
- timer.Simple(3, function()
- hook.Remove("NetworkEntityCreated", tag)
- end)
- else
- ply.server_ragdoll = rag
- end
- end)
- end
- if SERVER then
- util.AddNetworkString("server_ragdoll")
- hook.Add("PlayerDeath", "server_ragdoll", function(ply)
- local rag = ply.server_ragdoll
- if rag:IsValid() then
- local max = physenv.GetPerformanceSettings().MaxAngularVelocity
- for i = 0, rag:GetPhysicsObjectCount() - 1 do
- local bone = rag:GetPhysicsObjectNum(i) or NULL
- if bone:IsValid() then
- bone:AddAngleVelocity(VectorRand()*max)
- end
- end
- return
- end
- rag = ents.Create( "prop_ragdoll" )
- ply.server_ragdoll = rag
- rag.server_ragdoll_owner = ply
- rag:SetOwner(ply)
- rag:SetModel(ply:GetModel())
- rag:SetPos(ply:GetPos())
- rag:Spawn()
- net.Start("server_ragdoll")
- net.WriteEntity(ply)
- net.WriteString(tostring(rag:EntIndex()))
- net.Broadcast()
- local bones = rag:GetPhysicsObjectCount()
- for i = 0, bones - 1 do
- local bone = rag:GetPhysicsObjectNum(i) or NULL
- if bone:IsValid() then
- local name = rag:GetBoneName(rag:TranslatePhysBoneToBone(i))
- local pos, ang = ply:GetBonePosition(ply:LookupBone(name))
- bone:SetPos( pos )
- bone:SetAngle( ang )
- bone:Wake()
- bone:SetVelocity(ply:GetVelocity())
- end
- end
- end)
- hook.Add("Think", "server_ragdoll", function()
- for key, ent in pairs(ents.FindByClass("prop_ragdoll")) do
- local ply = ent.server_ragdoll_owner
- if ply then
- if not ply:IsValid() or ply:Alive() then
- ent:Remove()
- else
- ply:SetPos(ent:GetPhysicsObject():GetPos())
- ply:SetMoveType(MOVETYPE_NONE)
- end
- end
- end
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement