Skip to content

Commit 768e28c

Browse files
v5.7.3
1 parent dfb20e6 commit 768e28c

File tree

1 file changed

+21
-38
lines changed

1 file changed

+21
-38
lines changed

Swing_Prediction.lua

+21-38
Original file line numberDiff line numberDiff line change
@@ -144,62 +144,51 @@ end
144144
---@param me WPlayer
145145
---@return AimTarget? target
146146
local function GetBestTarget(me)
147-
-- Define settings for target selection
148-
local settings = {
149-
MinDistance = 150,
147+
settings = {
148+
MinDistance = 200,
150149
MaxDistance = 1000,
151-
MinHealth = 17,
150+
MinHealth = 10,
152151
MaxHealth = 100,
153152
MinFOV = 0,
154153
MaxFOV = mFov:GetValue(),
155154
}
156155

157-
-- Get all players in the game
158156
local players = entities.FindByClass("CTFPlayer")
159157
local localPlayer = entities.GetLocalPlayer()
160158
if not localPlayer then return end
161159

162-
-- Create a table to store target factors for each player
160+
---@type Target[]
163161
local targetList = {}
164-
for i = 1, #players do
165-
targetList[i] = nil
166-
end
162+
local targetCount = 0
167163

168-
-- Calculate target factors for each player
164+
-- Calculate target factors
169165
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+
183172
local distance = (player:GetAbsOrigin() - localPlayer:GetAbsOrigin()):Length()
184173
local height_diff = math.floor(math.abs(player:GetAbsOrigin().z - localPlayer:GetAbsOrigin().z))
185174

186-
-- Skip players that are too far away or too high
187175
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
190178
local angles = Math.PositionAngles(localPlayer:GetAbsOrigin(), player:GetAbsOrigin())
191179
local fov = Math.AngleFov(engine.GetViewAngles(), angles)
192180
if fov > settings.MaxFOV then goto continue end
193181

194-
-- Calculate player's health factor
195182
local health = player:GetHealth()
183+
196184
local distanceFactor = Math.RemapValClamped(distance, settings.MinDistance, settings.MaxDistance, 1, 0.1)
197185
local healthFactor = Math.RemapValClamped(health, settings.MinHealth, settings.MaxHealth, 1, 0.5)
198186
local fovFactor = Math.RemapValClamped(fov, settings.MinFOV, settings.MaxFOV, 1, 0.5)
199187

200-
-- Calculate overall factor for player
201188
local factor = distanceFactor * healthFactor * fovFactor
202-
targetList[i] = { player = player, factor = factor}
189+
targetCount = targetCount + 1
190+
targetList[targetCount] = { player = player, factor = factor }
191+
203192
::continue::
204193
end
205194

@@ -208,8 +197,8 @@ local function GetBestTarget(me)
208197
return a.factor > b.factor
209198
end)
210199

211-
-- Select the best target
212200
local bestTarget = nil
201+
213202
for _, target in ipairs(targetList) do
214203
local player = target.player
215204
local aimPos = player:GetAbsOrigin()
@@ -219,7 +208,6 @@ local function GetBestTarget(me)
219208
-- Set as best target
220209
bestTarget = { entity = player, pos = aimPos, angles = angles, factor = target.factor }
221210
break
222-
::continue::
223211
end
224212

225213
return bestTarget
@@ -468,13 +456,8 @@ end]]--
468456
end
469457

470458
--[-----Get best target------------------]
471-
472-
if #players == 1 then
473-
return
474-
end
475-
476459
local keybind = mKeyOverrite:GetValue()
477-
--if not pLocal:InCond(17) then
460+
if not pLocal:InCond(17) then
478461
if keybind == KEY_NONE and GetBestTarget(pLocal) ~= nil then
479462
-- Check if player has no key bound
480463
CurrentTarget = GetBestTarget(pLocal).entity
@@ -486,7 +469,7 @@ end]]--
486469
else
487470
CurrentTarget = nil
488471
end
489-
--end
472+
end
490473

491474
-- Refill and skip code when alone
492475
if CurrentTarget == nil then

0 commit comments

Comments
 (0)