Skip to content

Commit 400e6d9

Browse files
v2.3.16
1 parent fbd3278 commit 400e6d9

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Hvh_Tools.lua

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ local currentTarget = nil
8282
-- Returns the best target (lowest fov)
8383
---@param me WPlayer
8484
---@return AimTarget? target
85-
local function GetBestTarget(me, pLocalOrigin)
85+
local function GetBestTarget(me, pLocalOrigin, pLocal)
8686
players = entities.FindByClass("CTFPlayer")
8787
local target = nil
8888
local lastFov = math.huge
@@ -93,20 +93,26 @@ local function GetBestTarget(me, pLocalOrigin)
9393
}
9494
local closestPlayer = nil
9595
local closestDistance = math.huge
96+
local ValidTarget
9697
-- Loop through all players to find closest one
9798
for _, entity1 in pairs(players) do
98-
if entity1 and entity1:IsAlive() and entity1:GetTeamNumber() ~= me:GetTeamNumber() and entity1:GetPropInt("m_iClass") == 2 or entity1:GetPropInt("m_iClass") == 8 then
99+
if entity1 == pLocal then goto continue end
100+
ValidTarget = entity1 and entity1:IsAlive() and entity1:GetTeamNumber() ~= me:GetTeamNumber()
101+
if ValidTarget and entity1:GetPropInt("m_iClass") == 2 or ValidTarget and entity1:GetPropInt("m_iClass") == 8 then
99102

100103
local distance = (entity1:GetAbsOrigin() - me:GetAbsOrigin()):Length()
101104
if distance < closestDistance and distance < 2000 then -- if player is closer than the current closest player
102105
closestPlayer = entity1 -- update closest player
103106
closestDistance = distance -- update closest distance
104107
end
105108
end
109+
::continue::
106110
end
107111

108112
for _, entity in pairs(players) do -- iterate through all players
109-
if entity and entity:IsAlive() and entity:GetTeamNumber() ~= me:GetTeamNumber() and entity:GetPropInt("m_iClass") == 2 then
113+
if entity == pLocal then goto continue end
114+
ValidTarget = entity and entity:IsAlive() and entity:GetTeamNumber() ~= me:GetTeamNumber()
115+
if ValidTarget and entity:GetPropInt("m_iClass") == 2 or ValidTarget and entity:GetPropInt("m_iClass") == 8 then
110116
local targetPos = entity:GetAbsOrigin()
111117
local playerPos = me:GetAbsOrigin()
112118
local forwardVec = engine.GetViewAngles():Forward()

0 commit comments

Comments
 (0)