@@ -82,7 +82,7 @@ local currentTarget = nil
82
82
-- Returns the best target (lowest fov)
83
83
--- @param me WPlayer
84
84
--- @return AimTarget ? target
85
- local function GetBestTarget (me , pLocalOrigin )
85
+ local function GetBestTarget (me , pLocalOrigin , pLocal )
86
86
players = entities .FindByClass (" CTFPlayer" )
87
87
local target = nil
88
88
local lastFov = math.huge
@@ -93,20 +93,26 @@ local function GetBestTarget(me, pLocalOrigin)
93
93
}
94
94
local closestPlayer = nil
95
95
local closestDistance = math.huge
96
+ local ValidTarget
96
97
-- Loop through all players to find closest one
97
98
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
99
102
100
103
local distance = (entity1 :GetAbsOrigin () - me :GetAbsOrigin ()):Length ()
101
104
if distance < closestDistance and distance < 2000 then -- if player is closer than the current closest player
102
105
closestPlayer = entity1 -- update closest player
103
106
closestDistance = distance -- update closest distance
104
107
end
105
108
end
109
+ :: continue::
106
110
end
107
111
108
112
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
110
116
local targetPos = entity :GetAbsOrigin ()
111
117
local playerPos = me :GetAbsOrigin ()
112
118
local forwardVec = engine .GetViewAngles ():Forward ()
0 commit comments