Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Commit

Permalink
Replace 'self.Owner' with 'self:GetOwner()'
Browse files Browse the repository at this point in the history
- Replace 'self.Owner' with 'self:GetOwner()'
- AUG: Add check if there's any ammunation before playing the reload animation
  • Loading branch information
MinIsMin committed Nov 7, 2017
1 parent b0b9542 commit 99356ec
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 61 deletions.
5 changes: 3 additions & 2 deletions lua/weapons/weapon_ghost_augbar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ function SWEP:SetZoom(state)
return
else
if state then
self.Owner:SetFOV(20, 0.3)
self:GetOwner():SetFOV(20, 0.3)
else
self.Owner:SetFOV(0, 0.2)
self:GetOwner():SetFOV(0, 0.2)
end
end
end
Expand Down Expand Up @@ -87,6 +87,7 @@ function SWEP:PreDrop()
end

function SWEP:Reload()
if ( self:Clip1() == self.Primary.ClipSize or self:GetOwner():GetAmmoCount( self.Primary.Ammo ) <= 0 ) then return end
self.Weapon:DefaultReload(ACT_VM_RELOAD)
self:SetIronsights( false )
self:SetZoom(false)
Expand Down
4 changes: 2 additions & 2 deletions lua/weapons/weapon_ghost_awp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ function SWEP:SetZoom(state)
return
else
if state then
self.Owner:SetFOV(20, 0.3)
self:GetOwner():SetFOV(20, 0.3)
else
self.Owner:SetFOV(0, 0.2)
self:GetOwner():SetFOV(0, 0.2)
end
end
end
Expand Down
50 changes: 25 additions & 25 deletions lua/weapons/weapon_ghost_base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,12 @@ function SWEP:PrimaryAttack(worldsnd)

if not self:CanPrimaryAttack() then return end

if CLIENT and LocalPlayer() == self.Owner then
if CLIENT and LocalPlayer() == self:GetOwner() then
self.Weapon:EmitSound( self.Primary.Sound, self.Primary.SoundLevel )
else
local tbl = {}
for k, v in ipairs(player.GetAll()) do
if v != self.Owner and v:IsGhost() then
if v != self:GetOwner() and v:IsGhost() then
table.insert(tbl, v)
end
end
Expand All @@ -252,14 +252,14 @@ function SWEP:PrimaryAttack(worldsnd)

self:TakePrimaryAmmo( 1 )

local owner = self.Owner
local owner = self:GetOwner()
if not IsValid(owner) or owner:IsNPC() or (not owner.ViewPunch) then return end

owner:ViewPunch( Angle( math.Rand(-0.2,-0.1) * self.Primary.Recoil, math.Rand(-0.1,0.1) * self.Primary.Recoil, 0 ) )
end

function SWEP:DryFire(setnext)
if CLIENT and LocalPlayer() == self.Owner then
if CLIENT and LocalPlayer() == self:GetOwner() then
self:EmitSound( "Weapon_Pistol.Empty" )
end

Expand All @@ -276,7 +276,7 @@ function SWEP:ShootEffects()
end

function SWEP:CanPrimaryAttack()
if not IsValid(self.Owner) then return end
if not IsValid(self:GetOwner()) then return end

if self.Weapon:Clip1() <= 0 then
self:DryFire(self.SetNextPrimaryFire)
Expand All @@ -286,7 +286,7 @@ function SWEP:CanPrimaryAttack()
end

function SWEP:CanSecondaryAttack()
if not IsValid(self.Owner) then return end
if not IsValid(self:GetOwner()) then return end

if self.Weapon:Clip2() <= 0 then
self:DryFire(self.SetNextSecondaryFire)
Expand Down Expand Up @@ -319,7 +319,7 @@ end
function SWEP:ShootBullet( dmg, recoil, numbul, cone )

self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
-- self.Owner:SetAnimation( PLAYER_ATTACK1 )
-- self:GetOwner():SetAnimation( PLAYER_ATTACK1 )

if not IsFirstTimePredicted() then return end

Expand All @@ -328,12 +328,12 @@ function SWEP:ShootBullet( dmg, recoil, numbul, cone )
numbul = numbul or 1
cone = cone or 0.01

self.Owner:LagCompensation(true)
self:GetOwner():LagCompensation(true)

local bullet = {}
bullet.Num = numbul
bullet.Src = self.Owner:GetShootPos()
bullet.Dir = self.Owner:GetAimVector()
bullet.Src = self:GetOwner():GetShootPos()
bullet.Dir = self:GetOwner():GetAimVector()
bullet.Spread = Vector( cone, cone, 0 )
bullet.Tracer = 0
bullet.TracerName = self.Tracer or "Tracer"
Expand All @@ -355,25 +355,25 @@ function SWEP:ShootBullet( dmg, recoil, numbul, cone )
end

if SERVER then
self.Owner:FireBullets(bullet)
self:GetOwner():FireBullets(bullet)
elseif LocalPlayer():IsGhost() then
self.Owner:FireBullets(bullet)
self:GetOwner():FireBullets(bullet)
end

self.Owner:LagCompensation(false)
self:GetOwner():LagCompensation(false)

-- Owner can die after firebullet
if (not IsValid(self.Owner)) or (not self.Owner:Alive()) or self.Owner:IsNPC() then return end
if (not IsValid(self:GetOwner())) or (not self:GetOwner():Alive()) or self:GetOwner():IsNPC() then return end

if ((game.SinglePlayer() and SERVER) or
((not game.SinglePlayer()) and CLIENT and IsFirstTimePredicted())) then

-- reduce recoil if ironsighting
recoil = sights and (recoil * 0.6) or recoil

local eyeang = self.Owner:EyeAngles()
local eyeang = self:GetOwner():EyeAngles()
eyeang.pitch = eyeang.pitch - recoil
self.Owner:SetEyeAngles( eyeang )
self:GetOwner():SetEyeAngles( eyeang )
end

end
Expand Down Expand Up @@ -420,17 +420,17 @@ function SWEP:OnRestore()
end

function SWEP:Ammo1()
return IsValid(self.Owner) and self.Owner:GetAmmoCount(self.Primary.Ammo) or false
return IsValid(self:GetOwner()) and self:GetOwner():GetAmmoCount(self.Primary.Ammo) or false
end

-- The OnDrop() hook is useless for this as it happens AFTER the drop. OwnerChange
-- does not occur when a drop happens for some reason. Hence this thing.
function SWEP:PreDrop()
if SERVER and IsValid(self.Owner) and self.Primary.Ammo ~= "none" then
if SERVER and IsValid(self:GetOwner()) and self.Primary.Ammo ~= "none" then
local ammo = self:Ammo1()

-- Do not drop ammo if we have another gun that uses this type
for _, w in pairs(self.Owner:GetWeapons()) do
for _, w in pairs(self:GetOwner():GetWeapons()) do
if IsValid(w) and w ~= self and w:GetPrimaryAmmoType() == self:GetPrimaryAmmoType() then
ammo = 0
end
Expand All @@ -439,7 +439,7 @@ function SWEP:PreDrop()
self.StoredAmmo = ammo

if ammo > 0 then
self.Owner:RemoveAmmo(ammo, self.Primary.Ammo)
self:GetOwner():RemoveAmmo(ammo, self.Primary.Ammo)
end
end
end
Expand Down Expand Up @@ -522,18 +522,18 @@ function SWEP:DyingShot()
end

-- Owner should still be alive here
if IsValid(self.Owner) then
if IsValid(self:GetOwner()) then
local punch = self.Primary.Recoil or 5

-- Punch view to disorient aim before firing dying shot
local eyeang = self.Owner:EyeAngles()
local eyeang = self:GetOwner():EyeAngles()
eyeang.pitch = eyeang.pitch - math.Rand(-punch, punch)
eyeang.yaw = eyeang.yaw - math.Rand(-punch, punch)
self.Owner:SetEyeAngles( eyeang )
self:GetOwner():SetEyeAngles( eyeang )

MsgN(self.Owner:Nick() .. " fired his DYING SHOT")
MsgN(self:GetOwner():Nick() .. " fired his DYING SHOT")

self.Owner.dying_wep = self.Weapon
self:GetOwner().dying_wep = self.Weapon

self:PrimaryAttack(true)

Expand Down
38 changes: 19 additions & 19 deletions lua/weapons/weapon_ghost_crowbar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,24 @@ local sound_single = Sound("Weapon_Crowbar.Single")
function SWEP:PrimaryAttack()
self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )

if not IsValid(self.Owner) then return end
if not IsValid(self:GetOwner()) then return end

if self.Owner.LagCompensation then -- for some reason not always true
self.Owner:LagCompensation(true)
if self:GetOwner().LagCompensation then -- for some reason not always true
self:GetOwner():LagCompensation(true)
end

local spos = self.Owner:GetShootPos()
local sdest = spos + (self.Owner:GetAimVector() * 70)
local spos = self:GetOwner():GetShootPos()
local sdest = spos + (self:GetOwner():GetAimVector() * 70)

local tr_main = util.TraceLine({start=spos, endpos=sdest, filter=self.Owner, mask=MASK_SHOT_HULL})
local tr_main = util.TraceLine({start=spos, endpos=sdest, filter=self:GetOwner(), mask=MASK_SHOT_HULL})
local hitEnt = tr_main.Entity

if CLIENT and LocalPlayer() == self.Owner then
if CLIENT and LocalPlayer() == self:GetOwner() then
self.Weapon:EmitSound(sound_single, self.Primary.SoundLevel )
else
local tbl = {}
for k, v in ipairs(player.GetHumans()) do
if v != self.Owner and v:IsGhost() then
if v != self:GetOwner() and v:IsGhost() then
table.insert(tbl, v)
end
end
Expand Down Expand Up @@ -94,8 +94,8 @@ function SWEP:PrimaryAttack()

-- do a bullet just to make blood decals work sanely
-- need to disable lagcomp because firebullets does its own
self.Owner:LagCompensation(false)
self.Owner:FireBullets({Num=1, Src=spos, Dir=self.Owner:GetAimVector(), Spread=Vector(0,0,0), Tracer=0, Force=1, Damage=0})
self:GetOwner():LagCompensation(false)
self:GetOwner():FireBullets({Num=1, Src=spos, Dir=self:GetOwner():GetAimVector(), Spread=Vector(0,0,0), Tracer=0, Force=1, Damage=0})
else
util.Effect("Impact", edata)
end
Expand All @@ -111,31 +111,31 @@ function SWEP:PrimaryAttack()

-- Do another trace that sees nodraw stuff like func_button
local tr_all = nil
tr_all = util.TraceLine({start=spos, endpos=sdest, filter=self.Owner})
tr_all = util.TraceLine({start=spos, endpos=sdest, filter=self:GetOwner()})

self.Owner:SetAnimation( PLAYER_ATTACK1 )
self:GetOwner():SetAnimation( PLAYER_ATTACK1 )

if hitEnt and hitEnt:IsValid() and hitEnt:IsPlayer() and hitEnt:IsGhost() then

local dmg = DamageInfo()
dmg:SetDamage(self.Primary.Damage)
dmg:SetAttacker(self.Owner)
dmg:SetAttacker(self:GetOwner())
dmg:SetInflictor(self.Weapon)
dmg:SetDamageForce(self.Owner:GetAimVector() * 1500)
dmg:SetDamagePosition(self.Owner:GetPos())
dmg:SetDamageForce(self:GetOwner():GetAimVector() * 1500)
dmg:SetDamagePosition(self:GetOwner():GetPos())
dmg:SetDamageType(DMG_CLUB)
hitEnt:TakeDamageInfo(dmg)

-- self.Weapon:SendWeaponAnim( ACT_VM_HITCENTER )

-- self.Owner:TraceHullAttack(spos, sdest, Vector(-16,-16,-16), Vector(16,16,16), 30, DMG_CLUB, 11, true)
-- self.Owner:FireBullets({Num=1, Src=spos, Dir=self.Owner:GetAimVector(), Spread=Vector(0,0,0), Tracer=0, Force=1, Damage=20})
-- self:GetOwner():TraceHullAttack(spos, sdest, Vector(-16,-16,-16), Vector(16,16,16), 30, DMG_CLUB, 11, true)
-- self:GetOwner():FireBullets({Num=1, Src=spos, Dir=self:GetOwner():GetAimVector(), Spread=Vector(0,0,0), Tracer=0, Force=1, Damage=20})

end
end

if self.Owner.LagCompensation then
self.Owner:LagCompensation(false)
if self:GetOwner().LagCompensation then
self:GetOwner():LagCompensation(false)
end
end

Expand Down
4 changes: 2 additions & 2 deletions lua/weapons/weapon_ghost_hl2smg.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ function SWEP:Reload()

