Skip to content

Commit 9471a99

Browse files
committed
Added pistols round
1 parent 57097f5 commit 9471a99

File tree

8 files changed

+104
-5
lines changed

8 files changed

+104
-5
lines changed

Modules/Config.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Text.Json;
2+
using CounterStrikeSharp.API.Modules.Utils;
23
using MySqlConnector;
34

45
using static RetakesAllocator.Modules.Core;
@@ -10,6 +11,7 @@ public class Config
1011
{
1112
public ConnectionConfig DbConnection { get; init; } = null!;
1213
public PrefixConfig Prefix { get; init; } = null!;
14+
public PistolRoundConfig PistolRound { get; init; } = null!;
1315

1416
public bool GiveArmor {get; init;} = true;
1517
public string[] triggerWords {get; init;} = { "guns", "gun", "weapon", "weapons"};
@@ -19,8 +21,10 @@ public Config()
1921
{
2022
DbConnection = new ConnectionConfig();
2123
Prefix = new PrefixConfig();
24+
PistolRound = new PistolRoundConfig();
2225
GiveArmor = true;
2326
triggerWords = new string[] { "guns", "gun", "weapon", "weapons"};
27+
AddSkipOption = true;
2428
}
2529

2630
public bool IsValid()
@@ -58,6 +62,18 @@ public class PrefixConfig
5862
public string PrefixCon { get; set; } = "[RetakesAllocator]";
5963
}
6064

65+
public class PistolRoundConfig
66+
{
67+
public int RoundAmount { get; init; } = 2;
68+
public string weapon_t { get; init; } = "weapon_glock";
69+
public string weapon_ct { get; init; } = "weapon_usp_silencer";
70+
71+
public string GetWeaponByTeam(CsTeam team)
72+
{
73+
return (team == CsTeam.Terrorist) ? weapon_t : weapon_ct;
74+
}
75+
}
76+
6177
public static class Configs
6278
{
6379
public const string ConfigDirectory = "configs";

Modules/Core.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace RetakesAllocator.Modules;
1515

16-
[MinimumApiVersion(154)]
16+
[MinimumApiVersion(202)]
1717
public class Core : BasePlugin
1818
{
1919
public static Core Plugin = null!;
@@ -27,6 +27,7 @@ public class Core : BasePlugin
2727

2828
public static Database Db = null!;
2929
public static List<Player> Players = new();
30+
public static int RoundsCounter = 0;
3031

3132
public override void Load(bool hotReload)
3233
{

Modules/Handlers/Events.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,49 @@
44
using static RetakesAllocator.Modules.Core;
55
using static RetakesAllocator.Modules.Utils;
66
using static RetakesAllocator.Modules.Models.Player;
7+
using CounterStrikeSharp.API;
78

89
namespace RetakesAllocator.Modules.Handlers;
910

1011
internal static class Events
1112
{
13+
static bool IgnoreRoundEnd = false;
14+
1215
public static void RegisterEvents()
1316
{
1417
Plugin.RegisterEventHandler<EventRoundPrestart>(OnRoundPreStart);
18+
Plugin.RegisterEventHandler<EventRoundEnd>(OnRoundEnd);
1519
Plugin.RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
1620
}
1721

1822
private static HookResult OnRoundPreStart(EventRoundPrestart @event, GameEventInfo info)
1923
{
2024
if (GetGameRules().WarmupPeriod)
2125
{
26+
IgnoreRoundEnd = true;
2227
return HookResult.Continue;
2328
}
2429

30+
// TODO: Add Vote Logic
31+
2532
SetupPlayers(Players);
2633

2734
return HookResult.Continue;
2835
}
2936

37+
private static HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info)
38+
{
39+
if (GetGameRules().WarmupPeriod || IgnoreRoundEnd)
40+
{
41+
IgnoreRoundEnd = false;
42+
return HookResult.Continue;
43+
}
44+
45+
RoundsCounter++;
46+
47+
return HookResult.Continue;
48+
}
49+
3050
private static HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
3151
{
3252
if(GetGameRules().WarmupPeriod)

Modules/Handlers/Listeners.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public static void RegisterListeners()
2424

2525
private static void OnMapStart(string map_name)
2626
{
27+
RoundsCounter = 0;
2728
Players.Clear();
2829
Utilities.GetPlayers().ForEach(AddPlayerToList);
2930
}

Modules/Models/Player.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ public void CreateSpawnDelay()
9494

9595
private void Timer_GiveWeapons()
9696
{
97+
if(RoundsCounter < Core.Config.PistolRound.RoundAmount)
98+
{
99+
WeaponsAllocator.AllocatePistolRound();
100+
return;
101+
}
102+
97103
WeaponsAllocator.Allocate();
98104
}
99105
}

Modules/Utils.cs

Lines changed: 25 additions & 0 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.Commands;
4+
using CounterStrikeSharp.API.Modules.Utils;
45
using static RetakesAllocator.Modules.Core;
56
using static RetakesAllocator.Modules.Database;
67
using Player = RetakesAllocator.Modules.Models.Player;
@@ -17,6 +18,11 @@ public static void PrintToChat(CCSPlayerController controller, string msg)
1718
controller.PrintToChat(msg);
1819
}
1920

21+
public static void PrintToChatAll(string msg)
22+
{
23+
Server.PrintToChatAll(msg);
24+
}
25+
2026
public static void PrintToServer(string msg, ConsoleColor color = ConsoleColor.Cyan)
2127
{
2228
Console.ForegroundColor = color;
@@ -85,4 +91,23 @@ public static void RemovePlayerFromList(CCSPlayerController player)
8591

8692
Players.Remove(playerObj);
8793
}
94+
95+
public static int GetRoundsAmount()
96+
{
97+
IEnumerable<CTeam> team = Utilities.FindAllEntitiesByDesignerName<CTeam>("cs_team");
98+
99+
if (team.Count() == 0)
100+
{
101+
return 0;
102+
}
103+
104+
int rounds = 0;
105+
106+
foreach (var t in team)
107+
{
108+
rounds = t.Score;
109+
}
110+
111+
return rounds;
112+
}
88113
}

Modules/Weapons/Allocator.cs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,38 @@ public void Allocate()
151151
GiveArmor();
152152
}
153153

