Skip to content

Commit af6f510

Browse files
Add files via upload
1 parent 96c4362 commit af6f510

File tree

1 file changed

+92
-123
lines changed

1 file changed

+92
-123
lines changed

A_Swing_Prediction.lua

+92-123
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,12 @@ local hitbox_Width = 24
206206
local isMelee = false
207207
local mresolution = 64
208208
local pLocal = entities.GetLocalPlayer()
209+
local players = entities.FindByClass("CTFPlayer")
209210
local ping = 0
210211
local swingrange = 48
211212
local tickRate = 66
212213
local tick_count = 0
213-
local time = 14
214+
local time = 13
214215
local Gcan_attack = false
215216
local Safe_Strafe = false
216217
local can_charge = false
@@ -224,7 +225,12 @@ local PredPath = {}
224225
local vHitbox = { Vector3(-24, -24, 0), Vector3(24, 24, 80) }
225226
local drawVhitbox = {}
226227
local gravity = client.GetConVar("sv_gravity") or 800 -- Get the current gravity
227-
local stepSize = pLocal:GetPropFloat("localdata", "m_flStepSize") or 18
228+
if pLocal then
229+
local stepSize = pLocal:GetPropFloat("localdata", "m_flStepSize") or 18
230+
else
231+
local stepSize = 18
232+
end
233+
228234
local backtrackTicks = {}
229235
local vPlayerViewHeight = 75
230236

@@ -265,9 +271,8 @@ local maxPositions = 4 -- Number of past positions to consider
265271

266272

267273
local function CalcStrafe()
268-
local players = entities.FindByClass("CTFPlayer")
269274
local autostrafe = gui.GetValue("Auto Strafe")
270-
local flags = pLocal:GetPropInt("m_fFlags")
275+
local flags = entities.GetLocalPlayer():GetPropInt("m_fFlags")
271276
local OnGround = flags & FL_ONGROUND == 1
272277

273278
for idx, entity in ipairs(players) do
@@ -462,84 +467,66 @@ end
462467

463468
local playerTicks = {}
464469

465-
local function GetBestTarget(me)
470+
local playerTicks = {}
471+
local maxTick = math.floor(((defFakeLatency) / 1000) / 0.015)
466472

467-
local players = entities.FindByClass("CTFPlayer")
473+
local function GetBestTarget(me)
468474
local localPlayer = entities.GetLocalPlayer()
469475
if not localPlayer then return end
470476

471477
local bestTarget = nil
472478
local bestFactor = 0
473-
local target_viewoffset = nil
474-
--settings.MaxDistance = swingrange * 1.2
475-
476479
local localPlayerViewAngles = engine.GetViewAngles()
477480

481+
for _, player in pairs(players) do
482+
if player == nil or not player:IsAlive()
483+
or player:IsDormant()
484+
or player == me or player:GetTeamNumber() == me:GetTeamNumber()
485+
or gui.GetValue("ignore cloaked") == 1 and player:InCond(4) then
486+
goto continue
487+
end
488+
489+
local numBacktrackTicks = gui.GetValue("Fake Latency") == 1 and maxTick or gui.GetValue("Fake Latency") == 0 and gui.GetValue("Backtrack") == 1 and 4 or 0
478490

