From 9386baf9feb29be635b4158aac9ae411ea4fe03d Mon Sep 17 00:00:00 2001 From: VindoesCompooter <100soundsystem32@gmail.com> Date: Thu, 4 Mar 2021 17:13:32 +0000 Subject: [PATCH 1/3] Whitespaces + Deprecated Cleanup Whitespaces and deprecated code cleanup. --- entities/weapons/nut_hands.lua | 187 ++++++++++++++++----------------- 1 file changed, 89 insertions(+), 98 deletions(-) diff --git a/entities/weapons/nut_hands.lua b/entities/weapons/nut_hands.lua index 232d0f5b..1c7eac5f 100644 --- a/entities/weapons/nut_hands.lua +++ b/entities/weapons/nut_hands.lua @@ -139,7 +139,7 @@ local function removeVelocity(entity, normalize) timer.Simple(0, function() -- reformed physics SetSubPhysMotionEnabled(entity, true) - + if (IsValid(phys)) then phys:SetVelocity(vel) end @@ -160,11 +160,11 @@ local function throwVelocity(entity, client, power) -- reformed physics if (IsValid(entity)) then SetSubPhysMotionEnabled(entity, true) - + if (IsValid(phys)) then phys:SetVelocity(vel) end - + entity:SetVelocity(vel) entity:SetLocalAngularVelocity(Angle()) end @@ -202,7 +202,7 @@ function SWEP:reset(throw) if (!throw) then removeVelocity(self.holdingEntity) else - throwVelocity(self.holdingEntity, self.Owner, 300) + throwVelocity(self.holdingEntity, self:GetOwner(), 300) end hook.Run("GravGunOnDropped", self:GetOwner(), self.holdingEntity, throw) @@ -319,13 +319,11 @@ if (SERVER) then end else function SWEP:Think() - if (CLIENT) then - if (self.Owner) then - local viewModel = self.Owner:GetViewModel() + if (CLIENT and self:GetOwner()) then + local viewModel = self:GetOwner():GetViewModel() - if (IsValid(viewModel)) then - viewModel:SetPlaybackRate(1) - end + if (IsValid(viewModel)) then + viewModel:SetPlaybackRate(1) end end end @@ -337,38 +335,36 @@ function SWEP:PrimaryAttack() end if (IsValid(self.holdingEntity)) then - self:doPickup(not self.isWepRaised or self:GetOwner():isWepRaised()) + self:doPickup(!self.isWepRaised or self:GetOwner():isWepRaised()) return end self:SetNextPrimaryFire(CurTime() + self.Primary.Delay) - if (hook.Run("CanPlayerThrowPunch", self.Owner) == false) then + if (hook.Run("CanPlayerThrowPunch", self:GetOwner()) == false) then return end local staminaUse = nut.config.get("punchStamina", 10) if (staminaUse > 0) then - local value = self.Owner:getLocalVar("stm", 0) - staminaUse + local value = self:GetOwner():getLocalVar("stm", 0) - staminaUse if (value < 0) then return elseif (SERVER) then - self.Owner:setLocalVar("stm", value) + self:GetOwner():setLocalVar("stm", value) end end if (SERVER) then - self.Owner:EmitSound("npc/vort/claw_swing"..math.random(1, 2)..".wav") + self:GetOwner():EmitSound("npc/vort/claw_swing"..math.random(1, 2)..".wav") end - local damage = self.Primary.Damage - self:doPunchAnimation() - self.Owner:SetAnimation(PLAYER_ATTACK1) - self.Owner:ViewPunch(Angle(self.LastHand + 2, self.LastHand + 5, 0.125)) + self:GetOwner():SetAnimation(PLAYER_ATTACK1) + self:GetOwner():ViewPunch(Angle(self.LastHand + 2, self.LastHand + 5, 0.125)) self:SetNW2Float( "startTime", CurTime() ); self:SetNW2Bool( "startPunch", true ); @@ -380,7 +376,7 @@ function SWEP:SecondaryAttack() return end - local client = self.Owner + local client = self:GetOwner() local data = {} data.start = client:GetShootPos() data.endpos = data.start + client:GetAimVector() * PLAYER_PICKUP_RANGE @@ -393,13 +389,13 @@ function SWEP:SecondaryAttack() if (SERVER and IsValid(entity)) then if (entity:isDoor()) then - if (hook.Run("PlayerCanKnock", self.Owner, entity) == false) then + if (hook.Run("PlayerCanKnock", self:GetOwner(), entity) == false) then return end - self.Owner:ViewPunch(Angle(-1.3, 1.8, 0)) - self.Owner:EmitSound("physics/wood/wood_crate_impact_hard"..math.random(2, 3)..".wav") - self.Owner:SetAnimation(PLAYER_ATTACK1) + self:GetOwner():ViewPunch(Angle(-1.3, 1.8, 0)) + self:GetOwner():EmitSound("physics/wood/wood_crate_impact_hard"..math.random(2, 3)..".wav") + self:GetOwner():SetAnimation(PLAYER_ATTACK1) self:doPunchAnimation() self:SetNextSecondaryFire(CurTime() + 0.4) @@ -417,8 +413,8 @@ function SWEP:SecondaryAttack() end function SWEP:dragObject(phys, targetpos, is_ragdoll) - if (!IsValid(phys)) then - return + if (!IsValid(phys)) then + return end local point = self:GetOwner():GetShootPos() + self:GetOwner():GetAimVector() * 50 @@ -444,74 +440,71 @@ function SWEP:allowPickup(target) local phys = target:GetPhysicsObject() local client = self:GetOwner() - return ( - IsValid(phys) and IsValid(client) and client:getChar() and - (not phys:HasGameFlag(FVPHYSICS_NO_PLAYER_PICKUP)) and - phys:GetMass() <= CARRY_WEIGHT_LIMIT and - (not isPlayerStandsOn(target)) and - (target.CanPickup != false) and - hook.Run("GravGunPickupAllowed", self:GetOwner(), target) != false and - (target.GravGunPickupAllowed and (target:GravGunPickupAllowed(self:GetOwner()) != false) or true) - ) + return + IsValid(phys) and IsValid(client) and client:getChar() and + (!phys:HasGameFlag(FVPHYSICS_NO_PLAYER_PICKUP)) and + phys:GetMass() <= CARRY_WEIGHT_LIMIT and + (!isPlayerStandsOn(target)) and + (target.CanPickup != false) and + hook.Run("GravGunPickupAllowed", self:GetOwner(), target) != false and + (target.GravGunPickupAllowed and (target:GravGunPickupAllowed(self:GetOwner()) != false) or true) end function SWEP:doPickup(throw, entity, trace) - self.Weapon:SetNextPrimaryFire( CurTime() + .1 ) - self.Weapon:SetNextSecondaryFire( CurTime() + .1 ) + self:SetNextPrimaryFire( CurTime() + .1 ) + self:SetNextSecondaryFire( CurTime() + .1 ) if (IsValid(self.holdingEntity)) then self:drop(throw) - self.Weapon:SetNextSecondaryFire(CurTime() + 0.1) + self:SetNextSecondaryFire(CurTime() + 0.1) return end local client = self:GetOwner() if (IsValid(entity)) then local phys = entity:GetPhysicsObject() - + if (!IsValid(phys) or !phys:IsMoveable() or phys:HasGameFlag(FVPHYSICS_PLAYER_HELD)) then - hook.Run("OnPickupObject", false, self.Owner, entity) + hook.Run("OnPickupObject", false, self:GetOwner(), entity) return end - + -- if we let the client mess with physics, desync ensues - if (SERVER) then - if (client:EyePos() - (entity:GetPos() + entity:OBBCenter())):Length() < self:getRange(entity) then - if (self:allowPickup(entity)) then - self:pickup(entity, trace) - self:SendWeaponAnim(ACT_VM_HITCENTER) - - -- make the refire slower to avoid immediately dropping - local delay = (entity:GetClass() == "prop_ragdoll") and 0.8 or 0.1 - - hook.Run("OnPickupObject", true, self.Owner, entity) - self:SetNextSecondaryFire(CurTime() + delay) - return - else - local is_ragdoll = entity:GetClass() == "prop_ragdoll" + if (SERVER and (client:EyePos() - (entity:GetPos() + entity:OBBCenter())):Length() < self:getRange(entity)) then + if (self:allowPickup(entity)) then + self:pickup(entity, trace) + self:SendWeaponAnim(ACT_VM_HITCENTER) - --[[ - --Drag ragdoll/props + -- make the refire slower to avoid immediately dropping + local delay = (entity:GetClass() == "prop_ragdoll") and 0.8 or 0.1 - local ent = entity - local phys = ent:GetPhysicsObject() - local pdir = trace.Normal * -1 + hook.Run("OnPickupObject", true, self:GetOwner(), entity) + self:SetNextSecondaryFire(CurTime() + delay) + return + else + local is_ragdoll = entity:GetClass() == "prop_ragdoll" - if is_ragdoll then + --[[ + --Drag ragdoll/props - phys = ent:GetPhysicsObjectNum(trace.PhysicsBone) + local ent = entity + local phys = ent:GetPhysicsObject() + local pdir = trace.Normal * -1 - -- increase refire to make rags easier to drag - --self.Weapon:SetNextSecondaryFire(CurTime() + 0.04) - end - - if (IsValid(phys)) then - self:dragObject(phys, pdir, 6000, is_ragdoll) - return - end - ]]-- - end + if is_ragdoll then + + phys = ent:GetPhysicsObjectNum(trace.PhysicsBone) + + -- increase refire to make rags easier to drag + --self.Weapon:SetNextSecondaryFire(CurTime() + 0.04) + end + + if (IsValid(phys)) then + self:dragObject(phys, pdir, 6000, is_ragdoll) + return + end + ]]-- end end end @@ -535,7 +528,7 @@ function SWEP:pickup(entity, trace) pos = pos + self.holdingEntity:GetUp()*obb.z self.carryHack:SetPos(pos) - + self.carryHack:SetModel("models/weapons/w_bugbait.mdl") self.carryHack:SetColor(Color(50, 250, 50, 240)) @@ -601,7 +594,7 @@ function SWEP:pickup(entity, trace) self:SetNW2Bool("holdingObject", true) self.constr = constraint.Weld(self.carryHack, self.holdingEntity, 0, bone, max_force, true) - self.Owner:EmitSound("physics/body/body_medium_impact_soft"..math.random(1, 3)..".wav", 75) + self:GetOwner():EmitSound("physics/body/body_medium_impact_soft"..math.random(1, 3)..".wav", 75) hook.Run("GravGunOnPickedUp", self:GetOwner(), self.holdingEntity) end @@ -611,8 +604,8 @@ end local down = Vector(0, 0, -1) function SWEP:allowEntityDrop() local client = self:GetOwner() - local ent = self.carryHack - if (!IsValid(client)) or (!IsValid(ent)) then return false end + + if (!IsValid(client)) or (!IsValid(self.carryHack)) then return false end local ground = client:GetGroundEntity() if ground and (ground:IsWorld() or IsValid(ground)) then return true end @@ -645,13 +638,13 @@ ACT_VM_FISTS_DRAW = 3 ACT_VM_FISTS_HOLSTER = 2 function SWEP:Deploy() - if (!IsValid(self.Owner)) then + if (!IsValid(self:GetOwner())) then return end self:reset() - local viewModel = self.Owner:GetViewModel() + local viewModel = self:GetOwner():GetViewModel() if (IsValid(viewModel)) then viewModel:SetPlaybackRate(1) @@ -662,13 +655,13 @@ function SWEP:Deploy() end function SWEP:Holster() - if (!IsValid(self.Owner)) then + if (!IsValid(self:GetOwner())) then return end self:reset() - local viewModel = self.Owner:GetViewModel() + local viewModel = self:GetOwner():GetViewModel() if (IsValid(viewModel)) then viewModel:SetPlaybackRate(1) @@ -693,27 +686,25 @@ function SWEP:doPunchAnimation() self.LastHand = math.abs(1 - self.LastHand) local sequence = 4 + self.LastHand - local viewModel = self.Owner:GetViewModel() + local viewModel = self:GetOwner():GetViewModel() if (IsValid(viewModel)) then viewModel:SetPlaybackRate(0.5) viewModel:SetSequence(sequence) end - if(self:GetNW2Bool( "startPunch", false )) then - if( CurTime() > self:GetNW2Float( "startTime", CurTime() ) + 0.055 ) then - self:doPunch(); - self:SetNW2Bool( "startPunch", false ); - self:SetNW2Float( "startTime", 0 ); - end + if (self:GetNW2Bool( "startPunch", false )) and ( CurTime() > self:GetNW2Float( "startTime", CurTime() ) + 0.055 ) then + self:doPunch() + self:SetNW2Bool( "startPunch", false ) + self:SetNW2Float( "startTime", 0 ) end end function SWEP:doPunch() - if (IsValid(self) and IsValid(self.Owner)) then + if (IsValid(self) and IsValid(self:GetOwner())) then local damage = self.Primary.Damage local context = {damage = damage} - local result = hook.Run("PlayerGetFistDamage", self.Owner, damage, context) + local result = hook.Run("PlayerGetFistDamage", self:GetOwner(), damage, context) if (result != nil) then damage = result @@ -721,11 +712,11 @@ function SWEP:doPunch() damage = context.damage end - self.Owner:LagCompensation(true) + self:GetOwner():LagCompensation(true) local data = {} - data.start = self.Owner:GetShootPos() - data.endpos = data.start + self.Owner:GetAimVector()*96 - data.filter = self.Owner + data.start = self:GetOwner():GetShootPos() + data.endpos = data.start + self:GetOwner():GetAimVector()*96 + data.filter = self:GetOwner() local trace = util.TraceLine(data) if (SERVER and trace.Hit) then @@ -733,19 +724,19 @@ function SWEP:doPunch() if (IsValid(entity)) then local damageInfo = DamageInfo() - damageInfo:SetAttacker(self.Owner) + damageInfo:SetAttacker(self:GetOwner()) damageInfo:SetInflictor(self) damageInfo:SetDamage(damage) damageInfo:SetDamageType(DMG_SLASH) damageInfo:SetDamagePosition(trace.HitPos) - damageInfo:SetDamageForce(self.Owner:GetAimVector()*10000) + damageInfo:SetDamageForce(self:GetOwner():GetAimVector()*10000) entity:DispatchTraceAttack(damageInfo, data.start, data.endpos) - self.Owner:EmitSound("physics/body/body_medium_impact_hard"..math.random(1, 6)..".wav", 80) + self:GetOwner():EmitSound("physics/body/body_medium_impact_hard"..math.random(1, 6)..".wav", 80) end end - hook.Run("PlayerThrowPunch", self.Owner, trace) - self.Owner:LagCompensation(false) + hook.Run("PlayerThrowPunch", self:GetOwner(), trace) + self:GetOwner():LagCompensation(false) end end From c64e719bf27a08424eee7a54ca9bcfba836628b6 Mon Sep 17 00:00:00 2001 From: VindoesCompooter <100soundsystem32@gmail.com> Date: Thu, 4 Mar 2021 17:20:31 +0000 Subject: [PATCH 2/3] Key fix for 1.2-wip Added the key fix for 1.2-wip --- plugins/doors/entities/weapons/nut_keys.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugins/doors/entities/weapons/nut_keys.lua b/plugins/doors/entities/weapons/nut_keys.lua index e40bdc83..0062627b 100644 --- a/plugins/doors/entities/weapons/nut_keys.lua +++ b/plugins/doors/entities/weapons/nut_keys.lua @@ -112,6 +112,10 @@ function SWEP:PrimaryAttack() data.filter = self.Owner local entity = util.TraceLine(data).Entity + if (hook.Run("KeyLockOverride",self:GetOwner(),entity)) then + return + end + --[[ Locks the entity if the contiditon fits: 1. The entity is door and client has access to the door. @@ -192,6 +196,9 @@ function SWEP:SecondaryAttack() data.filter = self.Owner local entity = util.TraceLine(data).Entity + if (hook.Run("KeyUnlockOverride",self:GetOwner(),entity)) then + return + end --[[ Unlocks the entity if the contiditon fits: From bcb381afe7fcea330244e746e92ea44a82434af9 Mon Sep 17 00:00:00 2001 From: Zoephix Date: Thu, 4 Mar 2021 18:32:39 +0100 Subject: [PATCH 3/3] Optimizations --- entities/weapons/nut_hands.lua | 97 ++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 41 deletions(-) diff --git a/entities/weapons/nut_hands.lua b/entities/weapons/nut_hands.lua index 1c7eac5f..1ba6ce43 100644 --- a/entities/weapons/nut_hands.lua +++ b/entities/weapons/nut_hands.lua @@ -181,6 +181,8 @@ function SWEP:reset(throw) end if (IsValid(self.holdingEntity)) then + local owner = self:GetOwner() + if (!self.holdingEntity:IsWeapon()) then if (!IsValid(self.prevOwner)) then self.holdingEntity:SetOwner(nil) @@ -202,10 +204,10 @@ function SWEP:reset(throw) if (!throw) then removeVelocity(self.holdingEntity) else - throwVelocity(self.holdingEntity, self:GetOwner(), 300) + throwVelocity(self.holdingEntity, owner, 300) end - hook.Run("GravGunOnDropped", self:GetOwner(), self.holdingEntity, throw) + hook.Run("GravGunOnDropped", owner, self.holdingEntity, throw) end self.dt.carried_rag = nil @@ -304,11 +306,12 @@ if (SERVER) then stand_time = curTime + 0.1 end + local owner = self:GetOwner() local obb = math.abs(self.holdingEntity:GetModelBounds():Length2D()) - self.carryHack:SetPos(self:GetOwner():EyePos() + self:GetOwner():GetAimVector() * (35+obb)) + self.carryHack:SetPos(owner:EyePos() + owner:GetAimVector() * (35+obb)) - local targetAng = self:GetOwner():GetAngles() + local targetAng = owner:GetAngles() if (self.carryHack.preferedAngle) then targetAng.p = 0 @@ -319,8 +322,10 @@ if (SERVER) then end else function SWEP:Think() - if (CLIENT and self:GetOwner()) then - local viewModel = self:GetOwner():GetViewModel() + local owner = self:GetOwner() + + if (CLIENT and owner) then + local viewModel = owner:GetViewModel() if (IsValid(viewModel)) then viewModel:SetPlaybackRate(1) @@ -334,37 +339,39 @@ function SWEP:PrimaryAttack() return end + local owner = self:GetOwner() + if (IsValid(self.holdingEntity)) then - self:doPickup(!self.isWepRaised or self:GetOwner():isWepRaised()) + self:doPickup(!self.isWepRaised or owner:isWepRaised()) return end self:SetNextPrimaryFire(CurTime() + self.Primary.Delay) - if (hook.Run("CanPlayerThrowPunch", self:GetOwner()) == false) then + if (hook.Run("CanPlayerThrowPunch", owner) == false) then return end local staminaUse = nut.config.get("punchStamina", 10) if (staminaUse > 0) then - local value = self:GetOwner():getLocalVar("stm", 0) - staminaUse + local value = owner:getLocalVar("stm", 0) - staminaUse if (value < 0) then return elseif (SERVER) then - self:GetOwner():setLocalVar("stm", value) + owner:setLocalVar("stm", value) end end if (SERVER) then - self:GetOwner():EmitSound("npc/vort/claw_swing"..math.random(1, 2)..".wav") + owner:EmitSound("npc/vort/claw_swing"..math.random(1, 2)..".wav") end self:doPunchAnimation() - self:GetOwner():SetAnimation(PLAYER_ATTACK1) - self:GetOwner():ViewPunch(Angle(self.LastHand + 2, self.LastHand + 5, 0.125)) + owner:SetAnimation(PLAYER_ATTACK1) + owner:ViewPunch(Angle(self.LastHand + 2, self.LastHand + 5, 0.125)) self:SetNW2Float( "startTime", CurTime() ); self:SetNW2Bool( "startPunch", true ); @@ -389,13 +396,13 @@ function SWEP:SecondaryAttack() if (SERVER and IsValid(entity)) then if (entity:isDoor()) then - if (hook.Run("PlayerCanKnock", self:GetOwner(), entity) == false) then + if (hook.Run("PlayerCanKnock", client, entity) == false) then return end - self:GetOwner():ViewPunch(Angle(-1.3, 1.8, 0)) - self:GetOwner():EmitSound("physics/wood/wood_crate_impact_hard"..math.random(2, 3)..".wav") - self:GetOwner():SetAnimation(PLAYER_ATTACK1) + client:ViewPunch(Angle(-1.3, 1.8, 0)) + client:EmitSound("physics/wood/wood_crate_impact_hard"..math.random(2, 3)..".wav") + client:SetAnimation(PLAYER_ATTACK1) self:doPunchAnimation() self:SetNextSecondaryFire(CurTime() + 0.4) @@ -417,7 +424,9 @@ function SWEP:dragObject(phys, targetpos, is_ragdoll) return end - local point = self:GetOwner():GetShootPos() + self:GetOwner():GetAimVector() * 50 + local owner = self:GetOwner() + + local point = owner:GetShootPos() + owner:GetAimVector() * 50 local physDirection = targetpos - point local length = physDirection:Length2D() physDirection:Normalize() @@ -446,8 +455,8 @@ function SWEP:allowPickup(target) phys:GetMass() <= CARRY_WEIGHT_LIMIT and (!isPlayerStandsOn(target)) and (target.CanPickup != false) and - hook.Run("GravGunPickupAllowed", self:GetOwner(), target) != false and - (target.GravGunPickupAllowed and (target:GravGunPickupAllowed(self:GetOwner()) != false) or true) + hook.Run("GravGunPickupAllowed", client, target) != false and + (target.GravGunPickupAllowed and (target:GravGunPickupAllowed(client) != false) or true) end function SWEP:doPickup(throw, entity, trace) @@ -466,7 +475,7 @@ function SWEP:doPickup(throw, entity, trace) local phys = entity:GetPhysicsObject() if (!IsValid(phys) or !phys:IsMoveable() or phys:HasGameFlag(FVPHYSICS_PLAYER_HELD)) then - hook.Run("OnPickupObject", false, self:GetOwner(), entity) + hook.Run("OnPickupObject", false, client, entity) return end @@ -479,7 +488,7 @@ function SWEP:doPickup(throw, entity, trace) -- make the refire slower to avoid immediately dropping local delay = (entity:GetClass() == "prop_ragdoll") and 0.8 or 0.1 - hook.Run("OnPickupObject", true, self:GetOwner(), entity) + hook.Run("OnPickupObject", true, client, entity) self:SetNextSecondaryFire(CurTime() + delay) return else @@ -543,7 +552,7 @@ function SWEP:pickup(entity, trace) -- TODO: set the desired angles before adding the constraint local preferredAngles = hook.Run("GetPreferredCarryAngles", self.holdingEntity) - if (self:GetOwner():KeyDown(IN_RELOAD) and !preferredAngles) then + if (client:KeyDown(IN_RELOAD) and !preferredAngles) then preferredAngles = Angle() end @@ -558,7 +567,7 @@ function SWEP:pickup(entity, trace) self.carryHack:SetAngles(grabAngle) else - self.carryHack:SetAngles(self:GetOwner():GetAngles()) + self.carryHack:SetAngles(client:GetAngles()) end self.carryHack:Spawn() @@ -594,9 +603,9 @@ function SWEP:pickup(entity, trace) self:SetNW2Bool("holdingObject", true) self.constr = constraint.Weld(self.carryHack, self.holdingEntity, 0, bone, max_force, true) - self:GetOwner():EmitSound("physics/body/body_medium_impact_soft"..math.random(1, 3)..".wav", 75) + client:EmitSound("physics/body/body_medium_impact_soft"..math.random(1, 3)..".wav", 75) - hook.Run("GravGunOnPickedUp", self:GetOwner(), self.holdingEntity) + hook.Run("GravGunOnPickedUp", client, self.holdingEntity) end end end @@ -638,13 +647,15 @@ ACT_VM_FISTS_DRAW = 3 ACT_VM_FISTS_HOLSTER = 2 function SWEP:Deploy() - if (!IsValid(self:GetOwner())) then + local owner = self:GetOwner() + + if (!IsValid(owner)) then return end self:reset() - local viewModel = self:GetOwner():GetViewModel() + local viewModel = owner:GetViewModel() if (IsValid(viewModel)) then viewModel:SetPlaybackRate(1) @@ -655,13 +666,15 @@ function SWEP:Deploy() end function SWEP:Holster() - if (!IsValid(self:GetOwner())) then + local owner = self:GetOwner() + + if (!IsValid(owner)) then return end self:reset() - local viewModel = self:GetOwner():GetViewModel() + local viewModel = owner:GetViewModel() if (IsValid(viewModel)) then viewModel:SetPlaybackRate(1) @@ -701,10 +714,12 @@ function SWEP:doPunchAnimation() end function SWEP:doPunch() - if (IsValid(self) and IsValid(self:GetOwner())) then + local owner = self:GetOwner() + + if (IsValid(self) and IsValid(owner)) then local damage = self.Primary.Damage local context = {damage = damage} - local result = hook.Run("PlayerGetFistDamage", self:GetOwner(), damage, context) + local result = hook.Run("PlayerGetFistDamage", owner, damage, context) if (result != nil) then damage = result @@ -712,11 +727,11 @@ function SWEP:doPunch() damage = context.damage end - self:GetOwner():LagCompensation(true) + owner:LagCompensation(true) local data = {} - data.start = self:GetOwner():GetShootPos() - data.endpos = data.start + self:GetOwner():GetAimVector()*96 - data.filter = self:GetOwner() + data.start = owner:GetShootPos() + data.endpos = data.start + owner:GetAimVector()*96 + data.filter = owner local trace = util.TraceLine(data) if (SERVER and trace.Hit) then @@ -724,19 +739,19 @@ function SWEP:doPunch() if (IsValid(entity)) then local damageInfo = DamageInfo() - damageInfo:SetAttacker(self:GetOwner()) + damageInfo:SetAttacker(owner) damageInfo:SetInflictor(self) damageInfo:SetDamage(damage) damageInfo:SetDamageType(DMG_SLASH) damageInfo:SetDamagePosition(trace.HitPos) - damageInfo:SetDamageForce(self:GetOwner():GetAimVector()*10000) + damageInfo:SetDamageForce(owner:GetAimVector()*10000) entity:DispatchTraceAttack(damageInfo, data.start, data.endpos) - self:GetOwner():EmitSound("physics/body/body_medium_impact_hard"..math.random(1, 6)..".wav", 80) + owner:EmitSound("physics/body/body_medium_impact_hard"..math.random(1, 6)..".wav", 80) end end - hook.Run("PlayerThrowPunch", self:GetOwner(), trace) - self:GetOwner():LagCompensation(false) + hook.Run("PlayerThrowPunch", owner, trace) + owner:LagCompensation(false) end end