Skip to content

Commit 0e229c7

Browse files
Add files via upload
1 parent deacb09 commit 0e229c7

File tree

1 file changed

+64
-60
lines changed

1 file changed

+64
-60
lines changed

A_Swing_Prediction.lua

+64-60
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ local Menu = {
102102
InstantAttack = true,
103103
ChargeReach = false,
104104
TroldierAssist = false,
105+
advancedHitreg = false,
105106
},
106107
Keybind = KEY_NONE,
107108
KeybindName = "Always On",
@@ -212,7 +213,7 @@ local swingrange = 48
212213
local tickRate = 66
213214
local tick_count = 0
214215
local time = 13
215-
local Gcan_attack = false
216+
local can_attack = false
216217
local Safe_Strafe = false
217218
local can_charge = false
218219
local Charge_Range = 128
@@ -525,11 +526,10 @@ local function GetBestTarget(me)
525526
return bestTarget
526527
end
527528

528-
local can_attack = false
529-
local OriginalAngles = Vector3()
530-
local OriginalPosition = Vector3()
531-
local lastswingtracedata = {}
532-
local swingresult
529+
-- Global flags and data storage
530+
local attackReady = false
531+
local attackData = {}
532+
local isAttackSuccessful = false
533533

534534
-- Function to check if target is in range
535535
local function checkInRange(targetPos, spherePos, sphereRadius, pWeapon)
@@ -548,50 +548,60 @@ local function checkInRange(targetPos, spherePos, sphereRadius, pWeapon)
548548

549549
-- Check if the target is within the sphere radius
550550
if sphereRadius > distanceAlongVector then
551-
-- Target is in range, store data for PropUpdate
552-
OriginalPosition = pLocal:GetPropVector("tfnonlocaldata", "m_vecOrigin")
553-
OriginalAngles = pLocal:GetPropVector("tfnonlocaldata", "m_angEyeAngles[0]")
554-
lastswingtracedata = {pWeapon, spherePos, closestPoint}
555-
return true, closestPoint
551+
if not Menu.Misc.advancedHitreg then return true, closestPoint end
552+
if Menu.Misc.ChargeReach and pLocalClass == 4 and chargeLeft == 100 then return true, closestPoint end
553+
554+
-- Prepare data for PropUpdate
555+
attackReady = true
556+
attackData = {
557+
pWeapon = pWeapon,
558+
spherePos = spherePos,
559+
closestPoint = closestPoint,
560+
originalPosition = pLocal:GetPropVector("tfnonlocaldata", "m_vecOrigin"),
561+
originalAngles = pLocal:GetPropVector("tfnonlocaldata", "m_angEyeAngles[0]")
562+
}
563+
return isAttackSuccessful, closestPoint
556564
else
557-
lastswingtracedata = nil
558565
-- Target is not in range
559566
return false, nil
560567
end
561568
end
562569

570+
local counter = 0
563571

564572
-- PostPropUpdate function to adjust player position and angle
565573
local function PropUpdate()
566-
if lastswingtracedata and not can_attack then
567-
local pWeapon = lastswingtracedata[1]
568-
local spherePos = lastswingtracedata[2]
569-
local closestPoint = lastswingtracedata[3]
570-
if spherePos and closestPoint then
571-
local Angle = Math.PositionAngles(spherePos, closestPoint)
572-
573-
-- Adjust player position and view angles for swing trace
574-
pLocal:SetPropVector(spherePos, "tfnonlocaldata", "m_vecOrigin")
575-
pLocal:SetPropVector(Vector3(Angle.x, Angle.y, Angle.z), "tfnonlocaldata", "m_angEyeAngles[0]")
576-
577-
-- Perform the swing trace
578-
local SwingTrace = pLocal.DoSwingTrace(pWeapon)
579-
swingresult = SwingTrace
580-
581-
-- Reset the player's original position and view angles
582-
pLocal:SetPropVector(OriginalPosition, "tfnonlocaldata", "m_vecOrigin")
583-
pLocal:SetPropVector(OriginalAngles, "tfnonlocaldata", "m_angEyeAngles[0]")
584-
585-
-- Clear last swing trace data
586-
lastswingtracedata = nil
574+
counter = counter + 1
575+
if counter % 2 == 0 and attackReady and Menu.Misc.advancedHitreg then
576+
local angle = Math.PositionAngles(attackData.spherePos, attackData.closestPoint)
577+
578+
-- Adjust player position and view angles for swing trace
579+
pLocal:SetPropVector(attackData.spherePos, "tfnonlocaldata", "m_vecOrigin")
580+
pLocal:SetPropVector(Vector3(angle.x, angle.y, angle.z), "tfnonlocaldata", "m_angEyeAngles[0]")
581+
582+
-- Perform the swing trace
583+
local swingTraceResult = pLocal.DoSwingTrace(attackData.pWeapon)
584+
585+
-- Check if the swing trace hit something
586+
if swingTraceResult and swingTraceResult.fraction < 1 then
587+
-- Attack hit
588+
isAttackSuccessful = true
589+
else
590+
isAttackSuccessful = false -- Reset attack success flag
587591
end
588-
end
589-
end
590592

591-
callbacks.Unregister("PostPropUpdate", "swingcheck") -- Unregister the "CreateMove" callback
592-
callbacks.Register("PostPropUpdate","swingcheck", PropUpdate)
593+
-- Reset the player's original position and view angles
594+
pLocal:SetPropVector(attackData.originalPosition, "tfnonlocaldata", "m_vecOrigin")
595+
pLocal:SetPropVector(attackData.originalAngles, "tfnonlocaldata", "m_angEyeAngles[0]")
593596

597+
-- Reset the flags and clear data
598+
attackReady = false
599+
attackData = {}
600+
end
601+
end
594602

603+
callbacks.Unregister("PostPropUpdate", "MyPostPropUpdate")
604+
callbacks.Register("PostPropUpdate", "MyPostPropUpdate", PropUpdate)
595605

596606

597607
local Hitbox = {
@@ -716,7 +726,7 @@ local function checkInRangeWithLatency(playerIndex, swingRange, pWeapon, cmd)
716726
return inRange, point, can_charge
717727
end
718728
end
719-
729+
720730
-- Adjust hitbox for current position
721731
inRange, point = checkInRange(vPlayerOrigin, pLocalOrigin, swingRange - 18, pWeapon, cmd)
722732
if inRange then
@@ -860,7 +870,7 @@ local function OnCreateMove(pCmd)
860870
pUsingMargetGarden = true
861871
-- Set "pUsingProjectileWeapon" to true
862872
end -- Set "pUsingProjectileWeapon" to false
863-
873+
864874
--[--Troldier assist--]
865875
if Menu.Misc.TroldierAssist then
866876
local state = ""
@@ -994,6 +1004,9 @@ end
9941004
local player = WPlayer.FromEntity(pLocal)
9951005

9961006
strafeAngle = Menu.Misc.strafePred and strafeAngles[pLocal:GetIndex()] or 0
1007+
if not Menu.Misc.advancedHitreg then
1008+
swingrange = swingrange - math.abs(strafeAngle)
1009+
end
9971010

9981011
local predData = PredictPlayer(player, time, strafeAngle)
9991012

@@ -1006,6 +1019,7 @@ if CurrentTarget == nil then
10061019
vPlayerFuture = nil
10071020
return
10081021
end
1022+
10091023
vPlayerOrigin = CurrentTarget:GetAbsOrigin() -- Get closest player origin
10101024

10111025
local VpFlags = CurrentTarget:GetPropInt("m_fFlags")
@@ -1043,7 +1057,7 @@ vdistance = (vPlayerOrigin - pLocalOrigin):Length()
10431057
-- Get distance between local player and closest player after swing
10441058
fDistance = (vPlayerFuture - pLocalFuture):Length()
10451059
local inRange = false
1046-
local inRangePoint = nil
1060+
local inRangePoint = Vector3(0, 0, 0)
10471061

10481062
inRange, InRangePoint, can_charge = checkInRangeWithLatency(CurrentTarget:GetIndex(), swingrange, pWeapon, pCmd)
10491063
-- Use inRange to decide if can attack
@@ -1054,7 +1068,7 @@ vdistance = (vPlayerOrigin - pLocalOrigin):Length()
10541068
local hitbox = hitboxes[6]
10551069
local aimpos = nil
10561070
--else
1057-
--aimpos = CurrentTarget:GetAbsOrigin() + Vheight --aimpos = (hitbox[1] + hitbox[2]) * 0.5 --if no InRange point accesable then aim at defualt hitbox
1071+
aimpos = CurrentTarget:GetAbsOrigin() + Vheight --aimpos = (hitbox[1] + hitbox[2]) * 0.5 --if no InRange point accesable then aim at defualt hitbox
10581072
--end
10591073

10601074
-- Inside your game loop
@@ -1086,7 +1100,7 @@ vdistance = (vPlayerOrigin - pLocalOrigin):Length()
10861100
-- Control charge if charge bot is enabled and the local player is in condition 17
10871101
ChargeControl(pCmd)
10881102
end
1089-
1103+
10901104
elseif Menu.Misc.ChargeControl and pLocal:InCond(17) then
10911105
-- Control charge if charge bot is enabled and the local player is in condition 17
10921106
ChargeControl(pCmd)
@@ -1095,32 +1109,21 @@ vdistance = (vPlayerOrigin - pLocalOrigin):Length()
10951109
--Check if attack simulation was succesfull
10961110
if can_attack == true then
10971111
--remove tick
1098-
1099-
Gcan_attack = false
1100-
if Menu.Misc.InstantAttack == true and warp.GetChargedTicks() > 15 then
1101-
warp.TriggerDoubleTap()
1102-
warp.TriggerWarp()
1103-
end
1104-
pCmd:SetButtons(pCmd:GetButtons() | IN_ATTACK)-- attack
1105-
1106-
elseif Menu.Misc.CritRefill then
1107-
if pWeapon:GetCritTokenBucket() <= 18 and fDistance > 350 then
1108-
pCmd:SetButtons(pCmd:GetButtons() | IN_ATTACK)--refill
1109-
end
1110-
Gcan_attack = true
1111-
else
1112-
1113-
Gcan_attack = true
1112+
if Menu.Misc.InstantAttack == true and warp.GetChargedTicks() > 15 then
1113+
warp.TriggerDoubleTap()
1114+
warp.TriggerWarp()
1115+
end
1116+
pCmd:SetButtons(pCmd:GetButtons() | IN_ATTACK)-- attack
1117+
can_attack = false
11141118
end
11151119

11161120
if can_charge then
11171121
pCmd:SetButtons(pCmd:GetButtons() | IN_ATTACK2)-- charge
1122+
can_charge = false
11181123
end
11191124

11201125
-- Update last variables
1121-
11221126
Safe_Strafe = false -- reset safe strafe
1123-
can_charge = false
11241127
vHitbox[2].z = 82
11251128
::continue::
11261129
end
@@ -1812,6 +1815,7 @@ if not (engine.Con_IsVisible() or engine.IsGameUIVisible()) and Menu.Visuals.Ena
18121815

18131816
ImMenu.BeginFrame(1)
18141817
Menu.Misc.InstantAttack = ImMenu.Checkbox("Instant Attack", Menu.Misc.InstantAttack)
1818+
Menu.Misc.advancedHitreg = ImMenu.Checkbox("Advanced Hitreg", Menu.Misc.advancedHitreg)
18151819
Menu.Misc.TroldierAssist = ImMenu.Checkbox("Troldier Assist", Menu.Misc.TroldierAssist)
18161820
ImMenu.EndFrame()
18171821

0 commit comments

Comments
 (0)