CapsAdmin

Untitled

Jan 23rd, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.40 KB | None | 0 0
  1. local fire = {
  2.     "particles/flamelet1",
  3.     "particles/flamelet2",
  4.     "particles/flamelet3",
  5.     "particles/flamelet4",
  6.     "particles/flamelet5",
  7. }
  8.  
  9. local smoke = {
  10.     "particle/smokesprites_0001",
  11.     "particle/smokesprites_0002",
  12.     "particle/smokesprites_0003",
  13.     "particle/smokesprites_0004",
  14.     "particle/smokesprites_0005",
  15.     "particle/smokesprites_0006",
  16.     "particle/smokesprites_0007",
  17.     "particle/smokesprites_0008",
  18.     "particle/smokesprites_0009",
  19.     "particle/smokesprites_0010",
  20.     "particle/smokesprites_0012",
  21.     "particle/smokesprites_0013",
  22.     "particle/smokesprites_0014",
  23.     "particle/smokesprites_0015",
  24.     "particle/smokesprites_0016",
  25. }
  26.  
  27. local sounds = {
  28.     "ambient/explosions/explode_5.wav",
  29.     "ambient/explosions/explode_8.wav",
  30. }
  31.  
  32. local function draw_sunbeams(pos, amount, size)
  33.     local ply = LocalPlayer()
  34.     local eye_pos = EyePos()
  35.     if util.QuickTrace(eye_pos, pos - eye_pos, {ply}).HitWorld then return end
  36.    
  37.     local screen_pos = pos:ToScreen()
  38.     DrawSunbeams(
  39.         0,
  40.         amount * math.Clamp(ply:GetAimVector():DotProduct((pos - eye_pos):GetNormalized()) - 0.5, 0, 1) * 2,
  41.         size,
  42.         screen_pos.x / ScrW(),
  43.         screen_pos.y / ScrH()
  44.     )
  45. end
  46.  
  47. local explosions = {}
  48.  
  49. hook.Add("Think", "explosion_think", function()
  50.     for key, data in pairs(explosions) do
  51.         for _, think in pairs(data.arms) do
  52.             think()
  53.         end
  54.         if data.think() ~= nil then
  55.             explosions[key] = nil
  56.         end
  57.     end
  58. end)
  59.  
  60. hook.Add("RenderScreenspaceEffects", "explosion_render", function()
  61.     for key, data in pairs(explosions) do
  62.         data.render()
  63.     end
  64. end)
  65.  
  66. local emitter = ParticleEmitter(Vector())
  67.  
  68. local function explode(origin, normal, size, arm_size)
  69.  
  70.     size = size or 1
  71.     arm_size = arm_size or 1
  72.    
  73.     local explosion = {arms = {}}
  74.  
  75.     local light = DynamicLight(tostring(origin))
  76.    
  77.     light.Pos = origin
  78.     light.r = 255
  79.     light.g = 50
  80.     light.b = 0
  81.     light.Brightness = 1 * size
  82.     light.Size = 1000 * size
  83.     light.Decay = 1000
  84.     light.DieTime = CurTime() + 2
  85.  
  86.     sound.Play(table.Random(sounds), origin, 160, math.random(70, 130))
  87.  
  88.     local arm_count = math.Round(math.Clamp(50 * size, 10, 70))
  89.     local wind = Vector(math.random(-200, 200), math.random(-200, 200), math.random(-50, 50)) * size
  90.  
  91.     local lifespan = 0
  92.  
  93.     for i = 0, arm_count do
  94.         local color = math.random(200,255)
  95.         local lightball = emitter:Add("sprites/light_glow02_add", origin)
  96.  
  97.         local life = math.Rand(0.5, 1)
  98.         lifespan = lifespan + life
  99.  
  100.         local vec = VectorRand() + normal
  101.         lightball:SetVelocity((vec * 10 + Vector(0, 0, vec.z)) * math.random(100,200) * size)
  102.         lightball:SetDieTime(life)
  103.         lightball:SetStartAlpha(50)
  104.         lightball:SetEndAlpha(50)
  105.         lightball:SetStartSize(math.random(300,400) * size * arm_size)
  106.         lightball:SetEndSize(0)
  107.         lightball:SetColor(255, color, color/1.5)
  108.         lightball:SetAirResistance(0)
  109.         lightball:SetGravity(physenv.GetGravity())
  110.         lightball:SetCollide(true)
  111.         lightball:SetBounce(0.2)
  112.  
  113.         local alpha = life * 255
  114.  
  115.         table.insert(explosion.arms, function()
  116.            
  117.             alpha = math.max(alpha - FrameTime() * 100, 0)
  118.    
  119.             local fire = emitter:Add(table.Random(fire), lightball:GetPos() )
  120.  
  121.                 fire:SetDieTime(life)
  122.                 fire:SetStartAlpha(alpha)
  123.                 fire:SetEndAlpha(0)
  124.                 fire:SetAngles(Angle(math.random(360), math.random(360), math.random(360)))
  125.                 fire:SetStartSize(0)
  126.                 fire:SetEndSize(math.random(50, 300) / 2 * size * arm_size)
  127.                 fire:SetColor(255,255,255)
  128.                 fire:SetRoll(math.Rand(-0.5, 0.5))
  129.                 fire:SetRollDelta(math.Rand(-0.5, 0.5))
  130.                 fire:SetAirResistance(30)
  131.                 fire:SetGravity(wind)
  132.  
  133.             local smoke = emitter:Add(table.Random(smoke), lightball:GetPos())
  134.                
  135.                 local color = math.random(20,50)
  136.                
  137.                 smoke:SetDieTime(life*3)
  138.                 smoke:SetStartAlpha(alpha)
  139.                 smoke:SetEndAlpha(0)
  140.                 smoke:SetAngles(Angle(math.random(360), math.random(360), math.random(360)))
  141.                 smoke:SetStartSize(0)
  142.                 smoke:SetEndSize(math.random(100,400) * size * arm_size)
  143.                 smoke:SetColor(color, color, color)
  144.                 smoke:SetRoll(math.Rand(-0.5, 0.5))
  145.                 smoke:SetRollDelta(math.Rand(-0.5, 0.5))
  146.                 smoke:SetAirResistance(30)
  147.                 smoke:SetGravity(wind)
  148.                 smoke:SetCollide(true)
  149.                    
  150.         end)
  151.     end
  152.    
  153.     lifespan = lifespan / arm_count
  154.    
  155.     explosion.render = function()
  156.         draw_sunbeams(origin, lifespan / 10, 0.1)
  157.     end
  158.        
  159.     explosion.think = function()
  160.         lifespan = lifespan - FrameTime()
  161.         if lifespan < 0 then
  162.             return true
  163.         end
  164.     end
  165.    
  166.     table.insert(explosions, explosion)
  167. end
  168.  
  169. explode(there, trace.HitNormal)
Advertisement
Add Comment
Please, Sign In to add comment