-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMoveSpec.cs
More file actions
204 lines (176 loc) · 6.81 KB
/
Copy pathMoveSpec.cs
File metadata and controls
204 lines (176 loc) · 6.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Admin;
using CounterStrikeSharp.API.Core.Capabilities;
using CounterStrikeSharp.API.Modules.Entities;
using CounterStrikeSharp.API.Modules.Utils;
using MenuManager;
using System.Collections.Generic;
using System.Linq;
namespace MoveSpec;
public class MoveSpec : BasePlugin
{
private IMenuApi? _menuApi;
private readonly PluginCapability<IMenuApi?> _menuApiCapability = new("menu:nfcore");
private CCSPlayerController? _tCaptain;
private CCSPlayerController? _ctCaptain;
private List<CCSPlayerController> _availablePlayers = new();
private bool _isPickingInProgress = false;
private bool _isCTTurn = true; // CT picks first
private int _pickedPlayers = 0; // 8 picks (4 per team)
public override string ModuleName => "MoveSpec";
public override string ModuleVersion => "1.0.0";
public override string ModuleAuthor => "NoxianWill";
public override string ModuleDescription => "MoveSpec: Admin team picking and captain system with menu support.";
public override void OnAllPluginsLoaded(bool hotReload)
{
_menuApi = _menuApiCapability.Get();
}
[ConsoleCommand("css_spec", "Moves all players to spectators and starts captain picking")]
public void OnSpecCommand(CCSPlayerController? player, CommandInfo command)
{
if (!IsAdmin(player)) return;
if (_menuApi == null)
{
player?.PrintToChat("[MoveSpec] MenuManager not available!");
return;
}
if (_tCaptain == null || _ctCaptain == null)
{
player?.PrintToChat("[MoveSpec] Both captains must be set first!");
return;
}
_availablePlayers.Clear();
foreach (var p in Utilities.GetPlayers())
{
if (p != null && p.IsValid && p.PlayerPawn.IsValid && p != _tCaptain && p != _ctCaptain)
{
p.ChangeTeam(CsTeam.Spectator);
_availablePlayers.Add(p);
}
}
_isPickingInProgress = true;
_isCTTurn = true;
_pickedPlayers = 0;
PrintToAll("[MoveSpec] Captain picking has started! CT captain picks first.");
ShowPickingMenu(_ctCaptain);
}
[ConsoleCommand("css_mscancel", "Cancels the captain picking process and moves players back to teams")]
public void OnCancelCommand(CCSPlayerController? player, CommandInfo command)
{
if (!IsAdmin(player)) return;
if (!_isPickingInProgress)
{
player?.PrintToChat("[MoveSpec] No picking process in progress!");
return;
}
CancelPickingProcess();
}
private void CancelPickingProcess()
{
if (!_isPickingInProgress) return;
// Move all spectators back to teams
foreach (var p in Utilities.GetPlayers())
{
if (p != null && p.IsValid && p.PlayerPawn.IsValid && p.Team == CsTeam.Spectator)
{
// Alternate between T and CT teams
p.ChangeTeam(_isCTTurn ? CsTeam.CounterTerrorist : CsTeam.Terrorist);
_isCTTurn = !_isCTTurn;
}
}
// Reset all state
_isPickingInProgress = false;
_availablePlayers.Clear();
_pickedPlayers = 0;
_tCaptain = null;
_ctCaptain = null;
PrintToAll("[MoveSpec] Captain picking process has been cancelled. Players have been moved back to teams.");
}
[ConsoleCommand("css_tcapt", "Sets the Terrorist team captain")]
[CommandHelper(minArgs: 1, usage: "<player name>")]
public void OnTCaptCommand(CCSPlayerController? player, CommandInfo command)
{
if (!IsAdmin(player)) return;
var targetName = command.GetArg(1);
var target = FindPlayerByName(targetName);
if (target == null)
{
player?.PrintToChat("[MoveSpec] Player not found!");
return;
}
_tCaptain = target;
target.ChangeTeam(CsTeam.Terrorist);
PrintToAll($"[MoveSpec] Terrorist captain set to: {target.PlayerName}");
}
[ConsoleCommand("css_ctcapt", "Sets the Counter-Terrorist team captain")]
[CommandHelper(minArgs: 1, usage: "<player name>")]
public void OnCTCaptCommand(CCSPlayerController? player, CommandInfo command)
{
if (!IsAdmin(player)) return;
var targetName = command.GetArg(1);
var target = FindPlayerByName(targetName);
if (target == null)
{
player?.PrintToChat("[MoveSpec] Player not found!");
return;
}
_ctCaptain = target;
target.ChangeTeam(CsTeam.CounterTerrorist);
PrintToAll($"[MoveSpec] Counter-Terrorist captain set to: {target.PlayerName}");
}
private void ShowPickingMenu(CCSPlayerController? captain)
{
if (!_isPickingInProgress || _menuApi == null || captain == null || !captain.IsValid)
return;
var menu = _menuApi.GetMenu($"Pick a player for {(captain.Team == CsTeam.CounterTerrorist ? "CT" : "T")} team");
foreach (var p in _availablePlayers)
{
if (p != null && p.IsValid)
{
menu.AddMenuOption(p.PlayerName, (picker, option) => OnPlayerPicked(p, captain));
}
}
menu.Open(captain);
}
private void OnPlayerPicked(CCSPlayerController picked, CCSPlayerController captain)
{
if (!_isPickingInProgress || picked == null || !picked.IsValid)
return;
picked.ChangeTeam(captain.Team);
_availablePlayers.Remove(picked);
_pickedPlayers++;
PrintToAll($"[MoveSpec] {captain.PlayerName} picked {picked.PlayerName}");
if (_pickedPlayers >= 8)
{
_isPickingInProgress = false;
PrintToAll("[MoveSpec] Team picking is complete! Teams are now 5v5.");
return;
}
// Switch turns
_isCTTurn = !_isCTTurn;
var nextCaptain = _isCTTurn ? _ctCaptain : _tCaptain;
ShowPickingMenu(nextCaptain);
}
private CCSPlayerController? FindPlayerByName(string name)
{
return Utilities.GetPlayers().FirstOrDefault(p => p.PlayerName.Contains(name, StringComparison.OrdinalIgnoreCase));
}
private bool IsAdmin(CCSPlayerController? player)
{
if (player == null || !player.IsValid || !player.PlayerPawn.IsValid)
return false;
if (!AdminManager.PlayerHasPermissions(player, "@css/admin"))
{
player.PrintToChat("[MoveSpec] You don't have permission to use this command!");
return false;
}
return true;
}
private void PrintToAll(string message)
{
Server.PrintToChatAll($" \x04{message}");
}
}