Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- EFFECT_EXPLOSION = {}
- local smoke = {
- "particle/smokesprites_0001",
- "particle/smokesprites_0002",
- "particle/smokesprites_0003",
- "particle/smokesprites_0004",
- "particle/smokesprites_0005",
- "particle/smokesprites_0006",
- "particle/smokesprites_0007",
- "particle/smokesprites_0008",
- "particle/smokesprites_0009",
- "particle/smokesprites_0010",
- "particle/smokesprites_0012",
- "particle/smokesprites_0013",
- "particle/smokesprites_0014",
- "particle/smokesprites_0015",
- "particle/smokesprites_0016",
- }
- local sounds = {
- "ambient/explosions/explode_5.wav",
- "ambient/explosions/explode_8.wav",
- }
- function EFFECT_EXPLOSION:ChooseMaterial(typ)
- if typ == "fire" then
- return "particles/flamelet"..math.random(1,5)
- elseif typ == "smoke" then
- return table.Random(smoke)
- end
- end
- function EFFECT_EXPLOSION:DrawSunBeamsInWorld(position, amount, size)
- if util.QuickTrace(EyePos(), position-EyePos(), {LocalPlayer()}).HitWorld then return end
- local screenPos = position:ToScreen()
- DrawSunbeams( 0, amount*math.Clamp(LocalPlayer():GetAimVector():DotProduct((position-EyePos()):Normalize())-0.5, 0, 1) * 2, size, screenPos.x / ScrW(), screenPos.y / ScrH())
- end
- local thinks = {}
- hook.Add("Think", "ParticleHackThink:Think", function()
- for key, func in pairs(thinks) do
- func()
- end
- end)
- function _R.CLuaParticle:HackThink(callback)
- local unique = tostring(self)
- thinks[unique] = callback
- timer.Simple(self:GetDieTime(), function()
- thinks[unique] = nil
- end)
- end
- function EFFECT_EXPLOSION:Init( data )
- local scale = data:GetScale()
- local armsize = data:GetRadius()
- local light = DynamicLight( tostring(self) )
- if light then
- light.Pos = data:GetOrigin()
- light.r = 255
- light.g = 50
- light.b = 0
- light.Brightness = 1*scale
- light.Size = 1000*scale
- light.Decay = 1000
- light.DieTime = CurTime()+2
- end
- WorldSound( table.Random(sounds), data:GetOrigin(), 160, math.random(70,130) )
- local origin = data:GetOrigin()
- local normal = data:GetNormal() / 3
- print(normal)
- local arms = math.Round(math.Clamp(50 * scale, 10, 70))
- local emitter = ParticleEmitter( origin )
- self.data = data
- local wind = Vector(math.random(-200,200),math.random(-200,200),math.random(-50,50)) * scale
- self.lifespan = 0
- for i=0, arms do
- local color = math.random(200,255)
- local lightball = emitter:Add( "sprites/light_glow02_add", origin )
- if lightball then
- local life = math.Rand(0.5, 1)
- self.lifespan = self.lifespan + life
- local vec = VectorRand() + normal
- lightball:SetVelocity( (vec * 10 + Vector(0,0,vec.z)) * math.random(100,200) * scale)
- lightball:SetDieTime( life )
- lightball:SetStartAlpha( 50 )
- lightball:SetEndAlpha( 50 )
- lightball:SetStartSize( math.random(300,400) * scale * armsize )
- lightball:SetEndSize( 0 )
- lightball:SetColor(255,color,color/1.5)
- lightball:SetAirResistance( 0 )
- lightball:SetGravity( Vector( 0, 0, -600 ) )
- lightball:SetCollide(true)
- lightball:SetBounce(0.2)
- local arm = ParticleEmitter( origin )
- local alpha = life * 255
- lightball:HackThink(function()
- alpha = alpha - 1
- local fire = arm:Add( self:ChooseMaterial("fire"), lightball:GetPos() )
- if fire then
- fire:SetDieTime( life )
- fire:SetStartAlpha( alpha / 2 )
- fire:SetEndAlpha( 0 )
- fire:SetAngles(Angle(math.random(360),math.random(360),math.random(360)))
- fire:SetStartSize( 0 )
- fire:SetEndSize( math.random(50,300) /2 * scale * armsize )
- fire:SetColor(255,255,255)
- fire:SetRoll( math.Rand(-0.5, 0.5) )
- fire:SetRollDelta( math.Rand(-0.5, 0.5) )
- fire:SetAirResistance( 30 )
- fire:SetGravity(wind)
- end
- local smoke = arm:Add( self:ChooseMaterial("smoke"), lightball:GetPos() )
- local color = math.random(20,50)
- if smoke then
- smoke:SetDieTime( life*3 )
- smoke:SetStartAlpha( alpha )
- smoke:SetEndAlpha( 0 )
- smoke:SetAngles(Angle(math.random(360),math.random(360),math.random(360)))
- smoke:SetStartSize( 0 )
- smoke:SetEndSize( math.random(100,400) * scale * armsize )
- smoke:SetColor(color,color,color)
- smoke:SetRoll( math.Rand(-0.5, 0.5) )
- smoke:SetRollDelta( math.Rand(-0.5, 0.5) )
- smoke:SetAirResistance( 30 )
- smoke:SetGravity(wind)
- smoke:SetCollide(true)
- end
- arm:Finish()
- end)
- lightball:SetNextThink(CurTime()+0.05)
- end
- end
- emitter:Finish()
- self.lifespan = self.lifespan/arms
- end
- function EFFECT_EXPLOSION:Think()
- self.lifespan = self.lifespan - .01
- if self.lifespan > 0 then
- return true
- end
- return false
- end
- function EFFECT_EXPLOSION:Render()
- local data = self.data
- self:DrawSunBeamsInWorld(data:GetOrigin(), self.lifespan/10, 0.1)
- end
- local e = EffectData()
- local caps = player.GetByUniqueID(--[[CapsAdmin]] "1416729906")
- e:SetOrigin(caps:GetEyeTrace().HitPos)
- e:SetNormal(caps:GetEyeTrace().HitNormal)
- e:SetScale(1) -- size of the explosion
- e:SetRadius(1) -- armsize
- EFFECT_EXPLOSION:Init(e)
- hook.Add("RenderScreenspaceEffects", 1, function()
- EFFECT_EXPLOSION:Render()
- if not EFFECT_EXPLOSION:Think() then
- hook.Remove("RenderScreenspaceEffects", 1)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment