Skip to content

Commit

Permalink
Updated code to comply with the new linter
Browse files Browse the repository at this point in the history
- Updated every case on ACF entities where the owner was retrieved with ENT.Owned, using ENT:GetPlayer() now.
- Updated every SWEP and tool where SWEP.Owner was used, replaced it with SWEP:GetOwner().
  • Loading branch information
TwistedTail committed Jan 19, 2021
1 parent 9eb171d commit 2e04bf0
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 37 deletions.
4 changes: 2 additions & 2 deletions lua/entities/acf_base_scalable/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ do -- Entity user -------------------------------
end

function ENT:GetUser(Input)
if not IsValid(Input) then return self.Owner end
if not IsValid(Input) then return self:GetPlayer() end

local User = FindUser(self, Input)

return IsValid(User) and User or self.Owner
return IsValid(User) and User or self:GetPlayer()
end
end ---------------------------------------------
4 changes: 2 additions & 2 deletions lua/entities/acf_base_simple/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ do -- Entity user -------------------------------
end

function ENT:GetUser(Input)
if not IsValid(Input) then return self.Owner end
if not IsValid(Input) then return self:GetPlayer() end

local User = FindUser(self, Input)

return IsValid(User) and User or self.Owner
return IsValid(User) and User or self:GetPlayer()
end
end ---------------------------------------------
2 changes: 1 addition & 1 deletion lua/entities/acf_gun/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ do -- Metamethods --------------------------------
if TraceRes.Hit then
local Entity = TraceRes.Entity

