Skip to content

Commit ac2e03d

Browse files
authored
Merge pull request #11 from oscar-wos/sv_accelerate-fix
fix: sv_accelerate
2 parents a8ab861 + 1e0208c commit ac2e03d

File tree

6 files changed

+49
-36
lines changed

6 files changed

+49
-36
lines changed

src/AntiRush.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,14 @@ private void DoAction(CCSPlayerController controller, Zone zone)
133133
switch (zone.Type)
134134
{
135135
case ZoneType.Bounce:
136-
controller.Bounce();
136+
const PlayerButtons checkButtons = PlayerButtons.Forward | PlayerButtons.Back | PlayerButtons.Moveleft | PlayerButtons.Moveright;
137+
138+
if ((controller.Buttons & checkButtons) != 0)
139+
controller.PlayerPawn.Value?.Teleport(new Vector(_playerData[controller].LastPos[0], _playerData[controller].LastPos[1], _playerData[controller].LastPos[2]), null, new Vector(_playerData[controller].LastVel[0], _playerData[controller].LastVel[1], _playerData[controller].LastVel[2]));
140+
141+
else
142+
controller.Bounce(_playerData[controller].LastPos, _playerData[controller].LastVel);
143+
137144
return;
138145

139146
case ZoneType.Hurt:

src/ControllerExtends.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using CounterStrikeSharp.API;
22
using CounterStrikeSharp.API.Core;
33
using CounterStrikeSharp.API.Modules.Admin;
4+
using CounterStrikeSharp.API.Modules.Utils;
45

56
namespace AntiRush;
67

@@ -16,7 +17,7 @@ public static bool IsValid(this CCSPlayerController? controller, bool checkBot =
1617

1718
public static void Damage(this CCSPlayerController? controller, int damage)
1819
{
19-
if (controller == null || !controller.IsValid() || controller!.PlayerPawn.Value == null)
20+
if (controller == null || !controller.IsValid() || controller.PlayerPawn.Value == null)
2021
return;
2122

2223
controller.PlayerPawn.Value.Health -= damage;
@@ -26,17 +27,17 @@ public static void Damage(this CCSPlayerController? controller, int damage)
2627
controller.PlayerPawn.Value.CommitSuicide(true, true);
2728
}
2829

29-
public static void Bounce(this CCSPlayerController? controller)
30+
public static void Bounce(this CCSPlayerController? controller, float[] lastPos, float[] lastVel)
3031
{
31-
if (controller == null || !controller.IsValid() || controller!.PlayerPawn.Value == null)
32+
if (controller == null || controller.PlayerPawn.Value == null)
3233
return;
3334

34-
var vel = controller.PlayerPawn.Value.AbsVelocity;
35-
var speed = Math.Sqrt(vel.X * vel.X + vel.Y * vel.Y);
35+
var vel = new Vector(lastVel[0], lastVel[1], lastVel[2]);
36+
var speed = vel.Length2D();
3637

37-
vel *= (-350 / (float)speed);
38+
vel *= (-350 / speed);
3839
vel.Z = vel.Z <= 0 ? 150 : Math.Min(vel.Z, 150);
39-
controller.PlayerPawn.Value.Teleport(controller.PlayerPawn.Value.AbsOrigin, controller.PlayerPawn.Value.EyeAngles, vel);
40+
controller.PlayerPawn.Value.Teleport(new Vector(lastPos[0], lastPos[1], lastPos[2]), null, vel);
4041
}
4142

4243
public static bool HasPermission(this CCSPlayerController? controller, string permission)

src/Globals.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
namespace AntiRush;
66

7-
[MinimumApiVersion(245)]
7+
[MinimumApiVersion(304)]
88
public partial class AntiRush
99
{
1010
public override string ModuleName => "AntiRush";
11-
public override string ModuleVersion => "1.0.8";
11+
public override string ModuleVersion => "1.0.9";
1212
public override string ModuleAuthor => "https://github.com/oscar-wos/AntiRush";
1313
public AntiRushConfig Config { get; set; } = new();
1414
public Menu.Menu Menu { get; } = new();

src/Listeners.cs

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ private void OnTick()
3434

3535
foreach (var controller in Utilities.GetPlayers().Where(c => c.IsValid() && c.PawnIsAlive))
3636
{
37+
if (controller.PlayerPawn.Value == null)
38+
continue;
39+
40+
var doAction = false;
41+
3742
foreach (var zone in _zones)
3843
{
3944
if (((Config.NoRushTime != 0 && Config.NoRushTime + _roundStart < Server.CurrentTime) || _bombPlanted) && Config.RushZones.Contains((int)zone.Type))
@@ -42,53 +47,52 @@ private void OnTick()
4247
if (Config.NoCampTime != 0 && Config.NoCampTime + _roundStart > Server.CurrentTime && Config.CampZones.Contains((int)zone.Type))
4348
continue;
4449

45-
var isInZone = zone.IsInZone(controller.PlayerPawn.Value!.AbsOrigin!);
50+
var isInZone = zone.IsInZone(controller.PlayerPawn.Value.AbsOrigin!);
4651

4752
if (!zone.Data.TryGetValue(controller, out _))
4853
zone.Data[controller] = new ZoneData();
4954

55+
if (!zone.Teams.Contains(controller.Team))
56+
continue;
57+
5058
if (!isInZone)
5159
{
52-
if (zone.Data[controller].Entry != 0)
53-
{
54-
zone.Data[controller].Entry = 0;
55-
zone.Data[controller].Exit = Server.CurrentTime;
56-
}
57-
60+
zone.Data[controller].Entry = 0;
5861
continue;
5962
}
6063

61-
if (zone.Data[controller].Entry == 0)
64+
if (zone.Delay == 0)
6265
{
63-
zone.Data[controller].Entry = Server.CurrentTime;
64-
zone.Data[controller].Exit = 0;
66+
doAction = true;
67+
DoAction(controller, zone);
68+
continue;
6569
}
6670

67-
if (!zone.Teams.Contains(controller.Team))
68-
continue;
71+
if (zone.Data[controller].Entry == 0)
72+
zone.Data[controller].Entry = Server.CurrentTime;
73+
74+
var diff = (zone.Data[controller].Entry + zone.Delay) - Server.CurrentTime;
6975

70-
if (zone.Delay != 0)
76+
if (diff > 0)
7177
{
72-
var diff = (zone.Data[controller].Entry + zone.Delay) - Server.CurrentTime;
78+
var diffString = diff % 1;
7379

74-
if (diff > 0)
75-
{
76-
var diffString = diff % 1;
77-
78-
if (diffString.ToString("0.00") is ("0.00" or "0.01") && diff >= 1)
79-
controller.PrintToChat($"{Prefix}{Localizer["delayRemaining", zone.ToString(Localizer), diff.ToString("0")]}");
80-
}
81-
else
82-
DoAction(controller, zone);
80+
if (diffString.ToString("0.00") is ("0.00" or "0.01") && diff >= 1)
81+
controller.PrintToChat($"{Prefix}{Localizer["delayRemaining", zone.ToString(Localizer), diff.ToString("0")]}");
8382

8483
continue;
8584
}
8685

86+
doAction = true;
8787
DoAction(controller, zone);
8888
}
89-
}
9089

91-
return;
90+
if (doAction)
91+
continue;
92+
93+
_playerData[controller].LastPos = [controller.PlayerPawn.Value.AbsOrigin!.X, controller.PlayerPawn.Value.AbsOrigin.Y, controller.PlayerPawn.Value.AbsOrigin.Z];
94+
_playerData[controller].LastVel = [controller.PlayerPawn.Value.AbsVelocity.X, controller.PlayerPawn.Value.AbsVelocity.Y, controller.PlayerPawn.Value.AbsVelocity.Z];
95+
}
9296
}
9397

9498
private void OnMapStart(string mapName)

src/PlayerData.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ public class PlayerData
1010
public float LastMessage { get; set; }
1111
public bool Debug { get; set; }
1212
public bool[] DebugOptions { get; set; } = new bool[Enum.GetValues(typeof(ZoneType)).Length];
13+
public float[] LastPos = [];
14+
public float[] LastVel = [];
1315
}

src/ZoneData.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33
public class ZoneData
44
{
55
public float Entry { get; set; }
6-
public float Exit { get; set; }
76
}

0 commit comments

Comments
 (0)