From 2e04bf09b0c1b6fded33bb17fef0a5edccf43594 Mon Sep 17 00:00:00 2001 From: TwistedTail <8784231+TwistedTail@users.noreply.github.com> Date: Tue, 19 Jan 2021 01:55:35 -0300 Subject: [PATCH] Updated code to comply with the new linter - 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(). --- lua/entities/acf_base_scalable/init.lua | 4 ++-- lua/entities/acf_base_simple/init.lua | 4 ++-- lua/entities/acf_gun/init.lua | 2 +- lua/weapons/acf_base/cl_init.lua | 20 +++++++++------- lua/weapons/acf_base/init.lua | 32 +++++++++++++++---------- lua/weapons/acf_base/shared.lua | 18 +++++++------- lua/weapons/torch/shared.lua | 6 ++--- 7 files changed, 49 insertions(+), 37 deletions(-) diff --git a/lua/entities/acf_base_scalable/init.lua b/lua/entities/acf_base_scalable/init.lua index b6f53e1ef..2c580785e 100644 --- a/lua/entities/acf_base_scalable/init.lua +++ b/lua/entities/acf_base_scalable/init.lua @@ -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 --------------------------------------------- diff --git a/lua/entities/acf_base_simple/init.lua b/lua/entities/acf_base_simple/init.lua index b6f53e1ef..2c580785e 100644 --- a/lua/entities/acf_base_simple/init.lua +++ b/lua/entities/acf_base_simple/init.lua @@ -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 --------------------------------------------- diff --git a/lua/entities/acf_gun/init.lua b/lua/entities/acf_gun/init.lua index c5ed25f57..7abbf96f2 100644 --- a/lua/entities/acf_gun/init.lua +++ b/lua/entities/acf_gun/init.lua @@ -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) diff --git a/lua/weapons/acf_base/cl_init.lua b/lua/weapons/acf_base/cl_init.lua index 6ff0c9414..e2031cd31 100644 --- a/lua/weapons/acf_base/cl_init.lua +++ b/lua/weapons/acf_base/cl_init.lua @@ -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() @@ -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) diff --git a/lua/weapons/acf_base/init.lua b/lua/weapons/acf_base/init.lua index c4744bf12..ffd7ae12a 100644 --- a/lua/weapons/acf_base/init.lua +++ b/lua/weapons/acf_base/init.lua @@ -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 @@ -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 @@ -47,16 +47,21 @@ 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 @@ -64,13 +69,14 @@ function SWEP:CrateReload() 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 @@ -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 diff --git a/lua/weapons/acf_base/shared.lua b/lua/weapons/acf_base/shared.lua index 308628291..ba92c42da 100644 --- a/lua/weapons/acf_base/shared.lua +++ b/lua/weapons/acf_base/shared.lua @@ -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 @@ -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) @@ -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 diff --git a/lua/weapons/torch/shared.lua b/lua/weapons/torch/shared.lua index 85dbb0644..9c9a6a9c2 100644 --- a/lua/weapons/torch/shared.lua +++ b/lua/weapons/torch/shared.lua @@ -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) @@ -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 @@ -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 = {}