if Entity == self.CurrentUser or Entity:CPPIGetOwner() == self.Owner then
if Entity == self.CurrentUser or Entity:CPPIGetOwner() == self:GetPlayer() then
self.BarrelFilter[#self.BarrelFilter + 1] = Entity

return self:BarrelCheck(Offset)
Expand Down
20 changes: 12 additions & 8 deletions lua/weapons/acf_base/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ SWEP.Slot = 1
SWEP.SlotPos = 1
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = false
SWEP.ScreenFactor = {}
SWEP.ScreenFactor.w = surface.ScreenWidth()
SWEP.ScreenFactor.h = surface.ScreenHeight()
SWEP.FloatingAim = {}
SWEP.FloatingAim.bounds = 0.3

SWEP.ScreenFactor = {
w = ScrW(),
h = ScrH(),
}

SWEP.FloatingAim = {
bounds = 0.3,
}

function SWEP:Initialize()
self:StartUp()
Expand Down Expand Up @@ -65,18 +69,18 @@ end

function SWEP:ApplyRecoil(Recoil)
local RecoilAng = Angle(Recoil * math.Rand(-1, -0.25), Recoil * math.Rand(-0.25, 0.25), 0)
self.Owner:ViewPunch(RecoilAng)
self:GetOwner():ViewPunch(RecoilAng)
end

--Clientside effect, for Viewmodel stuff
function SWEP:MuzzleEffect()
self:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
self.Owner:MuzzleFlash()
self:GetOwner():MuzzleFlash()
end

function SWEP:StartUp()
print("Starting Client")
self.FOV = self.Owner:GetFOV()
self.FOV = self:GetOwner():GetFOV()
self.ViewModelFOV = self.FOV
self.LastIrons = 0
--hook.Add("InputMouseApply","ACF_SWEPFloatingCrosshair",ACF_SWEPFloatingCrosshair)
Expand Down
32 changes: 20 additions & 12 deletions lua/weapons/acf_base/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function SWEP:Initialize()
end

function SWEP:Reload()
if (self:Clip1() < self.Primary.ClipSize and self.Owner:GetAmmoCount(self.Primary.Ammo) > 0) then
if (self:Clip1() < self.Primary.ClipSize and self:GetOwner():GetAmmoCount(self.Primary.Ammo) > 0) then
self:EmitSound("weapons/AMR/sniper_reload.wav", 70, 110, ACF.Volume)
self:DefaultReload(ACT_VM_RELOAD)
end
Expand All @@ -38,7 +38,7 @@ end
function SWEP:Think()
if self.OwnerIsNPC then return end

if self.Owner:KeyDown(IN_USE) then
if self:GetOwner():KeyDown(IN_USE) then
self:CrateReload()
end

Expand All @@ -47,30 +47,36 @@ end

--Server side effect, for external stuff
function SWEP:MuzzleEffect()
local Owner = self:GetOwner()

self:EmitSound("weapons/AMR/sniper_fire.wav", nil, nil, ACF.Volume)
self.Owner:MuzzleFlash()
self.Owner:SetAnimation(PLAYER_ATTACK1)

Owner:MuzzleFlash()
Owner:SetAnimation(PLAYER_ATTACK1)
end

function SWEP:CrateReload()
local ViewTr = {}
ViewTr.start = self.Owner:GetShootPos()
ViewTr.endpos = self.Owner:GetShootPos() + self.Owner:GetAimVector() * 128
ViewTr.filter = {self.Owner, self}
local Owner = self:GetOwner()
local ViewTr = {
start = Owner:GetShootPos(),
endpos = Owner:GetShootPos() + Owner:GetAimVector() * 128,
filter = { Owner, self },
}

local ViewRes = util.TraceLine(ViewTr) --Trace to see if it will hit anything

if SERVER then
local AmmoEnt = ViewRes.Entity

if IsValid(AmmoEnt) and AmmoEnt.Ammo > 0 and AmmoEnt.RoundId == self.Primary.UserData["Id"] then
local CurAmmo = self.Owner:GetAmmoCount(self.Primary.Ammo)
local CurAmmo = Owner:GetAmmoCount(self.Primary.Ammo)
local Transfert = math.min(AmmoEnt.Ammo, self.Primary.DefaultClip - CurAmmo)
local AmmoType = AmmoTypes[AmmoEnt.AmmoType]

AmmoEnt.Ammo = AmmoEnt.Ammo - Transfert

self.Owner:GiveAmmo(Transfert, self.Primary.Ammo)
Owner:GiveAmmo(Transfert, self.Primary.Ammo)

self.Primary.BulletData = AmmoEnt.BulletData
self.Primary.RoundData = AmmoType

Expand All @@ -82,11 +88,13 @@ function SWEP:CrateReload()
end

function SWEP:StartUp()
local Owner = self:GetOwner()

self:SetDTBool(0, false)
self.LastIrons = 0

if self.Owner then
self.OwnerIsNPC = self.Owner:IsNPC() -- This ought to be better than getting it every time we fire
if Owner then
self.OwnerIsNPC = Owner:IsNPC() -- This ought to be better than getting it every time we fire
end
end

Expand Down
18 changes: 9 additions & 9 deletions lua/weapons/acf_base/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ function SWEP:PrimaryAttack()
self:ApplyRecoil(math.min(Recoil,50))
self:MuzzleEffect()
else
local MuzzlePos = self.Owner:GetShootPos()
local MuzzleVec = self.Owner:GetAimVector()
local Owner = self:GetOwner()
local MuzzlePos = Owner:GetShootPos()
local MuzzleVec = Owner:GetAimVector()
local Speed = self.Primary.BulletData["MuzzleVel"]
local Modifiers = self:CalculateModifiers()
--local Recoil = (self.Primary.BulletData["ProjMass"] * self.Primary.BulletData["MuzzleVel"] + self.Primary.BulletData["PropMass"] * 3000)/self.Weight
Expand All @@ -74,8 +75,8 @@ function SWEP:PrimaryAttack()

self.Primary.BulletData["Pos"] = MuzzlePos
self.Primary.BulletData["Flight"] = (MuzzleVec + Inaccuracy):GetNormalized() * Speed * 39.37 + self:GetVelocity()
self.Primary.BulletData["Owner"] = self.Owner
self.Primary.BulletData["Gun"] = self.Owner
self.Primary.BulletData["Owner"] = Owner
self.Primary.BulletData["Gun"] = Owner
self.Primary.BulletData["Crate"] = self:EntIndex()

self.Primary.RoundData:Create(self, self.Primary.BulletData)
Expand Down Expand Up @@ -103,21 +104,20 @@ end

-- Acuracy/recoil modifiers
function SWEP:CalculateModifiers()

local Owner = self:GetOwner()
local modifier = 1

if self.Owner:KeyDown(IN_FORWARD or IN_BACK or IN_MOVELEFT or IN_MOVERIGHT) then
if Owner:KeyDown(IN_FORWARD or IN_BACK or IN_MOVELEFT or IN_MOVERIGHT) then
modifier = modifier * 2
end

if not self.Owner:IsOnGround() then
if not Owner:IsOnGround() then
modifier = modifier * 2 --You can't be jumping and crouching at the same time, so return here
return modifier end

if self.Owner:Crouching() then
if Owner:Crouching() then
modifier = modifier * 0.5
end

return modifier

end
6 changes: 3 additions & 3 deletions lua/weapons/torch/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function SWEP:Think()
if CLIENT then return end

local Health, MaxHealth, Armor, MaxArmor = 0, 0, 0, 0
local Trace = self.Owner:GetEyeTrace()
local Trace = self:GetOwner():GetEyeTrace()
local Entity = Trace.Entity

self.LastDistance = Trace.StartPos:DistToSqr(Trace.HitPos)
Expand Down Expand Up @@ -121,7 +121,7 @@ function SWEP:PrimaryAttack()

local Entity = self.LastEntity
local Trace = self.LastTrace
local Owner = self.Owner
local Owner = self:GetOwner()

if ACF.Check(Entity) then
if Entity:IsPlayer() or Entity:IsNPC() then
Expand Down Expand Up @@ -181,7 +181,7 @@ function SWEP:SecondaryAttack()

local Entity = self.LastEntity
local Trace = self.LastTrace
local Owner = self.Owner
local Owner = self:GetOwner()

if ACF.Check(Entity) then
local HitRes = {}
Expand Down

0 comments on commit 2e04bf0

Please sign in to comment.