479-
for _, player in ipairs(players) do
480-
if player ~= nil and player:GetIndex() ~= pLocal:GetIndex() and player:IsAlive() and not player:IsDormant() then
481-
if player:GetTeamNumber() ~= localPlayer:GetTeamNumber() then
482-
483-
484-
--local minTick = math.floor((defFakeLatency / 900) / 0.015)
485-
local maxTick = math.floor(((defFakeLatency) / 1000) / 0.015)
486-
487-
local numBacktrackTicks = gui.GetValue("Fake Latency") == 1 and maxTick or gui.GetValue("Fake Latency") == 0 and gui.GetValue("Backtrack") == 1 and 4 or 0
488-
489-
if numBacktrackTicks ~= 0 then
490-
local playerIndex = player:GetIndex()
491-
playerTicks[playerIndex] = playerTicks[playerIndex] or {}
492-
table.insert(playerTicks[playerIndex], player:GetAbsOrigin())
493-
494-
-- If the player's tick count exceeds maxinteger, remove the oldest tick
495-
if #playerTicks[playerIndex] > numBacktrackTicks then
496-
table.remove(playerTicks[playerIndex], 1)
497-
end
498-
end
491+
if numBacktrackTicks ~= 0 then
492+
local playerIndex = player:GetIndex()
493+
playerTicks[playerIndex] = playerTicks[playerIndex] or {}
494+
table.insert(playerTicks[playerIndex], player:GetAbsOrigin())
499495

500-
local playerOrigin = player:GetAbsOrigin()
501-
local distance = math.abs(playerOrigin.x - pLocalOrigin.x) +
502-
math.abs(playerOrigin.y - pLocalOrigin.y) +
503-
math.abs(playerOrigin.z - pLocalOrigin.z)
496+
if #playerTicks[playerIndex] > numBacktrackTicks then
497+
table.remove(playerTicks[playerIndex], 1)
498+
end
499+
end
504500

505-
if distance <= settings.MaxDistance then
506-
local Pviewoffset = player:GetPropVector("localdata", "m_vecViewOffset[0]")
507-
local Pviewpos = playerOrigin + Pviewoffset
508-
local Pviewoffset2 = (Pviewpos - playerOrigin):Length()
501+
local playerOrigin = player:GetAbsOrigin()
502+
local distance = (playerOrigin - localPlayer:GetAbsOrigin()):Length()
509503

510-
local angles = Math.PositionAngles(pLocalOrigin, Pviewpos)
511-
local fov = Math.AngleFov(localPlayerViewAngles, angles)
504+
if distance <= 770 then
505+
local Pviewoffset = player:GetPropVector("localdata", "m_vecViewOffset[0]")
506+
local Pviewpos = playerOrigin + Pviewoffset
512507

513-
if fov <= settings.MaxFOV then
514-
local distanceFactor = Math.RemapValClamped(distance, settings.MinDistance, settings.MaxDistance, 1, 0.07)
515-
local fovFactor = Math.RemapValClamped(fov, settings.MinFOV, settings.MaxFOV, 1, 0.9)
516-
517-
-- Check if the player is visible
518-
local isVisible = Helpers.VisPos(player, pLocalOrigin, Pviewpos)
519-
520-
-- Add a visibility factor to the calculation
521-
local visibilityFactor = isVisible and 1.0 or 0.5
508+
local angles = Math.PositionAngles(localPlayer:GetAbsOrigin(), Pviewpos)
509+
local fov = Math.AngleFov(localPlayerViewAngles, angles)
522510

523-
local factor = distanceFactor * fovFactor * visibilityFactor
511+
if fov <= Menu.Aimbot.AimbotFOV then
512+
local distanceFactor = Math.RemapValClamped(distance, settings.MinDistance, settings.MaxDistance, 1, 0.9)
513+
local fovFactor = Math.RemapValClamped(fov, settings.MinFOV, Menu.Aimbot.AimbotFOV, 1, 1)
524514

525-
if factor > bestFactor then
526-
bestTarget = player
527-
bestFactor = factor
528-
end
529-
end
530-
end
515+
local factor = distanceFactor * fovFactor
516+
if factor > bestFactor then
517+
bestTarget = player
518+
bestFactor = factor
531519
end
532520
end
533521
end
522+
::continue::
523+
end
534524

535-
return bestTarget, target_viewoffset
525+
return bestTarget
536526
end
537527

538528
-- Define function to check InRange between the hitbox and the sphere
539529
local function checkInRange(targetPos, spherePos, sphereRadius)
540-
541-
local inaccuracyValue = inaccuracy[vPlayer:GetIndex()]
542-
if not inaccuracyValue then return nil end
543530

