Skip to content

Commit 96c4362

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

File tree

1 file changed

+35
-22
lines changed

1 file changed

+35
-22
lines changed

A_Swing_Prediction.lua

+35-22
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ local ping = 0
210210
local swingrange = 48
211211
local tickRate = 66
212212
local tick_count = 0
213-
local time = 15
213+
local time = 14
214214
local Gcan_attack = false
215215
local Safe_Strafe = false
216216
local can_charge = false
@@ -221,7 +221,7 @@ local Backtrackpositions = {}
221221
local pLocalPath = {}
222222
local vPlayerPath = {}
223223
local PredPath = {}
224-
local vHitbox = { Vector3(-24, -24, 0), Vector3(24, 24, 82) }
224+
local vHitbox = { Vector3(-24, -24, 0), Vector3(24, 24, 80) }
225225
local drawVhitbox = {}
226226
local gravity = client.GetConVar("sv_gravity") or 800 -- Get the current gravity
227227
local stepSize = pLocal:GetPropFloat("localdata", "m_flStepSize") or 18
@@ -260,9 +260,16 @@ local lastDeltas = {} ---@type table<number, number>
260260
local avgDeltas = {} ---@type table<number, number>
261261
local strafeAngles = {} ---@type table<number, number>
262262
local inaccuracy = {} ---@type table<number, number>
263+
local pastPositions = {} -- Stores past positions of the local player
264+
local maxPositions = 4 -- Number of past positions to consider
265+
263266

264267
local function CalcStrafe()
265268
local players = entities.FindByClass("CTFPlayer")
269+
local autostrafe = gui.GetValue("Auto Strafe")
270+
local flags = pLocal:GetPropInt("m_fFlags")
271+
local OnGround = flags & FL_ONGROUND == 1
272+
266273
for idx, entity in ipairs(players) do
267274
local entityIndex = entity:GetIndex()
268275

@@ -276,6 +283,24 @@ local function CalcStrafe()
276283
end
277284

278285
local v = entity:EstimateAbsVelocity()
286+
if entity == pLocal then
287+
table.insert(pastPositions, 1, entity:GetAbsOrigin())
288+
if #pastPositions > maxPositions then
289+
table.remove(pastPositions)
290+
end
291+
292+
293+
if not onGround and autostrafe == 2 and #pastPositions >= maxPositions then
294+
v = Vector3(0, 0, 0)
295+
for i = 1, #pastPositions - 1 do
296+
v = v + (pastPositions[i] - pastPositions[i + 1])
297+
end
298+
v = v / (maxPositions - 1)
299+
else
300+
v = entity:EstimateAbsVelocity()
301+
end
302+
end
303+
279304
local angle = v:Angles()
280305

281306
if lastAngles[entityIndex] == nil then
@@ -683,7 +708,7 @@ local function checkInRangeWithLatency(playerIndex, swingRange)
683708
return inRange, point
684709
end
685710

686-
inRange = checkInRange(vPlayerFuture, pLocalFuture, swingRange)
711+
inRange, point = checkInRange(vPlayerFuture, pLocalFuture, swingRange)
687712
if inRange then
688713
return inRange, point, can_charge
689714
end
@@ -762,7 +787,7 @@ local function checkInRangeWithLatency(playerIndex, swingRange)
762787
return inRange, point
763788
end
764789

765-
inRange = checkInRange(vPlayerFuture, pLocalFuture, swingRange)
790+
inRange, point = checkInRange(vPlayerFuture, pLocalFuture, swingRange)
766791
if inRange then
767792
return inRange, point
768793
end
@@ -787,7 +812,6 @@ local function OnCreateMove(pCmd)
787812
if not pLocal or not pLocal:IsAlive() then
788813
goto continue -- Return if the local player entity doesn't exist or is dead
789814
end
790-
791815
-- Check if the local player is a spy
792816
pLocalClass = pLocal:GetPropInt("m_iClass")
793817
if pLocalClass == nil or pLocalClass == 8 then
@@ -805,7 +829,7 @@ local function OnCreateMove(pCmd)
805829
local latIn = clientstate.GetLatencyIn()
806830
lerp = client.GetConVar("cl_interp") or 0
807831
Latency = (latOut + lerp) -- Calculate the reaction time in seconds
808-
Latency = math.floor(Latency * tickRate + 1) -- Convert the delay to ticks
832+
Latency = math.floor(Latency * (globals.TickInterval() * 66) + 1) -- Convert the delay to ticks
809833
defFakeLatency = gui.GetValue("Fake Latency Value (MS)")
810834

811835
-- Get the local player's flags and charge meter
@@ -862,7 +886,7 @@ local function OnCreateMove(pCmd)
862886
--[-------- Get SwingRange --------]
863887
swingrange = pWeapon:GetSwingRange()
864888

865-
local SwingHullSize = 36
889+
local SwingHullSize = 35.6
866890

867891
if pWeaponDef:GetName() == "The Disciplinary Action" then
868892
SwingHullSize = 55.8
@@ -935,11 +959,11 @@ end
935959
gui.SetValue("Melee Crit Hack", Menu.Misc.CritMode)
936960
end
937961

938-
local ONGround
939962
local Target_ONGround
940963
local strafeAngle = 0
941964
local can_attack = false
942965
local stop = false
966+
local OnGround = flags & FL_ONGROUND == 1
943967

944968
--[--------------Prediction-------------------]
945969
-- Predict both players' positions after swing
@@ -948,9 +972,8 @@ end
948972

949973
CalcStrafe()
950974

951-
952975
if inaccuracyValue then
953-
swingrange = swingrange - inaccuracyValue
976+
swingrange = swingrange - math.abs(inaccuracyValue)
954977
end
955978

956979
-- Local player prediction
@@ -975,8 +998,8 @@ if CurrentTarget == nil then
975998
end
976999
vPlayerOrigin = CurrentTarget:GetAbsOrigin() -- Get closest player origin
9771000

978-
local pFlags = CurrentTarget:GetPropInt("m_fFlags")
979-
local DUCKING = flags & FL_DUCKING == 2
1001+
local VpFlags = CurrentTarget:GetPropInt("m_fFlags")
1002+
local DUCKING = VpFlags & FL_DUCKING == 2
9801003
if DUCKING then
9811004
vHitbox[2].z = 62
9821005
else
@@ -1058,16 +1081,6 @@ vdistance = (vPlayerOrigin - pLocalOrigin):Length()
10581081
-- Control charge if charge bot is enabled and the local player is in condition 17
10591082
ChargeControl(pCmd)
10601083
end
1061-
1062-
--Shield bashing strat
1063-
if pLocalClass == 4 and pLocal:InCond(17) then -- If we are charging (17 is TF_COND_SHIELD_CHARGE)
1064-
local Bashed = (pLocalOrigin - vPlayerOrigin):Length() < swingrange - 18 -- If we bashed on enemy
1065-
1066-
if not Bashed then -- If Demoknight bashed on enemy
1067-
can_attack = false
1068-
goto continue
1069-
end
1070-
end
10711084

10721085
--Check if attack simulation was succesfull
10731086
if can_attack == true then

0 commit comments

Comments
 (0)