CapsAdmin

Untitled

Nov 8th, 2011
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.16 KB | None | 0 0
  1. EFFECT_EXPLOSION = {}
  2.  
  3. local smoke = {
  4.     "particle/smokesprites_0001",
  5.     "particle/smokesprites_0002",
  6.     "particle/smokesprites_0003",
  7.     "particle/smokesprites_0004",
  8.     "particle/smokesprites_0005",
  9.     "particle/smokesprites_0006",
  10.     "particle/smokesprites_0007",
  11.     "particle/smokesprites_0008",
  12.     "particle/smokesprites_0009",
  13.     "particle/smokesprites_0010",
  14.     "particle/smokesprites_0012",
  15.     "particle/smokesprites_0013",
  16.     "particle/smokesprites_0014",
  17.     "particle/smokesprites_0015",
  18.     "particle/smokesprites_0016",
  19. }
  20.  
  21. local sounds = {
  22.     "ambient/explosions/explode_5.wav",
  23.     "ambient/explosions/explode_8.wav",
  24. }
  25.  
  26. function EFFECT_EXPLOSION:ChooseMaterial(typ)
  27.     if typ == "fire" then
  28.         return "particles/flamelet"..math.random(1,5)
  29.     elseif typ == "smoke" then
  30.         return table.Random(smoke)
  31.     end
  32. end
  33.  
  34. function EFFECT_EXPLOSION:DrawSunBeamsInWorld(position, amount, size)
  35.     if util.QuickTrace(EyePos(), position-EyePos(), {LocalPlayer()}).HitWorld then return end
  36.     local screenPos = position:ToScreen()
  37.     DrawSunbeams( 0, amount*math.Clamp(LocalPlayer():GetAimVector():DotProduct((position-EyePos()):Normalize())-0.5, 0, 1) * 2, size, screenPos.x / ScrW(), screenPos.y / ScrH())
  38. end
  39.  
  40. local thinks = {}
  41.  
  42. hook.Add("Think", "ParticleHackThink:Think", function()
  43.     for key, func in pairs(thinks) do
  44.         func()
  45.     end
  46. end)
  47.  
  48. function _R.CLuaParticle:HackThink(callback)
  49.     local unique = tostring(self)
  50.     thinks[unique] = callback
  51.     timer.Simple(self:GetDieTime(), function()
  52.         thinks[unique] = nil
  53.     end)
  54. end
  55.  
  56. function EFFECT_EXPLOSION:Init( data )
  57.  
  58.     local scale = data:GetScale()
  59.     local armsize = data:GetRadius()
  60.  
  61.     local light = DynamicLight( tostring(self) )
  62.  
  63.     if light then
  64.         light.Pos = data:GetOrigin()
  65.         light.r = 255
  66.         light.g = 50
  67.         light.b = 0
  68.         light.Brightness = 1*scale
  69.         light.Size = 1000*scale
  70.         light.Decay = 1000
  71.         light.DieTime = CurTime()+2
  72.     end
  73.  
  74.     WorldSound( table.Random(sounds), data:GetOrigin(), 160, math.random(70,130) )
  75.  
  76.     local origin = data:GetOrigin()
  77.     local normal = data:GetNormal() / 3
  78.     print(normal)
  79.     local arms = math.Round(math.Clamp(50 * scale, 10, 70))
  80.  
  81.     local emitter = ParticleEmitter( origin )
  82.  
  83.     self.data = data
  84.  
  85.     local wind = Vector(math.random(-200,200),math.random(-200,200),math.random(-50,50)) * scale
  86.  
  87.     self.lifespan = 0
  88.  
  89.     for i=0, arms do
  90.         local color = math.random(200,255)
  91.         local lightball = emitter:Add( "sprites/light_glow02_add", origin )
  92.  
  93.         if lightball then
  94.             local life = math.Rand(0.5, 1)
  95.             self.lifespan = self.lifespan + life
  96.  
  97.             local vec = VectorRand() + normal
  98.             lightball:SetVelocity( (vec * 10 + Vector(0,0,vec.z)) * math.random(100,200) * scale)
  99.             lightball:SetDieTime( life )
  100.             lightball:SetStartAlpha( 50 )
  101.             lightball:SetEndAlpha( 50 )
  102.             lightball:SetStartSize( math.random(300,400) * scale * armsize )
  103.             lightball:SetEndSize( 0 )
  104.             lightball:SetColor(255,color,color/1.5)
  105.             lightball:SetAirResistance( 0 )
  106.             lightball:SetGravity( Vector( 0, 0, -600 ) )
  107.             lightball:SetCollide(true)
  108.             lightball:SetBounce(0.2)
  109.  
  110.             local arm = ParticleEmitter( origin )
  111.  
  112.             local alpha = life * 255
  113.  
  114.             lightball:HackThink(function()
  115.  
  116.                 alpha = alpha - 1
  117.  
  118.                 local fire = arm:Add( self:ChooseMaterial("fire"), lightball:GetPos()    )
  119.  
  120.                 if fire then
  121.                     fire:SetDieTime( life )
  122.                     fire:SetStartAlpha( alpha / 2 )
  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 * scale * armsize )
  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.                 end
  133.  
  134.                 local smoke = arm:Add( self:ChooseMaterial("smoke"), lightball:GetPos() )
  135.                 local color = math.random(20,50)
  136.  
  137.                 if smoke then
  138.                     smoke:SetDieTime( life*3 )
  139.                     smoke:SetStartAlpha( alpha )
  140.                     smoke:SetEndAlpha( 0 )
  141.                     smoke:SetAngles(Angle(math.random(360),math.random(360),math.random(360)))
  142.                     smoke:SetStartSize( 0 )
  143.                     smoke:SetEndSize( math.random(100,400) * scale * armsize )
  144.                     smoke:SetColor(color,color,color)
  145.                     smoke:SetRoll( math.Rand(-0.5, 0.5) )
  146.                     smoke:SetRollDelta( math.Rand(-0.5, 0.5) )
  147.                     smoke:SetAirResistance( 30 )
  148.                     smoke:SetGravity(wind)
  149.                     smoke:SetCollide(true)
  150.                 end
  151.                 arm:Finish()
  152.             end)
  153.             lightball:SetNextThink(CurTime()+0.05)
  154.         end
  155.     end
  156.     emitter:Finish()
  157.     self.lifespan = self.lifespan/arms
  158. end
  159.  
  160. function EFFECT_EXPLOSION:Think()
  161.     self.lifespan = self.lifespan - .01
  162.     if self.lifespan > 0 then
  163.         return true
  164.     end
  165.     return false
  166. end
  167.  
  168. function EFFECT_EXPLOSION:Render()
  169.     local data = self.data
  170.     self:DrawSunBeamsInWorld(data:GetOrigin(), self.lifespan/10, 0.1)
  171. end
  172.  
  173. local e = EffectData()
  174. local caps = player.GetByUniqueID(--[[CapsAdmin]] "1416729906")
  175. e:SetOrigin(caps:GetEyeTrace().HitPos)
  176. e:SetNormal(caps:GetEyeTrace().HitNormal)
  177. e:SetScale(1) -- size of the explosion
  178. e:SetRadius(1) -- armsize
  179. EFFECT_EXPLOSION:Init(e)
  180.  
  181. hook.Add("RenderScreenspaceEffects", 1, function()
  182.     EFFECT_EXPLOSION:Render()
  183.     if not EFFECT_EXPLOSION:Think() then
  184.         hook.Remove("RenderScreenspaceEffects", 1)
  185.     end
  186. end)
  187.  
Advertisement
Add Comment
Please, Sign In to add comment