From e49586c55f5440a39d4fc0a08431558d6e6588a4 Mon Sep 17 00:00:00 2001 From: Garrett Brown Date: Thu, 7 May 2020 16:50:17 -0400 Subject: [PATCH 1/2] Distance checks and make lever girthier --- lua/entities/gmod_wire_lever.lua | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/lua/entities/gmod_wire_lever.lua b/lua/entities/gmod_wire_lever.lua index 0300929793..e0ac479b97 100644 --- a/lua/entities/gmod_wire_lever.lua +++ b/lua/entities/gmod_wire_lever.lua @@ -58,18 +58,21 @@ if CLIENT then local isClicking = LocalPlayer():KeyDown(IN_USE) or LocalPlayer():KeyDown(IN_ATTACK) if isClicking and not self.wasClicking and IsValid(self.csmodel) then - local rayPos = util.IntersectRayWithOBB( - LocalPlayer():GetShootPos(), - LocalPlayer():GetEyeTrace().Normal * 75, - self.csmodel:GetPos(), - self.csmodel:GetAngles(), - self.csmodel:OBBMins(), - self.csmodel:OBBMaxs() - ) - if rayPos then - net.Start("wire_lever_activate") - net.WriteEntity(self) - net.SendToServer() + local aimPos = LocalPlayer():GetShootPos() + if aimPos:DistToSqr(self:GetPos())<160^2 then + local rayPos = util.IntersectRayWithOBB( + aimPos, + LocalPlayer():GetAimVector() * 160, + self.csmodel:GetPos(), + self.csmodel:GetAngles(), + self.csmodel:OBBMins() - Vector(2,2,2), + self.csmodel:OBBMaxs() + Vector(2,2,2) + ) + if rayPos then + net.Start("wire_lever_activate") + net.WriteEntity(self) + net.SendToServer() + end end end self.wasClicking = isClicking @@ -123,7 +126,7 @@ else if not IsValid(ply) or not IsValid(ent) or not ent.Use or ent:GetClass() ~= "gmod_wire_lever" then return end if IsValid(ent.User) then return end - if ply:GetShootPos():Distance(ent:GetPos()) < 100 then + if ply:GetShootPos():DistToSqr(ent:GetPos()) < 160^2 then ent:Use(ply, ply, USE_ON, 1) end end) From ee793ef95efb3610fbab8d50a7d4cc7d7a5a7cf6 Mon Sep 17 00:00:00 2001 From: Garrett Brown Date: Fri, 8 May 2020 01:39:31 -0400 Subject: [PATCH 2/2] Distance check to 100 --- lua/entities/gmod_wire_lever.lua | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lua/entities/gmod_wire_lever.lua b/lua/entities/gmod_wire_lever.lua index e0ac479b97..d62e7017a9 100644 --- a/lua/entities/gmod_wire_lever.lua +++ b/lua/entities/gmod_wire_lever.lua @@ -59,10 +59,10 @@ if CLIENT then local isClicking = LocalPlayer():KeyDown(IN_USE) or LocalPlayer():KeyDown(IN_ATTACK) if isClicking and not self.wasClicking and IsValid(self.csmodel) then local aimPos = LocalPlayer():GetShootPos() - if aimPos:DistToSqr(self:GetPos())<160^2 then + if aimPos:DistToSqr(self:GetPos())<100^2 then local rayPos = util.IntersectRayWithOBB( aimPos, - LocalPlayer():GetAimVector() * 160, + LocalPlayer():GetAimVector() * 100, self.csmodel:GetPos(), self.csmodel:GetAngles(), self.csmodel:OBBMins() - Vector(2,2,2), @@ -126,7 +126,7 @@ else if not IsValid(ply) or not IsValid(ent) or not ent.Use or ent:GetClass() ~= "gmod_wire_lever" then return end if IsValid(ent.User) then return end - if ply:GetShootPos():DistToSqr(ent:GetPos()) < 160^2 then + if ply:GetShootPos():DistToSqr(ent:GetPos()) < 100^2 then ent:Use(ply, ply, USE_ON, 1) end end) @@ -136,8 +136,7 @@ else if IsValid(self.User) then local shootPos = self.User:GetShootPos() - local distSqr = shootPos:DistToSqr(self:GetPos()) - if distSqr < 160^2 and (self.User:KeyDown(IN_USE) or self.User:KeyDown(IN_ATTACK)) then + if shootPos:DistToSqr(self:GetPos()) < 100^2 and (self.User:KeyDown(IN_USE) or self.User:KeyDown(IN_ATTACK)) then local shootDir = self.User:GetAimVector() self:CalcAngle(shootPos, shootDir) else