New muzzle flashes!

This commit is contained in:
Fesiug 2023-11-18 03:40:31 -05:00
parent 240af4a438
commit 9d25f5751c
2 changed files with 195 additions and 25 deletions

View File

@ -1,34 +1,196 @@
AddCSLuaFile()
local mat_flash, mat_arm, mat_beam, mat_spark = Material( "benny/effects/flash.png" ), Material( "benny/effects/flash_arm.png" ), Material( "benny/effects/flash_beam.png" ), Material( "benny/effects/flash_spark.png" )
local rba = Vector( 8, 8, 8 )
local rbb = -rba
function EFFECT:Init( data )
-- Because CEffectData is a shared object, we can't just store it and use its' properties later
-- Instead, we store the properties themselves
self.offset = data:GetOrigin() + Vector( 0, 0, 0.2 )
self.offset = data:GetOrigin()
self.angles = data:GetAngles()
self.particles = 4
self.el = data:GetEntity()
self.en = data:GetEntity()
if IsValid(self.en.CWM) then self.en = self.en.CWM end
self.ea = data:GetAttachment()
self.particles = 1
self.CreationTime = CurTime()
self.DieTime = CurTime() + 0.05
self:SetRenderBounds( rbb, rba )
self.RandomRoll1 = math.Rand( 0, 1 )
self.RandomRoll2 = math.Rand( 0, 1 )
--self.RandomRoll3 = math.Rand( 0, 1 )
local dlight = DynamicLight( self.el:EntIndex() )
if ( dlight ) then
dlight.Pos = self.el:GetPos() + self.el:GetAngles():Forward()*24 + self.el:GetAngles():Up()*16
dlight.r = 255
dlight.g = 200
dlight.b = 150
dlight.Brightness = 4
dlight.Size = 72*1.5
dlight.DieTime = CurTime() + 0.07
dlight.Decay = 72*20
end
-- Smoke!
local atti = self.en:GetAttachment( self.ea )
if true then
local emitter = ParticleEmitter( atti.Pos, false )
for i=1, 2 do
local p = emitter:Add( "particles/smokey", atti.Pos )
if p then
p:SetAngles( atti.Ang )
p:SetVelocity( atti.Ang:Forward()*64 + VectorRand( -32, 32 ) )
p:SetGravity( Vector( 0, 0, 50 ))
p:SetRoll( 0 )
p:SetRollDelta( math.pi*.5 )
p:SetColor( 255, 255, 255 )
p:SetLifeTime( 0 )
p:SetDieTime( 1 )
p:SetLighting( true )
p:SetStartAlpha( 14 )
p:SetEndAlpha( 0 )
p:SetStartSize( 8 )
p:SetEndSize( 64 )
end
end
end
-- Spark!
local atti = self.en:GetAttachment( self.ea )
if true then
local emitter = ParticleEmitter( atti.Pos, false )
for i=1, 8 do
local p = emitter:Add( mat_spark, atti.Pos )
if p then
p:SetAngles( atti.Ang )
p:SetVelocity( atti.Ang:Forward()*64*i )
p:SetRoll( math.Rand( 0, 1 )*math.pi*2*8 )
p:SetRollDelta( 0 )
p:SetColor( 255, 255, 255 )
p:SetLifeTime( 0 )
p:SetDieTime( .05 )
p:SetLighting( false )
p:SetStartAlpha( 63 )
p:SetEndAlpha( 0 )
p:SetStartSize( 4 )
p:SetEndSize( 2 )
end
end
end
end
function EFFECT:Think()
return true
return (self.DieTime >= CurTime()) -- Return false to kill
end
function EFFECT:Render()
local emitter = ParticleEmitter( self.offset, false )
for i=0, self.particles do
local particle = emitter:Add( "effects/softglow", self.offset )
if particle then
particle:SetAngles( self.angles )
particle:SetVelocity( Vector( 0, 0, 15 ) )
particle:SetColor( 255, 102, 0 )
particle:SetLifeTime( 0 )
particle:SetDieTime( 0.2 )
particle:SetStartAlpha( 255 )
particle:SetEndAlpha( 0 )
particle:SetStartSize( 1.6 )
particle:SetStartLength( 1 )
particle:SetEndSize( 1.2 )
particle:SetEndLength( 4 )
local atti = self.en:GetAttachment( self.ea )
local tf = 1-math.TimeFraction( self.DieTime, self.CreationTime, CurTime() )
-- Big flash!
if true then
local emitter = ParticleEmitter( atti.Pos + EyeAngles():Forward()*-16, false )
for i=1, 1 do
local p = emitter:Add( mat_flash, atti.Pos )
if p then
p:SetAngles( atti.Ang )
p:SetVelocity( vector_origin )
p:SetRoll( 0 )
p:SetRollDelta( 0 )
p:SetColor( 255, 255, 255 )
p:SetLifeTime( 0 )
p:SetDieTime( FrameTime()+0.001 )
p:SetStartAlpha( 255 )
p:SetEndAlpha( 255 )
p:SetStartSize( Lerp( tf, 6, 0 ) )
p:SetEndSize( Lerp( tf, 6, 0 ) )
p:SetNextThink( CurTime() )
p:SetThinkFunction( function( pa )
timer.Simple( 0, function()
pa:SetStartAlpha( 0 )
pa:SetEndAlpha( 0 )
end)
pa:SetNextThink( CurTime() )
end)
end
end
emitter:Finish()
end
-- Long stick!
if true then
local emitter = ParticleEmitter( atti.Pos, false )
for i=1, 1 do
local p = emitter:Add( mat_beam, atti.Pos )
if p then
p:SetAngles( atti.Ang )
p:SetVelocity( atti.Ang:Forward() / (2^16) )
p:SetRoll( 0 )
p:SetRollDelta( 0 )
p:SetColor( 255, 250, 150 )
p:SetLifeTime( 0 )
p:SetDieTime( FrameTime()+0.001 )
p:SetStartAlpha( math.Clamp( Lerp( tf, 127, -127 ), 0, 255 ) )
p:SetEndAlpha( math.Clamp( Lerp( tf, 127, -127 ), 0, 255 ) )
p:SetStartSize( Lerp( tf, 16, 4 ) )
p:SetStartLength( Lerp( tf, 12, 16 ) )
p:SetEndSize( Lerp( tf, 16, 4 ) )
p:SetEndLength( Lerp( tf, 12, 16 ) )
p:SetNextThink( CurTime() )
p:SetThinkFunction( function( pa )
timer.Simple( 0, function()
pa:SetStartAlpha( 0 )
pa:SetEndAlpha( 0 )
end)
pa:SetNextThink( CurTime() )
end)
end
end
end
-- Big arms!
if true then
local emitter = ParticleEmitter( atti.Pos, false )
for i=0, 3 do
local meep = Angle( atti.Ang )
meep:RotateAroundAxis( atti.Ang:Right(), (i/4)*360 + (self.RandomRoll1*360) )
meep:RotateAroundAxis( atti.Ang:Up(), 90 )
local pointy = atti.Ang:Forward()
pointy:Mul( 0.25 )
pointy:Add( meep:Forward() )
local p = emitter:Add( mat_arm, atti.Pos )
if p then
p:SetAngles( atti.Ang )
p:SetVelocity( pointy )
p:SetRoll( 0 )
p:SetRollDelta( 0 )
p:SetColor( 255, 255, 230 )
p:SetLifeTime( 0 )
p:SetDieTime( FrameTime()+0.001 )
p:SetStartAlpha( Lerp( tf, 64, 0 ) )
p:SetEndAlpha( Lerp( tf, 64, 0 ) )
p:SetStartSize( Lerp( tf, 1, 12 ) )
p:SetStartLength( Lerp( tf, 10, 1 ) )
p:SetEndSize( Lerp( tf, 1, 12 ) )
p:SetEndLength( Lerp( tf, 10, 1 ) )
p:SetNextThink( CurTime() )
p:SetThinkFunction( function( pa )
timer.Simple( 0, function()
pa:SetStartAlpha( 0 )
pa:SetEndAlpha( 0 )
end)
pa:SetNextThink( CurTime() )
end)
end
end
end
end

View File

@ -42,12 +42,20 @@ function SWEP:BFire( hand )
if CLIENT and IsFirstTimePredicted() then
local vStart = self:GetAttachment( 1 ).Pos
local vPoint = p:GetEyeTrace().HitPos
local effectdata = EffectData()
effectdata:SetStart( vStart )
effectdata:SetOrigin( vPoint )
util.Effect( "ToolTracer", effectdata )
if IsValid(self.CWM) then
local vStart = self.CWM:GetAttachment( 1 ).Pos
--local vPoint = p:GetEyeTrace().HitPos
--local effectdata = EffectData()
--effectdata:SetStart( vStart )
--effectdata:SetOrigin( vPoint )
--util.Effect( "ToolTracer", effectdata )
local ed = EffectData()
ed:SetOrigin( vStart )
--ed:SetAngles( Angle() )
ed:SetEntity( self )
ed:SetAttachment( 1 )
util.Effect( "benny_muzzleflash", ed )
end
end
end
end