154+
public void AllocatePistolRound()
155+
{
156+
if (_player == null || cCSPlayerController == null || !_player.player.IsValid)
157+
{
158+
return;
159+
}
160+
161+
if (!cCSPlayerController.PawnIsAlive)
162+
{
163+
return;
164+
}
165+
166+
if (cCSPlayerController.Team < CsTeam.Terrorist || cCSPlayerController.Team > CsTeam.CounterTerrorist)
167+
{
168+
return;
169+
}
170+
171+
172+
string secondary = Core.Config.PistolRound.GetWeaponByTeam(cCSPlayerController.Team);
173+
174+
cCSPlayerController.GiveNamedItem(secondary);
175+
cCSPlayerController.GiveNamedItem(CsItem.Knife);
176+
177+
if (cCSPlayerController.Team == CsTeam.CounterTerrorist)
178+
{
179+
GiveCtEquipment();
180+
}
181+
182+
if(Core.Config.GiveArmor)
183+
cCSPlayerController.GiveNamedItem(CsItem.Kevlar);
184+
}
185+
154186
private CsItem SelectGrenade()
155187
{
156188
var grenade = CsItem.HEGrenade;
@@ -178,8 +210,6 @@ private CsItem SelectGrenade()
178210

179211
private void GiveCtEquipment()
180212
{
181-
cCSPlayerController.GiveNamedItem(CsItem.KevlarHelmet);
182-
183213
if (
184214
cCSPlayerController.Team == CsTeam.CounterTerrorist
185215
&& cCSPlayerController.PlayerPawn.IsValid

RetakesAllocator.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<RootNamespace>RetakesAllocator</RootNamespace>
@@ -14,6 +14,6 @@
1414
</ItemGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.168" />
17+
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.202" />
1818
</ItemGroup>
1919
</Project>

0 commit comments

Comments
 (0)