self.Weapon:DefaultReload( ACT_VM_RELOAD )
self:SetIronsights( false )
if CLIENT and LocalPlayer() == self.Owner then
if CLIENT and LocalPlayer() == self:GetOwner() then
self:EmitSound( "Weapon_SMG1.Reload" )
else
local filter = RecipientFilter()
for k, v in ipairs(player.GetHumans()) do
if v != self.Owner and v:IsGhost() then
if v != self:GetOwner() and v:IsGhost() then
filter:AddPlayer(v)
end
end
Expand Down
6 changes: 3 additions & 3 deletions lua/weapons/weapon_ghost_rifle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ function SWEP:SetZoom(state)
return
else
if state then
self.Owner:SetFOV(20, 0.3)
self:GetOwner():SetFOV(20, 0.3)
else
self.Owner:SetFOV(0, 0.2)
self:GetOwner():SetFOV(0, 0.2)
end
end
end
Expand Down Expand Up @@ -81,7 +81,7 @@ function SWEP:PreDrop()
end

function SWEP:Reload()
if ( self:Clip1() == self.Primary.ClipSize or self.Owner:GetAmmoCount( self.Primary.Ammo ) <= 0 ) then return end
if ( self:Clip1() == self.Primary.ClipSize or self:GetOwner():GetAmmoCount( self.Primary.Ammo ) <= 0 ) then return end
self.Weapon:DefaultReload(ACT_VM_RELOAD)
self:SetIronsights( false )
self:SetZoom(false)
Expand Down
16 changes: 8 additions & 8 deletions lua/weapons/weapon_ghost_shotgun.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function SWEP:Reload()
self:SetIronsights( false )
if self.dt.reloading then return end
if not IsFirstTimePredicted() then return end
if self.Weapon:Clip1() < self.Primary.ClipSize and self.Owner:GetAmmoCount( self.Primary.Ammo ) > 0 then
if self.Weapon:Clip1() < self.Primary.ClipSize and self:GetOwner():GetAmmoCount( self.Primary.Ammo ) > 0 then
if self:StartReload() then
return
end
Expand All @@ -68,7 +68,7 @@ function SWEP:StartReload()

self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )

local ply = self.Owner
local ply = self:GetOwner()

if not ply or ply:GetAmmoCount(self.Primary.Ammo) <= 0 then
return false
Expand All @@ -91,7 +91,7 @@ function SWEP:StartReload()
end

function SWEP:PerformReload()
local ply = self.Owner
local ply = self:GetOwner()

-- prevent normal shooting in between reloads
self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
Expand All @@ -102,7 +102,7 @@ function SWEP:PerformReload()

if wep:Clip1() >= self.Primary.ClipSize then return end

self.Owner:RemoveAmmo( 1, self.Primary.Ammo, false )
self:GetOwner():RemoveAmmo( 1, self.Primary.Ammo, false )
self.Weapon:SetClip1( self.Weapon:Clip1() + 1 )

wep:SendWeaponAnim(ACT_VM_RELOAD)
Expand All @@ -119,12 +119,12 @@ end

function SWEP:CanPrimaryAttack()
if self.Weapon:Clip1() <= 0 then
if CLIENT and LocalPlayer() == self.Owner then
if CLIENT and LocalPlayer() == self:GetOwner() then
self:EmitSound( "Weapon_Shotgun.Empty" )
else
local filter = RecipientFilter()
for k, v in ipairs(player.GetHumans()) do
if v != self.Owner and v:IsGhost() then
if v != self:GetOwner() and v:IsGhost() then
filter:AddPlayer(v)
end
end
Expand All @@ -142,14 +142,14 @@ end

function SWEP:Think()
if self.dt.reloading and IsFirstTimePredicted() then
if self.Owner:KeyDown(IN_ATTACK) then
if self:GetOwner():KeyDown(IN_ATTACK) then
self:FinishReload()
return
end

if self.reloadtimer <= CurTime() then

if self.Owner:GetAmmoCount(self.Primary.Ammo) <= 0 then
if self:GetOwner():GetAmmoCount(self.Primary.Ammo) <= 0 then
self:FinishReload()
elseif self.Weapon:Clip1() < self.Primary.ClipSize then
self:PerformReload()
Expand Down

0 comments on commit 99356ec

Please sign in to comment.