1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
EFFECT.Mat = Material("effects/yellowflare")
/*---------------------------------------------------------
EFFECT:Init(data)
---------------------------------------------------------*/
function EFFECT:Init(data)
self.StartPos = data:GetStart()
self.EndPos = data:GetOrigin()
self.Dir = self.EndPos - self.StartPos
self.Entity:SetRenderBoundsWS(self.StartPos, self.EndPos)
self.TracerTime = 0.4
// Die when it reaches its target
self.DieTime = CurTime() + self.TracerTime
// Play ricochet sound with random pitch
local vGrav = Vector(0, 0, -450)
local Dir = self.Dir:GetNormalized()
local emitter = ParticleEmitter(self.StartPos)
for i = 1, 10 do
local particle = emitter:Add("effects/yellowflare", self.StartPos)
particle:SetVelocity((Dir + VectorRand() * 0.5) * math.Rand(50, 150))
particle:SetDieTime(math.Rand(0.5, 2))
particle:SetStartAlpha(255)
particle:SetStartSize(math.Rand(2, 4))
particle:SetEndSize(0)
particle:SetRoll(0)
particle:SetGravity(vGrav * 0.4)
particle:SetCollide(true)
particle:SetBounce(0.8)
particle:SetAirResistance(50)
particle:SetStartLength(0.2)
particle:SetEndLength(0)
particle:SetVelocityScale(true)
particle:SetCollide(true)
end
local particle = emitter:Add("effects/yellowflare", self.StartPos)
particle:SetDieTime(0.1)
particle:SetStartAlpha(255)
particle:SetStartSize(128)
particle:SetEndSize(0)
particle:SetRoll(math.Rand(0, 360))
local particle = emitter:Add("effects/yellowflare", self.StartPos)
particle:SetDieTime(0.4)
particle:SetStartAlpha(255)
particle:SetStartSize(32)
particle:SetEndSize(0)
particle:SetRoll(math.Rand(0, 360))
emitter:Finish()
local dlight = DynamicLight(0)
if (dlight) then
dlight.Pos = self.StartPos
dlight.r = 255
dlight.g = 255
dlight.b = 255
dlight.Brightness = 4
dlight.size = 64
dlight.DieTime = CurTime() + 0.1
end
end
/*---------------------------------------------------------
THINK
---------------------------------------------------------*/
function EFFECT:Think()
if (CurTime() > self.DieTime) then return false end
return true
end
/*---------------------------------------------------------
Draw the effect
---------------------------------------------------------*/
function EFFECT:Render()
local fDelta = (self.DieTime - CurTime()) / self.TracerTime
fDelta = math.Clamp(fDelta, 0, 1)
render.SetMaterial(self.Mat)
local sinWave = math.sin(fDelta * math.pi)
local color = Color(255, 255, 255, 255 * fDelta)
render.DrawBeam(self.StartPos, self.EndPos, 8 * fDelta, 0.5, 0.5, color)
end
|