CapsAdmin

Untitled

Jun 18th, 2013
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.08 KB | None | 0 0
  1. local pos = here
  2. local emitter = ParticleEmitter(vector_origin)
  3.  
  4. local particles = {}
  5.  
  6. local sounds =
  7. {
  8.     "npc/headcrab_poison/ph_step2.wav",
  9.     "npc/headcrab_poison/ph_step3.wav",
  10.     "npc/headcrab_poison/ph_step4.wav",
  11. }
  12.  
  13. local WorldSound = WorldSound
  14. local math_random = math.random
  15.  
  16. local function collide(self, pos, normal)
  17.     WorldSound(sounds[math_random(#sounds)], pos, 60, math_random(25, 70))
  18. end
  19.  
  20. local gravity = physenv.GetGravity() * 0.5
  21. local vel = Vector()
  22. local sdir = Vector()
  23.  
  24. local function Think()
  25.     local delta = FrameTime()
  26.     local c = HSVToColor(CurTime() * 30%360, 0.5, 1)
  27.     sdir = sdir + ((VectorRand() - sdir) * delta)
  28.    
  29.     for i = 1, 2 do
  30.         local particle = emitter:Add("sprites/light_glow02_add", pos)
  31.  
  32.         vel.x = math.Rand(-1, 1) * 25
  33.         vel.y = math.Rand(-1, 1) * 25
  34.         vel.z = math.Rand(2.5, 5) * 50
  35.        
  36.         vel.x = vel.x + sdir.x * 100
  37.         vel.y = vel.y + sdir.y * 100
  38.         vel.z = vel.z + sdir.z * 100
  39.  
  40.         -- movement
  41.         particle:SetVelocity(vel)
  42.         particle:SetAirResistance(0)
  43.         particle:SetGravity(gravity)
  44.  
  45.         particle:SetCollide(true)
  46.         particle:SetBounce(0.25)
  47.  
  48.         -- appearance
  49.         particle:SetColor(c.r, c.g, c.b)
  50.         particle.clr = c
  51.  
  52.         particle:SetStartAlpha(255)
  53.         particle:SetEndAlpha(0)
  54.  
  55.         particle:SetStartSize(10)
  56.         particle:SetEndSize(0)
  57.  
  58.         particle:SetDieTime(math.Rand(1.5, 2.5))
  59.  
  60.         particle:SetStartLength(0)
  61.         particle:SetEndLength(0)
  62.         particle:SetCollideCallback(collide)
  63.  
  64.         table.insert(particles, particle)
  65.     end
  66. end
  67.  
  68. local mat = Material("particle/Particle_Glow_04_Additive")
  69.  
  70. local render_DrawBeam = render.DrawBeam
  71. local render_SetMaterial = render.SetMaterial
  72.  
  73. hook.Add("PostDrawTranslucentRenderables", 1, function()
  74.     for key, particle in pairs(particles) do
  75.         local delta = particle:GetDieTime() - particle:GetLifeTime()
  76.  
  77.         if delta > 0 then
  78.             local pos = particle:GetPos()
  79.             local vel = particle:GetVelocity()
  80.  
  81.             render_SetMaterial(mat)
  82.             render_DrawBeam(pos + vel * 0.05, pos - vel * 0.25, 1 * delta, 0, 1, particle.clr)
  83.         else
  84.             particles[key] = nil
  85.         end
  86.     end
  87. end)
  88.  
  89. hook.Add("Think", "particle_test", Think)
Advertisement
Add Comment
Please, Sign In to add comment