544531
local hitbox_min_trigger = targetPos + vHitbox[1]
545532
local hitbox_max_trigger = targetPos + vHitbox[2]
@@ -655,19 +642,6 @@ local function UpdateHomingMissile()
655642
end
656643
end
657644

658-
local canatack = false
659-
660-
-- Returns if the weapon can shoot
661-
---@param weapon Entity
662-
---@return boolean
663-
local function CanShoot(weapon)
664-
local nextPrimaryAttack = weapon:GetPropFloat("LocalActiveWeaponData", "m_flNextPrimaryAttack")
665-
local nextAttack = pLocal:GetPropFloat("bcc_localdata", "m_flNextAttack")
666-
if (not nextPrimaryAttack) or (not nextAttack) then return false end
667-
668-
return (nextPrimaryAttack <= globals.CurTime()) and (nextAttack <= globals.CurTime())
669-
end
670-
671645
local hasNotified = false
672646
local function checkInRangeWithLatency(playerIndex, swingRange)
673647
local inRange = false
@@ -677,9 +651,7 @@ local function checkInRangeWithLatency(playerIndex, swingRange)
677651

678652
if Backtrack == 0 and fakelatencyON == 0 then
679653
-- Check for charge range bug
680-
if pLocalClass == 4 -- player is Demoman
681-
and Menu.Misc.ChargeReach -- menu option for such option is true
682-
and chargeLeft == 100 then -- charge metter is full
654+
if pLocalClass == 4 and Menu.Misc.ChargeReach and chargeLeft == 100 then -- charge metter is full
683655
if checkInRange(vPlayerOrigin, pLocalOrigin, Charge_Range) then
684656
inRange = true
685657
point = vPlayerOrigin
@@ -701,93 +673,88 @@ local function checkInRangeWithLatency(playerIndex, swingRange)
701673
return inRange, point, can_charge
702674
end
703675
end
704-
676+
705677
-- Adjust hitbox for current position
706678
inRange, point = checkInRange(vPlayerOrigin, pLocalOrigin, swingRange - 18)
679+
print(inRange)
707680
if inRange then
708681
return inRange, point
709682
end
710683

684+
711685
inRange, point = checkInRange(vPlayerFuture, pLocalFuture, swingRange)
712686
if inRange then
713687
return inRange, point, can_charge
714688
end
715-
end
716-
717-
if fakelatencyON == 1 then
689+
elseif fakelatencyON == 1 then
718690
if not hasNotified then
719691
Notify.Simple("Fake Latency is enabled", " this may cause issues with the script", 7)
720692
hasNotified = true
721693
end
722694

723695
local minTick = 1
724-
local maxTick = #playerTicks[playerIndex]
696+
maxTick = #playerTicks[playerIndex]
725697

726698
for tick = minTick, maxTick do
727699
if playerTicks[playerIndex] then
728700
local pastOrigin = playerTicks[playerIndex][tick]
729701

730-
-- Check for charge range bug
731-
if pLocalClass == 4 -- player is Demoman
732-
and Menu.Misc.ChargeReach -- menu option for such option is true
733-
and chargeLeft == 100 then -- charge metter is full
734-
if checkInRange(pastOrigin, pLocalOrigin, Charge_Range) then
735-
inRange = true
736-
point = vPlayerOrigin
737-
tick_count = tick_count + 1
738-
if tick_count >= (time - 1) then
739-
tick_count = 0
740-
can_charge = true
702+
-- Check for charge range bug
703+
if pLocalClass == 4 -- player is Demoman
704+
and Menu.Misc.ChargeReach -- menu option for such option is true
705+
and chargeLeft == 100 then -- charge metter is full
706+
if checkInRange(pastOrigin, pLocalOrigin, Charge_Range) then
707+
inRange = true
708+
point = vPlayerOrigin
709+
tick_count = tick_count + 1
710+
if tick_count >= (time - 1) then
711+
tick_count = 0
712+
can_charge = true
713+
end
714+
end
741715
end
742-
end
743-
if inRange then
744-
return inRange, point, can_charge
745-
end
746-
end
747716

