Skip to content

Commit 98b0236

Browse files
authored
Slight code cleanup in weapon code (#1820)
Noticed things could be tidied a bit in these two files (I don't think this warrants an entry in the changelog)
1 parent 33ce917 commit 98b0236

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

gamemodes/terrortown/entities/weapons/weapon_ttt_flaregun.lua

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,26 @@ end
188188
---
189189
-- @ignore
190190
function SWEP:ShootFlare()
191+
local owner = self:GetOwner()
192+
193+
if not IsValid(owner) then
194+
return
195+
end
196+
191197
local cone = self.Primary.Cone
198+
192199
local bullet = {}
193200
bullet.Num = 1
194-
bullet.Src = self:GetOwner():GetShootPos()
195-
bullet.Dir = self:GetOwner():GetAimVector()
201+
bullet.Src = owner:GetShootPos()
202+
bullet.Dir = owner:GetAimVector()
196203
bullet.Spread = Vector(cone, cone, 0)
197204
bullet.Tracer = 1
205+
bullet.TracerName = self.Tracer
198206
bullet.Force = 2
199207
bullet.Damage = self.Primary.Damage
200-
bullet.TracerName = self.Tracer
201208
bullet.Callback = IgniteTarget
202209

203-
self:GetOwner():FireBullets(bullet)
210+
owner:FireBullets(bullet)
204211
end
205212

206213
---

gamemodes/terrortown/entities/weapons/weapon_ttt_push.lua

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,13 @@ end
113113
---
114114
-- @ignore
115115
function SWEP:FirePulse(force_fwd, force_up)
116-
if not IsValid(self:GetOwner()) then
116+
local owner = self:GetOwner()
117+
118+
if not IsValid(owner) then
117119
return
118120
end
119121

120-
self:GetOwner():SetAnimation(PLAYER_ATTACK1)
122+
owner:SetAnimation(PLAYER_ATTACK1)
121123

122124
sound.Play(self.Primary.Sound, self:GetPos(), self.Primary.SoundLevel)
123125

@@ -128,15 +130,14 @@ function SWEP:FirePulse(force_fwd, force_up)
128130

129131
local bullet = {}
130132
bullet.Num = num
131-
bullet.Src = self:GetOwner():GetShootPos()
132-
bullet.Dir = self:GetOwner():GetAimVector()
133+
bullet.Src = owner:GetShootPos()
134+
bullet.Dir = owner:GetAimVector()
133135
bullet.Spread = Vector(cone, cone, 0)
134136
bullet.Tracer = 1
137+
bullet.TracerName = "AirboatGunHeavyTracer"
135138
bullet.Force = force_fwd / 10
136139
bullet.Damage = 1
137-
bullet.TracerName = "AirboatGunHeavyTracer"
138140

139-
local owner = self:GetOwner()
140141
local fwd = force_fwd / num
141142
local up = force_up / num
142143

@@ -158,7 +159,7 @@ function SWEP:FirePulse(force_fwd, force_up)
158159
end
159160
end
160161

161-
self:GetOwner():FireBullets(bullet)
162+
owner:FireBullets(bullet)
162163
end
163164

164165
local CHARGE_FORCE_FWD_MIN = 300
@@ -229,17 +230,21 @@ end
229230
function SWEP:Think()
230231
BaseClass.Think(self)
231232

232-
if self.IsCharging and IsValid(self:GetOwner()) and self:GetOwner():IsTerror() then
233-
-- on client this is prediction
234-
if not self:GetOwner():KeyDown(IN_ATTACK2) then
235-
self:ChargedAttack()
236-
return true
237-
end
233+
if self.IsCharging then
234+
local owner = self:GetOwner()
238235

239-
if SERVER and self:GetCharge() < 1 and self.NextCharge < CurTime() then
240-
self:SetCharge(math.min(1, self:GetCharge() + CHARGE_AMOUNT))
236+
if IsValid(owner) and owner:IsTerror() then
237+
-- on client this is prediction
238+
if not owner:KeyDown(IN_ATTACK2) then
239+
self:ChargedAttack()
240+
return true
241+
end
241242

242-
self.NextCharge = CurTime() + CHARGE_DELAY
243+
if SERVER and self:GetCharge() < 1 and self.NextCharge < CurTime() then
244+
self:SetCharge(math.min(1, self:GetCharge() + CHARGE_AMOUNT))
245+
246+
self.NextCharge = CurTime() + CHARGE_DELAY
247+
end
243248
end
244249
end
245250
end

0 commit comments

Comments
 (0)