-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathchillycomp.sp
409 lines (300 loc) · 14.6 KB
/
chillycomp.sp
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
#define PLUGIN_VERSION "1.0.7"
#define UPDATE_URL ""
#define TAG "CHILLY"
#define COLOR_TAG "{matAmber}"
#define MAX_PLAYERS 36
#define DEBUG
#define DEBUG_TAG "COMP"
// #define ALLOWBOT
//=========================================================================
// P L U G I N S V A R I A B L E S
//=========================================================================
Handle g_hcDebuggingEnable = INVALID_HANDLE; //CVar to check if debugging logs is enabled
Handle g_hcMapTime = INVALID_HANDLE; //CVar to store the map time limit
Handle g_hoHud = INVALID_HANDLE; //Handle for HUD text display
Handle g_hoAdminMenu = INVALID_HANDLE; //Handle for Custom Admin Menu
Handle g_htCheckPlayerCounter = INVALID_HANDLE; //Timer to check the player counter
Handle g_htCheckCounter = INVALID_HANDLE; //Timer to check the counter for melee mode
Handle g_htRollMessage = INVALID_HANDLE; //Timer to display the "ROLL" message
//=========================================================================
// P L A Y E R S V A R I A B L E S
//=========================================================================
int g_iPlayerCounter = 0; //Number of Players in the RED or BLU team
bool g_bRollingSequence = false; //Has the Rolling Sequence started
bool g_bPlayerPenalty[MAX_PLAYERS] = false; //Dose Player has roll Penalty
//=========================================================================s
// R O L L I N G V A R I A B L E S
//=========================================================================
int g_iMapTimeLimit = 0; //Map Time Limit from mp_timelimit
bool g_bRollingPick = false; //Has the Rolling Pick started
bool g_bCheckCounter = false; //Has the timer to Check Counter started
bool g_bAutoDisable = false; //Has the rolling disabled itself
//========================================================================
// T E A M P I C K V A R I A B L E S
//========================================================================
Handle g_hPlayerPicked = INVALID_HANDLE;
int g_iPlayerCount = 0;
int g_iBluTeamLeader = -1; //Leader of BLU Team
int g_iRedTeamLeader = -1; //Leader of RED Team
//=========================================================================
// P L U S O N E L I S T V A R I A B L E S
//=========================================================================
Handle g_hcPlusOnePlayerID = INVALID_HANDLE;
int g_iPlusOneCount = 0;
int g_iPlusOneAllowed = 0;
int g_iPlusOneBlocked = 0;
bool g_bPlusOneAllowed[MAX_PLAYERS] = false; //Is player allowed to pick
//=========================================================================
// T E A M L I M I T V A R I A B L E S
//=========================================================================
Handle g_hcTeamLimitSize = INVALID_HANDLE; //CVar for team limit size varible from TeamLimit Plugin
//=========================================================================
// P L U G I N E V E N T F U N C T I O N S S T A R T
//============================================
// PluginInfo
// Info about the plugin is stored here
//============================================
public Plugin:myinfo = {
name = "ChillyComp",
author = "PepperKick",
description = "A plugin to manage pugs",
version = PLUGIN_VERSION,
url = "https://pepperkick.com/"
}
#include <headers>
//============================================
// OnPluginStart
// Executed when the plugin starts
//============================================
public OnPluginStart() {
LoadTranslations("chillycomp.phrases");
DebugLog("Loaded Translation Files");
//Set CVars
CreateCvars();
AutoExecConfig(true, "chillycomp");
if (LibraryExists("updater"))
Updater_AddPlugin(UPDATE_URL)
//Initialize Array Handles
g_hPlayerPicked = CreateArray(4, MaxClients + 1);
g_bMarkedPlusOnePlayers = CreateArray(4, MaxClients + 1);
g_bPlayerRollStatus = CreateArray(4, MaxClients + 1);
g_bPlayerReadyStatus = CreateArray(4, MaxClients + 1);
//Attach HUD Handle
g_hoHud = HudInit(127, 255, 127);
// Add Extra Colors
AddColors();
//Set CommandListeners
AddCommandListener(Command_JoinTeam, "jointeam"); //Attach Listener to "jointeam" command
AddCommandListener(Command_JoinSpec, "spectate"); //Attach Listener to "spectate" command
// Set Console Commands
RegConsoleCmd("pick", Command_PickPlayer, "Pick player through chat during picking process");
RegConsoleCmd("p", Command_PickPlayer, "Pick player through chat during picking process");
RegConsoleCmd("list", Command_PickList, "Shows the list of rolled and plus one players during picking process");
RegConsoleCmd("ready", Command_PlayerReady, "Set status as ready for match");
RegConsoleCmd("unready", Command_PlayerUnReady, "Set status as not ready for match");
// Set Admin Commands
RegAdminCmd("startroll", Command_StartRolling, ADMFLAG_BAN, "Start rolling process");
RegAdminCmd("mark", Command_MarkPlusOne, ADMFLAG_BAN, "Mark a player as plus one");
RegAdminCmd("restartpicking", Command_RestartPicking, ADMFLAG_BAN, "Restart the picking stage of rolling");
RegAdminCmd("rspicking", Command_RestartPicking, ADMFLAG_BAN, "Restart the picking stage of rolling");
RegAdminCmd("changecaptainred", Command_SwapCaptainRed, ADMFLAG_BAN, "Change RED team captain");
RegAdminCmd("changecapred", Command_SwapCaptainRed, ADMFLAG_BAN, "Change RED team captain");
RegAdminCmd("chgcapred", Command_SwapCaptainRed, ADMFLAG_BAN, "Change RED team captain");
RegAdminCmd("ccr", Command_SwapCaptainRed, ADMFLAG_BAN, "Change RED team captain");
RegAdminCmd("changecaptainblu", Command_SwapCaptainBlu, ADMFLAG_BAN, "Change BLU team captain");
RegAdminCmd("changecapblu", Command_SwapCaptainBlu, ADMFLAG_BAN, "Change BLU team captain");
RegAdminCmd("chgcapblu", Command_SwapCaptainBlu, ADMFLAG_BAN, "Change BLU team captain");
RegAdminCmd("ccb", Command_SwapCaptainBlu, ADMFLAG_BAN, "Change BLU team captain");
RegAdminCmd("changeroll", Command_ChangeRollStatus, ADMFLAG_BAN, "Change the roll status for a player");
//Match Function
Match_OnPluginStart();
//Reset Plugin
PluginReset();
// Attach cvar change hooks
HookConVarChange(g_hcRollMode, Handle_RollModeChange);
HookConVarChange(g_hcGameStatus, Hande_GameStatusChanged);
HookEvent("server_cvar", Event_ServerCvar, EventHookMode_Pre);
HookEvent("tournament_stateupdate", Event_TournamentStateUpdate, EventHookMode_Pre);
HookEvent("teamplay_round_start", Event_RoundStart);
AddCommandListener(OnSayCommand, "say");
AddCommandListener(OnSayCommand, "say2");
AddCommandListener(OnSayCommand, "say_team");
DebugLog("Loaded ChillyComp plugin, Version %s", PLUGIN_VERSION);
}
// P L U G I N E V E N T F U N C T I O N S E N D
//=========================================================================
//=========================================================================
// E V E N T F U N C T I O N S S T A R T
//============================================
// OnClientDisconnect
// Executed when a client disconnets
//============================================
public OnClientDisconnect(client) {
if(GetStatus() > STATE_INITIAL && GetStatus() < STATE_SETUP && (client == g_iBluTeamLeader || client == g_iRedTeamLeader)) {
// If a team leader leaves while picking is going on
new String:hudmsg[128];
Format(hudmsg, sizeof(hudmsg), "%T", "Rolling-Canceled-HUD", LANG_SERVER);
HudSetColor(255, 152, 0);
HudSetText(hudmsg);
CPrintToChatAll("%s[%s] %t", COLOR_TAG, TAG, "Rolling-Canceled-MSG-LeaderLeft");
RollingReset(); //Reset Rolling
return;
} else if(GetStatus() > STATE_INITIAL && GetStatus() < STATE_SETUP && RollingCheckPlayer(client) && CountPlayersInAnyTeam() < (GetConVarInt(g_hcTeamSize) * 2)) {
// If a player leaves while either rolling sequence or team picking is going on and there are not enough players
new String:hudmsg[128];
Format(hudmsg, sizeof(hudmsg), "%T", "Rolling-Canceled-HUD", LANG_SERVER);
HudSetColor(255, 152, 0);
HudSetText(hudmsg);
CPrintToChatAll("%s[%s] %t", COLOR_TAG, TAG, "Rolling-Canceled-MSG-PlayerLeft");
RollingReset(); //Reset Rolling
return;
}
}
//============================================
// OnAllPluginsLoaded
// Executed when all plugins loaded
//============================================
public OnAllPluginsLoaded() {
DebugLog("Plugins Loaded");
if (FindConVar("sm_teamlimit_version") != INVALID_HANDLE) {
g_hcTeamLimitSize = FindConVar("sm_teamlimit");
}
}
//============================================
// OnMapStart
// Executed when a map starts
//============================================
public OnMapStart() {
Match_OnMapStart();
SetStatus(STATE_INITIAL);
DebugLog("Map Started");
}
//============================================
// OnMapEnd
// Executed when a map ends
//============================================
public void OnMapEnd() {
DebugLog("Map Ended");
Match_OnMapEnd();
if (GetConVarInt(g_hcEnabled) == 0) return;
RollingReset();
}
//============================================
// StartMatch
// Executed when a match starts
//============================================
StartMatch() {
DebugLog("Match Started");
// SetPlusOneList();
}
//============================================
// ResetMatch
// Executed when a match resets
//============================================
ResetMatch() {
DebugLog("Match Reset");
if (GetConVarInt(g_hcEnabled) == 0) return;
PluginReset();
}
//============================================
// EndMatch
// Executed when a match ends
// Parameters
// bool Did the match end midgame
//============================================
EndMatch(bool:endedMidgame) {
DebugLog("Match Ended, Ended MidGame: %d", endedMidgame);
SetStatus(STATE_POST);
if (GetConVarInt(g_hcEnabled) == 0) return;
CreateTimer(GetConVarInt(g_hcPostMatchCoolDownTime) * 1.0, Timer_PostMatchCoolDown);
}
PluginReset() {
ClearPlusOne();
ClearRollStatus();
ClearReadyStatus();
RollingReset();
}
public Action:Command_JoinTeam(client, const String:command[], argc) {
char team[128];
GetCmdArg(1, team, sizeof(team));
if (GetStatus() > STATE_INITIAL && GetStatus() < STATE_SETUP) {
return RollingConditions(client, team);
} else if (GetStatus() > STATE_LIVE && GetStatus() < STATE_POST) {
return TeamLimitConditions(client, team);
}
return Plugin_Continue;
}
public void Event_RoundStart(Event event, const char[] name, bool dontBroadcast) {
if (GetConVarInt(g_hcEnabled) == 0) return;
if (GetConVarInt(g_hcTournamentModeCvar) == 0) return;
if (GetStatus() != STATE_SETUP) return;
if (!g_bWarmupRestartChecked) {
CheckWarmupRestart();
}
if (g_bWarmupRestartRequired && g_bWarmupRestartCounter > 0) {
DoWarmupRestart();
} else {
ResetWarmupResatrt();
SetStatus(STATE_LIVE);
}
return;
}
public void Hande_GameStatusChanged(ConVar convar, const char[] oldValue, const char[] newValue) {
int value = StringToInt(newValue);
CheckStatusChange(value);
}
public Action:OnSayCommand(client, const String:command[], argc) {
decl String:text[192];
GetCmdArgString(text, sizeof(text));
if (FilterColorChat(client, text)) {
CPrintToChat(client, "%s[%s] %t", COLOR_TAG, TAG, "Module-ChatControl-ColorChatBlocked");
return Plugin_Handled;
}
return Plugin_Continue;
}
public Action:Timer_PostMatchCoolDown(Handle timer) {
if (GetStatus() == STATE_POST) {
RollingReset();
}
return Plugin_Stop;
}
// E V E N T F U N C T I O N S E N D
//=========================================================================
//=========================================================================
// R O L L I N G F U N C T I O N S S T A R T
//============================================
// SetStatus
// Sets the status of the game
// Parameters
// int Status of the game
//============================================
public void SetStatus(int status) {
DebugLog("Setting status to %s", status);
SetConVarInt(g_hcGameStatus, status, false, false);
}
//============================================
// GetStatus
// Returns the status of the game
// Returns int
//============================================
public int GetStatus() {
return GetConVarInt(g_hcGameStatus);
}
// R O L L I N G F U N C T I O N S E N D
//=========================================================================
//=========================================================================
// U P D A T E R F U N C T I O N S S T A R T
public OnLibraryAdded(const String:name[]) {
if (StrEqual(name, "updater"))
Updater_AddPlugin(UPDATE_URL)
}
// U P D A T E R F U N C T I O N S E N D
//=========================================================================
public DebugLog(const char[] myString, any ...) {
#if defined DEBUG
int len = strlen(myString) + 255;
char[] myFormattedString = new char[len];
VFormat(myFormattedString, len, myString, 2);
PrintToServer("[%s] %s", DEBUG_TAG, myFormattedString);
#endif
}