-
Notifications
You must be signed in to change notification settings - Fork 1
/
roundinfo.sp
222 lines (196 loc) · 6.53 KB
/
roundinfo.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
#include <sourcemod>
#include <sdktools>
#include <morecolors>
/*
* Plugin Info
*/
public Plugin myinfo = {
name = "RoundInfo",
description = "Displays round info similarly to CompCtrl on PugChamp",
author = "Squidamtron",
version = "6.9",
url = "https://something.com"
}
//Constants for identifying teams
const int BLU_ID = 3;
const int RED_ID = 2;
//Variables for game info
ConVar g_RedTeamName;
ConVar g_BlueTeamName;
ConVar g_Tournament;
ConVar g_TimeLimit;
ConVar g_BracketText;
ConVar g_BracketColor;
ConVar g_MiscColor;
ConVar g_TextEnable;
bool roundLive = false;
int currentRound = 0;
bool gameOver = false;
int endTime = 0;
/* OnPluginStart()
*
* Called when plugin is loaded
* Sets up literally whatever
* PSST START HERE FOR MOST THINGS
*
*/
public void OnPluginStart() {
//yeet
g_RedTeamName = FindConVar("mp_tournament_redteamname");
g_BlueTeamName = FindConVar("mp_tournament_blueteamname");
g_Tournament = FindConVar("mp_tournament");
g_TimeLimit = FindConVar("mp_timelimit");
g_BracketText = CreateConVar("sm_roundinfo_btext", "Round Info", "Overrides the plugin name in the bracketed text.");
g_BracketColor = CreateConVar("sm_roundinfo_bcolor", "green", "Changes the color of the bracketed text.");
g_MiscColor = CreateConVar("sm_roundinfo_mcolor", "olive", "Changes the color of scores, timeleft, and round number.");
g_TextEnable = CreateConVar("sm_roundinfo_enable", "1", "Enables/Disables the text output.", FCVAR_NONE, true, 0.0, true, 1.0);
RegAdminCmd("sm_roundinfo_test", Test_Output, ADMFLAG_GENERIC, "Tests the output of the plugin to test colors, etc.");
RegAdminCmd("sm_roundinfo_rc", Console_Output, ADMFLAG_GENERIC, "Prints round info in the console; for use with rcon.");
HookEvent("teamplay_round_start", Event_RoundStart);
HookEvent("teamplay_game_over", Event_GameOver);
HookEvent("tf_game_over", Event_GameOver);
}
/* Event_RoundStart()
*
* Called when round starts
* Displays text about score, timeleft and round number
*
*/
public void Event_RoundStart(Event event, const char[] name, bool dontBroadcast) {
//yeet
//Get team ready status
new redReady = GameRules_GetProp("m_bTeamReady", 1, RED_ID);
new bluReady = GameRules_GetProp("m_bTeamReady", 1, BLU_ID);
//Check if both teams are ready AND tournament mode is active
//before putting any text into chat
if (bluReady && redReady && g_Tournament) {
roundLive = true;
currentRound = 0;
//Set gameOver to false incase another game started on the same map
gameOver = false;
}
//TODO Modularize most of the text? (More cvars?)
if (roundLive == true) {
//inner yeet
//Get Team Names
char redName[256];
g_RedTeamName.GetString(redName, sizeof(redName));
char bluName[256];
g_BlueTeamName.GetString(bluName, sizeof(bluName));
//Get cvar values
char btext[128];
g_BracketText.GetString(btext, sizeof(btext));
char bcolor[128];
g_BracketColor.GetString(bcolor, sizeof(bcolor));
char mcolor[128];
g_MiscColor.GetString(mcolor, sizeof(mcolor));
currentRound++;
if(g_TextEnable.IntValue == 1) {
//Print Round Info
CPrintToChatAll("{%s}[%s]{default} Current score: {blue}%s{default} {%s}%i{default}, {red}%s{default} {%s}%i{default}.", bcolor, btext, bluName, mcolor, GetTeamScore(BLU_ID), redName, mcolor, GetTeamScore(RED_ID));
//Print Timeleft and Round number IF NOT KOTH
//TODO Current Round visible if KOTH?
int timeleft = RoundToFloor(GetTimeLeft());
if (g_TimeLimit.IntValue != 0) {
//double inner yeet
CPrintToChatAll("{%s}[%s]{default} {%s}%i:%02i{default} remaining; starting round {%s}%i{default}.", bcolor, btext, mcolor, timeleft / 60, timeleft % 60, mcolor, currentRound);
}
}
}
}
/* Event_GameOver()
*
* Called when the game ends (timelimit/score)
* Sets up variables for console use
*
*/
public void Event_GameOver(Event event, const char[] name, bool dontBroadcast) {
//yeet
//Literally
gameOver = true;
roundLive = false;
endTime = RoundToFloor(GetTimeLeft());
//TODO Add end of game summary?
}
/* OnMapStart()
*
* Called when map starts
* Resets roundLive and currentRound
* Stops from displaying RoundInfo text on map change
*
*/
public void OnMapStart() {
//yeet
roundLive = false;
currentRound = 0;
gameOver = false;
}
/* Test_Output()
*
* Called when `sm_roundinfo_test` is run in console
* Outputs dummy info to test visuals
*
*/
public Action Test_Output(int client, int args) {
//yeeet
if(roundLive) {
//inneryeet
CPrintToChat(client, "Round is live! Should you really be doing this right now?");
return Plugin_Handled;
}
//Get cvar values
char btext[128];
g_BracketText.GetString(btext, sizeof(btext));
char bcolor[128];
g_BracketColor.GetString(bcolor, sizeof(bcolor));
char mcolor[128];
g_MiscColor.GetString(mcolor, sizeof(mcolor));
CPrintToChat(client, "{%s}[%s]{default} Current score: {blue}BLU{default} {%s}4{default}, {red}RED{default} {%s}3{default}.", bcolor, btext, mcolor, mcolor);
CPrintToChat(client, "{%s}[%s]{default} {%s}13:37{default} remaining; starting round {%s}8{default}.", bcolor, btext, mcolor, mcolor);
return Plugin_Handled;
}
/* Console_Output()
*
* Called when `sm_roundinfo_rc` is run in console
* Puts score and timeleft in console for rcon and
* can tell if the game ended
*
*/
public Action Console_Output(int client, int args) {
//yeet
if(roundLive == true && gameOver == false) {
//inneryeet
int timeleft = RoundToFloor(GetTimeLeft());
PrintToConsole(client, "BLU: %i", GetTeamScore(BLU_ID));
PrintToConsole(client, "RED: %i", GetTeamScore(RED_ID));
PrintToConsole(client, "Time: %i:%02i", timeleft / 60, timeleft % 60);
return Plugin_Handled;
}
else if(roundLive == false && gameOver == true) {
//inneryeet
PrintToConsole(client, "Game ended! With a time of %i:%02i remaining, the scores were:", endTime / 60, endTime % 60);
PrintToConsole(client, "BLU: %i", GetTeamScore(BLU_ID));
PrintToConsole(client, "RED: %i", GetTeamScore(RED_ID));
return Plugin_Handled;
}
else if(roundLive == false && gameOver == false) {
PrintToConsole(client, "Game hasn't started yet.");
return Plugin_Handled;
}
//STOP YELLING AT ME, SPCOMP!
PrintToConsole(client, "If you're seeing THIS message, something has gone horribly wrong.");
return Plugin_Handled;
}
/* GetTimeLeft()
*
* Gets accurate round time remaining
* Shamelessly borrowed from tsc and CompCtrl
* Does not like `mp_timelimit 0`
*
*/
float GetTimeLeft() {
float startTime = GameRules_GetPropFloat("m_flMapResetTime");
float timeLimit = float(g_TimeLimit.IntValue * 60);
float currentTime = GetGameTime();
return (startTime + timeLimit) - currentTime;
}