Python1320

Untitled

Oct 28th, 2011
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.26 KB | None | 0 0
  1. if CLIENT then
  2.  
  3. local function BodyPartHit(direction, part, parts, ent)
  4.  
  5.     table.insert(parts, ent)
  6.    
  7.     local sounds = {"player/pl_fallpain3.wav", "player/pl_fallpain1.wav"}
  8.     local tracedata = {}
  9.     local Pos = part:GetPos()
  10.    
  11.     tracedata.start = Pos
  12.     tracedata.endpos = Pos + direction:GetNormalized() * 30
  13.     tracedata.filter = parts
  14.    
  15.     local trace = util.TraceLine(tracedata)
  16.    
  17.     local emitter = ParticleEmitter( Pos )
  18.     local particle = emitter:Add( "effects/blooddrop", Pos + Vector( math.random( -10, 5 ), math.random( -5, 15 ), math.random( -5, 5) ) )
  19.         particle:SetVelocity( direction )
  20.         particle:SetDieTime( 1 )
  21.         particle:SetStartAlpha( 255 )
  22.         particle:SetStartSize( 2 )
  23.         particle:SetEndSize( 0 )
  24.         particle:SetRoll( math.random(0, 360) )
  25.         particle:SetColor( 80, 0, 0 )          
  26.     emitter:Finish()
  27.  
  28.     util.Decal("blood", trace.HitPos + trace.HitNormal, trace.HitPos - trace.HitNormal)
  29.    
  30.     ent:EmitSound(table.Random(sounds), direction:Length() / 1511 * 511)
  31. end
  32.  
  33. hook.Add("OnEntityCreated", "RagdollEntityHook", function(ent)
  34.  
  35.     if( !ent or !ent:IsValid() or ent:GetClass() != "class C_HL2MPRagdoll" ) then
  36.         return
  37.     end
  38.        
  39.     local ply = nil
  40.     for _, v in pairs(player.GetAll()) do
  41.         if( v:GetRagdollEntity() == ent ) then
  42.             ply = v
  43.             break
  44.         end
  45.     end
  46.    
  47.     if( ply == nil ) then
  48.         return
  49.     end
  50.    
  51.     local i = 0
  52.     local Vel = Vector(0,0,0)
  53.    
  54.     // Initilization
  55.     ent.VelTable = {}
  56.     ent.Parts = {}
  57.    
  58.     while i < ent:GetPhysicsObjectCount() do
  59.         local pobj = ent:GetPhysicsObjectNum(k)
  60.         ent.VelTable[i] = pobj:GetVelocity()
  61.         ent.Parts[i] = pobj
  62.         i= i + 1
  63.     end
  64.        
  65.     local enthook = tostring(ent)
  66.     hook.Add("Think", enthook, function()
  67.            
  68.         // ent becomes invalid when player spawns or leaves.
  69.         if( !ent or !ent:IsValid() or !ply:IsValid() ) then
  70.             print("Removing Hook")
  71.             hook.Remove("Think", enthook)
  72.             return
  73.         end
  74.            
  75.         local i = 0
  76.        
  77.         // Hmm, can this be done better?
  78.         while i < ent:GetPhysicsObjectCount() do
  79.        
  80.             local pobj = ent:GetPhysicsObjectNum(k)
  81.             local Vel = pobj:GetVelocity()
  82.             local VelDiff = ent.VelTable[i] - Vel
  83.             ent.VelTable[i] = Vel
  84.            
  85.             if( VelDiff:Length() >= 50 ) then
  86.                 print("Body Hit!")
  87.                 BodyPartHit(VelDiff, pobj, ent.Parts, ent)
  88.             end
  89.            
  90.             i= i + 1
  91.            
  92.         end
  93.                
  94.     end)
  95.    
  96. end)
  97.  
  98. end
  99.  
Advertisement
Add Comment
Please, Sign In to add comment