@@ -144,62 +144,51 @@ end
144
144
--- @param me WPlayer
145
145
--- @return AimTarget ? target
146
146
local function GetBestTarget (me )
147
- -- Define settings for target selection
148
- local settings = {
149
- MinDistance = 150 ,
147
+ settings = {
148
+ MinDistance = 200 ,
150
149
MaxDistance = 1000 ,
151
- MinHealth = 17 ,
150
+ MinHealth = 10 ,
152
151
MaxHealth = 100 ,
153
152
MinFOV = 0 ,
154
153
MaxFOV = mFov :GetValue (),
155
154
}
156
155
157
- -- Get all players in the game
158
156
local players = entities .FindByClass (" CTFPlayer" )
159
157
local localPlayer = entities .GetLocalPlayer ()
160
158
if not localPlayer then return end
161
159
162
- -- Create a table to store target factors for each player
160
+ --- @type Target[]
163
161
local targetList = {}
164
- for i = 1 , # players do
165
- targetList [i ] = nil
166
- end
162
+ local targetCount = 0
167
163
168
- -- Calculate target factors for each player
164
+ -- Calculate target factors
169
165
for i , player in pairs (players ) do
170
- -- Skip invalid players
171
- if player == nil
172
- or player :IsDormant ()
173
- or player == localPlayer
174
- or player :GetTeamNumber () == localPlayer :GetTeamNumber ()
175
- or not player :IsAlive ()
176
- or gui .GetValue (" ignore cloaked" ) == 1 and player :InCond (4 )
177
- or not Helpers .VisPos (player , pLocalOrigin , player :GetAbsOrigin ())
178
- then
179
- goto continue
180
- end
181
-
182
- -- Calculate distance and height difference to player
166
+ if not Helpers .VisPos (player , pLocalOrigin , player :GetAbsOrigin ()) then goto continue end
167
+ if player == localPlayer or player :GetTeamNumber () == localPlayer :GetTeamNumber () then goto continue end
168
+ if player == nil or not player :IsAlive () then goto continue end
169
+ if gui .GetValue (" ignore cloaked" ) == 1 and (player :InCond (4 )) then goto continue end
170
+ if player :IsDormant () then goto continue end
171
+
183
172
local distance = (player :GetAbsOrigin () - localPlayer :GetAbsOrigin ()):Length ()
184
173
local height_diff = math.floor (math.abs (player :GetAbsOrigin ().z - localPlayer :GetAbsOrigin ().z ))
185
174
186
- -- Skip players that are too far away or too high
187
175
if height_diff > 180 or distance > 700 then goto continue end
188
-
189
- -- Calculate player's FOV and skip if it's too high
176
+
177
+ -- Visibility Check
190
178
local angles = Math .PositionAngles (localPlayer :GetAbsOrigin (), player :GetAbsOrigin ())
191
179
local fov = Math .AngleFov (engine .GetViewAngles (), angles )
192
180
if fov > settings .MaxFOV then goto continue end
193
181
194
- -- Calculate player's health factor
195
182
local health = player :GetHealth ()
183
+
196
184
local distanceFactor = Math .RemapValClamped (distance , settings .MinDistance , settings .MaxDistance , 1 , 0.1 )
197
185
local healthFactor = Math .RemapValClamped (health , settings .MinHealth , settings .MaxHealth , 1 , 0.5 )
198
186
local fovFactor = Math .RemapValClamped (fov , settings .MinFOV , settings .MaxFOV , 1 , 0.5 )
199
187
200
- -- Calculate overall factor for player
201
188
local factor = distanceFactor * healthFactor * fovFactor
202
- targetList [i ] = { player = player , factor = factor }
189
+ targetCount = targetCount + 1
190
+ targetList [targetCount ] = { player = player , factor = factor }
191
+
203
192
:: continue::
204
193
end
205
194
@@ -208,8 +197,8 @@ local function GetBestTarget(me)
208
197
return a .factor > b .factor
209
198
end )
210
199
211
- -- Select the best target
212
200
local bestTarget = nil
201
+
213
202
for _ , target in ipairs (targetList ) do
214
203
local player = target .player
215
204
local aimPos = player :GetAbsOrigin ()
@@ -219,7 +208,6 @@ local function GetBestTarget(me)
219
208
-- Set as best target
220
209
bestTarget = { entity = player , pos = aimPos , angles = angles , factor = target .factor }
221
210
break
222
- :: continue::
223
211
end
224
212
225
213
return bestTarget
@@ -468,13 +456,8 @@ end]]--
468
456
end
469
457
470
458
-- [-----Get best target------------------]
471
-
472
- if # players == 1 then
473
- return
474
- end
475
-
476
459
local keybind = mKeyOverrite :GetValue ()
477
- -- if not pLocal:InCond(17) then
460
+ if not pLocal :InCond (17 ) then
478
461
if keybind == KEY_NONE and GetBestTarget (pLocal ) ~= nil then
479
462
-- Check if player has no key bound
480
463
CurrentTarget = GetBestTarget (pLocal ).entity
@@ -486,7 +469,7 @@ end]]--
486
469
else
487
470
CurrentTarget = nil
488
471
end
489
- -- end
472
+ end
490
473
491
474
-- Refill and skip code when alone
492
475
if CurrentTarget == nil then
0 commit comments