CapsAdmin

Untitled

Nov 6th, 2011
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.08 KB | None | 0 0
  1. local emitter = ParticleEmitter(vector_origin)
  2. local spews = {}
  3.  
  4. function SpewBloodWorld(pos, force, time)
  5.     time = time and CurTime() + time or CurTime() + 1 + math.random()
  6.    
  7.     table.insert(spews, {pos = pos, force = force, time = time})
  8. end
  9.  
  10. function SpewBloodEntity(ent, pos, force, time)
  11.     time = time and CurTime() + time or CurTime() + 1 + math.random()
  12.    
  13.     local len = (force*1):Length()
  14.     local pos, ang = WorldToLocal(pos, force:Angle(), ent:EyePos(), ent:EyeAngles())
  15.    
  16.     table.insert(spews, {ent = ent, lpos = pos, lang = ang, time = time, force = len})
  17. end
  18.  
  19. local function OnCollide(p, pos, normal)
  20.     util.Decal(math.random() > 0.99 and "blood" or "Impact.Flesh", pos, pos - normal * 5)
  21.     p:SetEndLength(1)
  22.     p:SetVelocity(p:GetVelocity() * VectorRand() * 1.1)
  23.     if math.random() > 0.96 then
  24.     WorldSound("physics/flesh/flesh_squishy_impact_hard"..math.random(4)..".wav", p:GetPos(), 50, math.random(200,255))
  25.     end
  26. end
  27.  
  28. local function SpewThink()
  29.     for id, data in pairs(spews) do
  30.    
  31.     if data.ent then
  32.         if data.ent:IsValid() then
  33.        
  34.         local pos, ang = LocalToWorld(data.ent:EyePos(), data.ent:EyeAngles(), data.lpos, data.lang)
  35.         data.pos = pos
  36.         data.force = ang:Forward() * data.len
  37.        
  38.         print(pos:Distance(data.ent:EyePos()), data.force)
  39.         else
  40.         table.remove(spews, id)
  41.         end
  42.     end
  43.    
  44.     for i=1, math.random(3) do
  45.         local p = emitter:Add("decals/blood" .. math.random(8), data.pos)
  46.        
  47.         if p then
  48.         p:SetStartSize(1)
  49.         p:SetEndSize(1)
  50.        
  51.         p:SetStartLength(0)
  52.         p:SetEndLength(10)
  53.         p:SetRollDelta(10)
  54.        
  55.         --p:SetColor(255, 0, 0, 255)
  56.         p:SetVelocity(data.force + VectorRand() * 10)
  57.        
  58.         p:SetLifeTime(1)
  59.         p:SetDieTime(1+(math.random()*3))
  60.         p:SetGravity(physenv.GetGravity())
  61.        
  62.         p:SetBounce(0.5)
  63.         p:SetCollide(true)
  64.         p:SetCollideCallback(OnCollide)
  65.         end
  66.        
  67.         if data.time < CurTime() then
  68.         table.remove(spews, id)
  69.         end
  70.      end
  71.     end
  72. end
  73.  
  74. hook.Add("Think","blood_spew",SpewThink)
  75.  
  76. SpewBloodEntity(me, me:EyePos() + me:GetAimVector() * 20, VectorRand()*100, 10)
  77.  
Advertisement
Add Comment
Please, Sign In to add comment