Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if CLIENT then
- local function BodyPartHit(direction, part, parts, ent)
- table.insert(parts, ent)
- local sounds = {"player/pl_fallpain3.wav", "player/pl_fallpain1.wav"}
- local tracedata = {}
- local Pos = part:GetPos()
- tracedata.start = Pos
- tracedata.endpos = Pos + direction:GetNormalized() * 30
- tracedata.filter = parts
- local trace = util.TraceLine(tracedata)
- local emitter = ParticleEmitter( Pos )
- local particle = emitter:Add( "effects/blooddrop", Pos + Vector( math.random( -10, 5 ), math.random( -5, 15 ), math.random( -5, 5) ) )
- particle:SetVelocity( direction )
- particle:SetDieTime( 1 )
- particle:SetStartAlpha( 255 )
- particle:SetStartSize( 2 )
- particle:SetEndSize( 0 )
- particle:SetRoll( math.random(0, 360) )
- particle:SetColor( 80, 0, 0 )
- emitter:Finish()
- util.Decal("blood", trace.HitPos + trace.HitNormal, trace.HitPos - trace.HitNormal)
- ent:EmitSound(table.Random(sounds), direction:Length() / 1511 * 511)
- end
- hook.Add("OnEntityCreated", "RagdollEntityHook", function(ent)
- if( !ent or !ent:IsValid() or ent:GetClass() != "class C_HL2MPRagdoll" ) then
- return
- end
- local ply = nil
- for _, v in pairs(player.GetAll()) do
- if( v:GetRagdollEntity() == ent ) then
- ply = v
- break
- end
- end
- if( ply == nil ) then
- return
- end
- local i = 0
- local Vel = Vector(0,0,0)
- // Initilization
- ent.VelTable = {}
- ent.Parts = {}
- while i < ent:GetPhysicsObjectCount() do
- local pobj = ent:GetPhysicsObjectNum(k)
- ent.VelTable[i] = pobj:GetVelocity()
- ent.Parts[i] = pobj
- i= i + 1
- end
- local enthook = tostring(ent)
- hook.Add("Think", enthook, function()
- // ent becomes invalid when player spawns or leaves.
- if( !ent or !ent:IsValid() or !ply:IsValid() ) then
- print("Removing Hook")
- hook.Remove("Think", enthook)
- return
- end
- local i = 0
- // Hmm, can this be done better?
- while i < ent:GetPhysicsObjectCount() do
- local pobj = ent:GetPhysicsObjectNum(k)
- local Vel = pobj:GetVelocity()
- local VelDiff = ent.VelTable[i] - Vel
- ent.VelTable[i] = Vel
- if( VelDiff:Length() >= 50 ) then
- print("Body Hit!")
- BodyPartHit(VelDiff, pobj, ent.Parts, ent)
- end
- i= i + 1
- end
- end)
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment