Skip to content

Commit 0de0a50

Browse files
Add files via upload
1 parent 26a114a commit 0de0a50

File tree

1 file changed

+76
-59
lines changed

1 file changed

+76
-59
lines changed

A_Swing_Prediction.lua

+76-59
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ local Mchargebot = menu:AddComponent(MenuLib.Checkbox("Charge Controll", true
4242
local mSensetivity = menu:AddComponent(MenuLib.Slider("Charge Sensetivity",1 ,100 ,50 ))
4343
local mAutoRefill = menu:AddComponent(MenuLib.Checkbox("Crit Refill", true))
4444
local mInstaHit = menu:AddComponent(MenuLib.Checkbox("Instant attack", true))
45+
local mWhipMate = menu:AddComponent(MenuLib.Checkbox("Whip teamamtes", true))
4546
--local AutoFakelat = menu:AddComponent(MenuLib.Checkbox("Adaptive Latency", true, ItemFlags.FullWidth))
4647
local AchargeRange = menu:AddComponent(MenuLib.Checkbox("Charge Reach", false, ItemFlags.FullWidth))
4748
local mAutoGarden = menu:AddComponent(MenuLib.Checkbox("Troldier assist", false))
@@ -298,7 +299,7 @@ end
298299
local function GetBestTarget(me)
299300
settings = {
300301
MinDistance = swingrange,
301-
MaxDistance = 1000,
302+
MaxDistance = 770,
302303
MinFOV = 0,
303304
MaxFOV = 360,
304305
}
@@ -307,41 +308,49 @@ local function GetBestTarget(me)
307308
local localPlayer = entities.GetLocalPlayer()
308309
if not localPlayer then return end
309310

311+
local localPlayerOrigin = localPlayer:GetAbsOrigin()
312+
local localPlayerTeam = localPlayer:GetTeamNumber()
313+
local localPlayerViewAngles = engine.GetViewAngles()
314+
310315
local targetList = {}
311316
local targetCount = 0
312-
313317
-- Calculate target factors
314318
for i, player in ipairs(players) do
315-
if not Helpers.VisPos(player, pLocalOrigin, player:GetAbsOrigin()) then
316-
-- Skip players not visible
317-
goto continue
318-
end
319+
local playerTeam = player:GetTeamNumber()
320+
local playerOrigin = player:GetAbsOrigin()
319321

320-
if player == localPlayer or player:GetTeamNumber() == localPlayer:GetTeamNumber() then
321-
-- Skip local player and teammates
322+
-- Check if the player is invalid
323+
if player == nil or player == pLocal or not player:IsAlive() or player:IsDormant() then
322324
goto continue
323325
end
324326

325-
if player == nil or not player:IsAlive() then
326-
-- Skip dead players or nil references
327+
-- Check if we have a whip and the "whip teammates" option is off, but the player is on the local player's team
328+
if not mWhipMate:GetValue() and swingrange == 109.5 and playerTeam == localPlayerTeam then
327329
goto continue
328330
end
329-
331+
330332
if gui.GetValue("ignore cloaked") == 1 and player:InCond(4) then
331-
-- Skip cloaked players if enabled
333+
goto continue
334+
end
335+
336+
if not Helpers.VisPos(player, localPlayerOrigin, playerOrigin) then
332337
goto continue
333338
end
334339

335-
if player:IsDormant() then
336-
-- Skip dormant players
340+
341+
-- Calculate Manhattan distance
342+
local distance = math.abs(playerOrigin.x - localPlayerOrigin.x) + math.abs(playerOrigin.y - localPlayerOrigin.y) + math.abs(playerOrigin.z - localPlayerOrigin.z)
343+
344+
if distance > settings.MaxDistance then
337345
goto continue
338346
end
339347

340-
local distance = (player:GetAbsOrigin() - localPlayer:GetAbsOrigin()):Length()
348+
local angles = Math.PositionAngles(localPlayerOrigin, playerOrigin + Vector3(0, 0, viewheight))
349+
local fov = Math.AngleFov(localPlayerViewAngles, angles)
341350

342-
-- Visibility Check
343-
local angles = Math.PositionAngles(pLocalOrigin, player:GetAbsOrigin() + Vector3(0, 0, viewheight))
344-
local fov = Math.AngleFov(engine.GetViewAngles(), angles)
351+
if fov > settings.MaxFOV then
352+
goto continue
353+
end
345354

346355
local distanceFactor = Math.RemapValClamped(distance, settings.MinDistance, settings.MaxDistance, 1, 0.07)
347356
local fovFactor = Math.RemapValClamped(fov, settings.MinFOV, settings.MaxFOV, 1, 1)
@@ -366,20 +375,22 @@ local function GetBestTarget(me)
366375
local bestTarget = nil
367376

368377
if targetCount > 0 then
369-
local player = targetList[1].player
370-
local aimPos = player:GetAbsOrigin() + Vector3(0, 0, 75)
371-
local angles = Math.PositionAngles(localPlayer:GetAbsOrigin(), aimPos)
372-
local fov = Math.AngleFov(angles, engine.GetViewAngles())
378+
local bestPlayer = targetList[1].player
379+
local bestPlayerOrigin = bestPlayer:GetAbsOrigin()
380+
local aimPos = bestPlayerOrigin + Vector3(0, 0, 75)
381+
local angles = Math.PositionAngles(localPlayerOrigin, aimPos)
382+
local fov = Math.AngleFov(angles, localPlayerViewAngles)
373383

374384
-- Set as best target
375-
bestTarget = { entity = player, angles = angles, factor = targetList[1].factor }
385+
bestTarget = { entity = bestPlayer, angles = angles, factor = targetList[1].factor }
376386
end
377387

378388
return bestTarget
379389
end
380390

391+
381392
-- Define function to check InRange between the hitbox and the sphere
382-
local function checkInRange(targetPos, spherePos, sphereRadius)
393+
local function checkInRange(targetPos, spherePos, sphereRadius, target)
383394
if vPlayerFuture == nil or not isMelee then
384395
return false, nil
385396
end
@@ -670,15 +681,13 @@ local cornerposition = Vector3( --ToDO: fix this
670681

671682
--[--------------Prediction-------------------]
672683
-- Predict both players' positions after swing
673-
strafeAngle = 0
674684
gravity = client.GetConVar("sv_gravity")
675685
stepSize = pLocal:GetPropFloat("localdata", "m_flStepSize")
676686

677687
-- Local player prediction
678688
if pLocal:EstimateAbsVelocity() == 0 then
679689
-- If the local player is not accelerating, set the predicted position to the current position
680690
pLocalFuture = pLocalOrigin
681-
strafeAngle = 0
682691
else
683692
local player = WPlayer.FromEntity(pLocal)
684693
CalcStrafe(player)
@@ -687,7 +696,7 @@ local cornerposition = Vector3( --ToDO: fix this
687696
local pHitbox = CalculateHitboxOffsets(player)
688697

689698
local predData = PredictPlayer(player, time, strafeAngle, pHitbox)
690-
local straightPredData = PredictPlayer(player, time, 0, pHitbox)
699+
--local straightPredData = PredictPlayer(player, time, 0, pHitbox)
691700

692701
if predData == nil then
693702
goto continue
@@ -698,12 +707,9 @@ local cornerposition = Vector3( --ToDO: fix this
698707
end
699708

700709
-- Target player prediction
701-
strafeAngle = 0
702-
703710
if CurrentTarget:EstimateAbsVelocity() == 0 then
704711
-- If the target player is not accelerating, set the predicted position to their current position
705712
vPlayerFuture = CurrentTarget:GetAbsOrigin()
706-
strafeAngle = 0
707713
else
708714
local player = WPlayer.FromEntity(CurrentTarget)
709715
CalcStrafe(player)
@@ -712,16 +718,16 @@ local cornerposition = Vector3( --ToDO: fix this
712718
local pHitbox = CalculateHitboxOffsets(player)
713719

714720
local predData = PredictPlayer(player, time, strafeAngle, pHitbox)
715-
local straightPredData = PredictPlayer(player, time, 0, pHitbox)
721+
--local straightPredData = PredictPlayer(player, time, 0, pHitbox)
716722

717723
if not predData then
718724
goto continue
719725
end
720726

721-
local hitchance = calculateHitChancePercentage(predData.pos[time], straightPredData.pos[time])
722-
if hitchance < 10 then
723-
predData = straightPredData
724-
end
727+
--local hitchance = calculateHitChancePercentage(predData.pos[time], straightPredData.pos[time])
728+
--if hitchance < 10 then
729+
--predData = straightPredData
730+
--end
725731

726732
vPlayerPath = predData.pos
727733
vPlayerFuture = predData.pos[time]
@@ -738,25 +744,33 @@ fDistance = (vPlayerFuture - pLocalFuture):Length()
738744
-- Simulate swing and return result
739745
local InRangePoint
740746

741-
--[[---Check for hit detection--------]]
742-
ONGround = (flags & FL_ONGROUND == 1)
743-
local InRange = false
744-
can_charge = false
745-
746747
-- Check for InRange with current position
747748
InRange, InRangePoint = checkInRange(vPlayerOrigin, pLocalOrigin, swingrange)
748-
-- Trigger doubletap only if in range, attacking, and doubletap conditions are met
749-
750-
if not InRange then
751-
-- If not in range, check future positions
752-
InRange = checkInRange(vPlayerFuture, pLocalFuture, swingrange)
753-
end
754749

755750
-- Decide if can attack based on InRange
756751
can_attack = InRange
757-
758752

753+
if can_attack then
754+
-- If in range, move players to their future positions
755+
CurrentTarget:SetPropVector(vPlayerFuture, "tfnonlocaldata", "m_vecOrigin")
756+
pLocal:SetPropVector(pLocalFuture, "tfnonlocaldata", "m_vecOrigin")
757+
758+
-- Make pLocal aim at the InRangePoint
759+
local aimAngles = Math.PositionAngles(pLocalFuture, InRangePoint)
760+
pCmd:SetViewAngles(aimAngles.pitch, aimAngles.yaw, 0)
759761

762+
-- Run a swing trace from pLocal to the target
763+
local swingTrace = pLocal:DoSwingTrace()
764+
765+
-- If the entity hit by the swing trace is the same as the target, consider the attack successful
766+
if swingTrace then
767+
can_charge = true
768+
end
769+
770+
-- Move players back to their original positions
771+
CurrentTarget:SetPropVector(vPlayerOrigin, "tfnonlocaldata", "m_vecOrigin")
772+
pLocal:SetPropVector(pLocalOrigin, "tfnonlocaldata", "m_vecOrigin")
773+
end
760774
-- Check for charge range bug
761775
if pLocalClass == 4 -- player is Demoman
762776
and AchargeRange:GetValue() -- menu option for such option is true
@@ -797,20 +811,23 @@ can_attack = InRange
797811
goto continue
798812
end
799813

800-
if Maimbot:GetValue() and Helpers.VisPos(CurrentTarget, vPlayerFuture, pLocalFuture)
801-
and pLocal:InCond(17)
802-
and not InRange
803-
then
804-
Eaimpos = Math.PositionAngles(pLocalOrigin, Eaimpos)
805-
pCmd:SetViewAngles(engine.GetViewAngles().pitch, Eaimpos.yaw, 0)
806-
elseif Maimbot:GetValue() and can_attack then
807-
Eaimpos = Math.PositionAngles(pLocalOrigin, Eaimpos)
808-
if MSilent:GetValue() then
809-
pCmd:SetViewAngles(Eaimpos.pitch, Eaimpos.yaw, 0)
810-
else
811-
engine.SetViewAngles(EulerAngles(Eaimpos.pitch, Eaimpos.yaw, 0))
814+
-- Calculate aim position only once
815+
Eaimpos = Math.PositionAngles(pLocalOrigin, Eaimpos)
816+
817+
if Maimbot:GetValue() then
818+
if Helpers.VisPos(CurrentTarget, vPlayerFuture, pLocalFuture) and not InRange then
819+
-- Set view angles based on the future position of the local player
820+
pCmd:SetViewAngles(engine.GetViewAngles().pitch, Eaimpos.yaw, 0)
821+
elseif can_attack then
822+
-- Set view angles based on whether silent aim is enabled
823+
if MSilent:GetValue() then
824+
pCmd:SetViewAngles(Eaimpos.pitch, Eaimpos.yaw, 0)
825+
else
826+
engine.SetViewAngles(EulerAngles(Eaimpos.pitch, Eaimpos.yaw, 0))
827+
end
812828
end
813829
elseif Mchargebot:GetValue() and pLocal:InCond(17) then
830+
-- Control charge if charge bot is enabled and the local player is in condition 17
814831
ChargeControl(pCmd)
815832
end
816833

0 commit comments

Comments
 (0)