748717
inRange, point = checkInRange(pastOrigin, pLocalOrigin, swingRange)
749718
if inRange then
750719
return inRange, point
751720
end
752721
end
753722
end
754-
end
755-
756-
if Backtrack == 1 then
723+
elseif Backtrack == 1 then
757724

758725
-- Check for charge range bug
759726
if pLocalClass == 4 -- player is Demoman
760-
and Menu.Misc.ChargeReach -- menu option for such option is true
761-
and chargeLeft == 100 then -- charge metter is full
762-
if checkInRange(vPlayerOrigin, pLocalOrigin, Charge_Range) then
763-
inRange = true
764-
point = vPlayerOrigin
765-
tick_count = tick_count + 1
766-
if tick_count >= (time - 1) then
767-
tick_count = 0
768-
can_charge = true
769-
end
770-
elseif checkInRange(vPlayerFuture, pLocalFuture, Charge_Range) then
771-
inRange = true
772-
point = vPlayerFuture
773-
tick_count = tick_count + 1
774-
if tick_count >= (time - 1) then
775-
tick_count = 0
776-
can_charge = true
727+
and Menu.Misc.ChargeReach -- menu option for such option is true
728+
and chargeLeft == 100 then -- charge metter is full
729+
if checkInRange(vPlayerOrigin, pLocalOrigin, Charge_Range) then
730+
inRange = true
731+
point = vPlayerOrigin
732+
tick_count = tick_count + 1
733+
if tick_count >= (time - 1) then
734+
tick_count = 0
735+
can_charge = true
736+
elseif checkInRange(vPlayerFuture, pLocalFuture, Charge_Range) then
737+
inRange = true
738+
point = vPlayerFuture
739+
tick_count = tick_count + 1
740+
if tick_count >= (time - 1) then
741+
tick_count = 0
742+
can_charge = true
743+
end
744+
end
745+
if inRange then
746+
return inRange, point, can_charge
747+
end
777748
end
778-
end
779-
if inRange then
780-
return inRange, point, can_charge
781-
end
782749
end
783-
750+
784751
-- Adjust hitbox for current position
785752
inRange, point = checkInRange(vPlayerOrigin, pLocalOrigin, swingRange)
786753
if inRange then
787754
return inRange, point
788755
end
789756

790-
inRange, point = checkInRange(vPlayerFuture, pLocalFuture, swingRange)
757+
inRange = checkInRange(vPlayerFuture, pLocalFuture, swingRange)
791758
if inRange then
792759
return inRange, point
793760
end
@@ -903,6 +870,7 @@ end
903870

904871
--[-----Get best target------------------]
905872
local keybind = Menu.Keybind
873+
players = entities.FindByClass("CTFPlayer")
906874
if keybind == 0 then
907875
-- Check if player has no key bound
908876
CurrentTarget = GetBestTarget(pLocal)
@@ -1072,7 +1040,7 @@ vdistance = (vPlayerOrigin - pLocalOrigin):Length()
10721040
else
10731041
engine.SetViewAngles(EulerAngles(aimpos.pitch, aimpos.yaw, 0))
10741042
end
1075-
else
1043+
elseif pLocalClass == 4 then
10761044
-- Control charge if charge bot is enabled and the local player is in condition 17
10771045
ChargeControl(pCmd)
10781046
end
@@ -1311,6 +1279,7 @@ local function handleKeybind(noKeyText, keybind, keybindName)
13111279
-- Reset keybind if the Escape key is pressed
13121280
keybind = 0
13131281
KeybindName = "Always On"
1282+
Notify.Simple("Keybind Success", "Bound Key: " .. KeybindName, 2)
13141283
else
13151284
-- Update keybind with the pressed key
13161285
keybind = pressedKey

0 commit comments

Comments
 (0)