@@ -525,31 +525,72 @@ local function GetBestTarget(me)
525
525
return bestTarget
526
526
end
527
527
528
- -- Define function to check InRange between the hitbox and the sphere
529
- local function checkInRange (targetPos , spherePos , sphereRadius )
530
-
531
- local hitbox_min_trigger = targetPos + vHitbox [1 ]
532
- local hitbox_max_trigger = targetPos + vHitbox [2 ]
533
-
534
- -- Calculate the closest point on the hitbox to the sphere
535
- local closestPoint = Vector3 (
536
- math.max (hitbox_min_trigger .x , math.min (spherePos .x , hitbox_max_trigger .x )),
537
- math.max (hitbox_min_trigger .y , math.min (spherePos .y , hitbox_max_trigger .y )),
538
- math.max (hitbox_min_trigger .z , math.min (spherePos .z , hitbox_max_trigger .z ))
539
- )
540
-
541
- -- Calculate the vector from the closest point to the sphere center
542
- local distanceAlongVector = (spherePos - closestPoint ):Length ()
543
- -- Compare the distance along the vector to the sum of the radius
544
- if sphereRadius > distanceAlongVector then
545
- return true , closestPoint
546
- else
547
- -- Not InRange
548
- return false , nil
549
- end
528
+ local can_attack = false
529
+ local OriginalAngles = Vector3 ()
530
+ local OriginalPosition = Vector3 ()
531
+ local lastswingtracedata = {}
532
+ local swingresult
533
+
534
+ -- Function to check if target is in range
535
+ local function checkInRange (targetPos , spherePos , sphereRadius , pWeapon )
536
+ local hitbox_min_trigger = targetPos + vHitbox [1 ]
537
+ local hitbox_max_trigger = targetPos + vHitbox [2 ]
538
+
539
+ -- Calculate the closest point on the hitbox to the sphere
540
+ local closestPoint = Vector3 (
541
+ math.max (hitbox_min_trigger .x , math.min (spherePos .x , hitbox_max_trigger .x )),
542
+ math.max (hitbox_min_trigger .y , math.min (spherePos .y , hitbox_max_trigger .y )),
543
+ math.max (hitbox_min_trigger .z , math.min (spherePos .z , hitbox_max_trigger .z ))
544
+ )
545
+
546
+ -- Calculate the distance from the closest point to the sphere center
547
+ local distanceAlongVector = (spherePos - closestPoint ):Length ()
548
+
549
+ -- Check if the target is within the sphere radius
550
+ 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
556
+ else
557
+ lastswingtracedata = nil
558
+ -- Target is not in range
559
+ return false , nil
550
560
end
551
-
552
-
561
+ end
562
+
563
+
564
+ -- PostPropUpdate function to adjust player position and angle
565
+ 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
+ local Angle = Math .PositionAngles (spherePos , closestPoint )
571
+
572
+ -- Adjust player position and view angles for swing trace
573
+ pLocal :SetPropVector (spherePos , " tfnonlocaldata" , " m_vecOrigin" )
574
+ pLocal :SetPropVector (Vector3 (Angle .x , Angle .y , Angle .z ), " tfnonlocaldata" , " m_angEyeAngles[0]" )
575
+
576
+ -- Perform the swing trace
577
+ local SwingTrace = pLocal .DoSwingTrace (pWeapon )
578
+ swingresult = SwingTrace
579
+
580
+ -- Reset the player's original position and view angles
581
+ pLocal :SetPropVector (OriginalPosition , " tfnonlocaldata" , " m_vecOrigin" )
582
+ pLocal :SetPropVector (OriginalAngles , " tfnonlocaldata" , " m_angEyeAngles[0]" )
583
+
584
+ -- Clear last swing trace data
585
+ lastswingtracedata = nil
586
+ end
587
+ end
588
+
589
+ callbacks .Unregister (" PostPropUpdate" , " swingcheck" ) -- Unregister the "CreateMove" callback
590
+ callbacks .Register (" PostPropUpdate" ," swingcheck" , PropUpdate )
591
+
592
+
593
+
553
594
554
595
local Hitbox = {
555
596
Head = 1 ,
@@ -643,7 +684,7 @@ local function UpdateHomingMissile()
643
684
end
644
685
645
686
local hasNotified = false
646
- local function checkInRangeWithLatency (playerIndex , swingRange )
687
+ local function checkInRangeWithLatency (playerIndex , swingRange , pWeapon , cmd )
647
688
local inRange = false
648
689
local point = nil
649
690
local Backtrack = gui .GetValue (" Backtrack" )
@@ -675,13 +716,13 @@ local function checkInRangeWithLatency(playerIndex, swingRange)
675
716
end
676
717
677
718
-- Adjust hitbox for current position
678
- inRange , point = checkInRange (vPlayerOrigin , pLocalOrigin , swingRange - 18 )
719
+ inRange , point = checkInRange (vPlayerOrigin , pLocalOrigin , swingRange - 18 , pWeapon , cmd )
679
720
if inRange then
680
721
return inRange , point
681
722
end
682
723
683
724
684
- inRange , point = checkInRange (vPlayerFuture , pLocalFuture , swingRange )
725
+ inRange , point = checkInRange (vPlayerFuture , pLocalFuture , swingRange , pWeapon , cmd )
685
726
if inRange then
686
727
return inRange , point , can_charge
687
728
end
@@ -713,7 +754,7 @@ local function checkInRangeWithLatency(playerIndex, swingRange)
713
754
end
714
755
end
715
756
716
- inRange , point = checkInRange (pastOrigin , pLocalOrigin , swingRange )
757
+ inRange , point = checkInRange (pastOrigin , pLocalOrigin , swingRange , pWeapon , cmd )
717
758
if inRange then
718
759
return inRange , point
719
760
end
@@ -748,12 +789,12 @@ local function checkInRangeWithLatency(playerIndex, swingRange)
748
789
end
749
790
750
791
-- Adjust hitbox for current position
751
- inRange , point = checkInRange (vPlayerOrigin , pLocalOrigin , swingRange )
792
+ inRange , point = checkInRange (vPlayerOrigin , pLocalOrigin , swingRange , pWeapon , cmd )
752
793
if inRange then
753
794
return inRange , point
754
795
end
755
796
756
- inRange = checkInRange (vPlayerFuture , pLocalFuture , swingRange )
797
+ inRange = checkInRange (vPlayerFuture , pLocalFuture , swingRange , pWeapon , cmd )
757
798
if inRange then
758
799
return inRange , point
759
800
end
928
969
929
970
local Target_ONGround
930
971
local strafeAngle = 0
931
- local can_attack = false
972
+ can_attack = false
932
973
local stop = false
933
974
local OnGround = flags & FL_ONGROUND == 1
934
975
@@ -1002,7 +1043,7 @@ vdistance = (vPlayerOrigin - pLocalOrigin):Length()
1002
1043
local inRange = false
1003
1044
local inRangePoint = nil
1004
1045
1005
- inRange , InRangePoint , can_charge = checkInRangeWithLatency (CurrentTarget :GetIndex (), swingrange )
1046
+ inRange , InRangePoint , can_charge = checkInRangeWithLatency (CurrentTarget :GetIndex (), swingrange , pWeapon , pCmd )
1006
1047
-- Use inRange to decide if can attack
1007
1048
can_attack = inRange
1008
1049
0 commit comments