-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathwarden.sp
More file actions
295 lines (258 loc) · 7.95 KB
/
warden.sp
File metadata and controls
295 lines (258 loc) · 7.95 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
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
#include <sourcemod>
#include <sdktools>
#define PLUGIN_VERSION "3.0.2"
#pragma semicolon 1
#pragma newdecls required
int Warden = -1;
ConVar g_cVar_mnotes = null, g_cvar_remove_death = null, g_cvar_remove_startround = null;
Handle g_fward_onBecome = null, g_fward_onRemoved = null, g_fward_onDeath = null, g_fward_onRemove = null;
public Plugin myinfo =
{
name = "Jailbreak Warden",
author = "ecca, ByDexter",
description = "Jailbreak Warden script",
version = PLUGIN_VERSION,
url = "ffac.eu"
};
public void OnPluginStart()
{
// Initialize our phrases
LoadTranslations("warden.phrases");
// Register our public commands
RegConsoleCmd("sm_w", BecomeWarden);
RegConsoleCmd("sm_warden", BecomeWarden);
RegConsoleCmd("sm_uw", ExitWarden);
RegConsoleCmd("sm_unwarden", ExitWarden);
RegConsoleCmd("sm_c", BecomeWarden);
RegConsoleCmd("sm_commander", BecomeWarden);
RegConsoleCmd("sm_uc", ExitWarden);
RegConsoleCmd("sm_uncommander", ExitWarden);
// Register our admin commands
RegAdminCmd("sm_rw", RemoveWarden, ADMFLAG_GENERIC);
RegAdminCmd("sm_rc", RemoveWarden, ADMFLAG_GENERIC);
// For our warden to look some extra cool
AddCommandListener(HookPlayerChat, "say");
// Hook
HookEvent("round_start", RoundStart);
HookEvent("player_death", OnClientDead);
// May not touch this line
CreateConVar("sm_warden_version", PLUGIN_VERSION, "The version of the SourceMod plugin JailBreak Warden, by ecca", FCVAR_REPLICATED | FCVAR_SPONLY | FCVAR_NOTIFY | FCVAR_DONTRECORD);
g_cVar_mnotes = CreateConVar("sm_better_warden_message", "0", "0 - Off, 1 - Center and Hint Text", FCVAR_NOTIFY, true, 0.0, true, 1.0);
g_cvar_remove_death = CreateConVar("sm_warden_death_remove", "1", "0 - Off, 1 - On", FCVAR_NOTIFY, true, 0.0, true, 1.0);
g_cvar_remove_startround = CreateConVar("sm_warden_roundstart_remove", "1", "0 - Off, 1 - On", FCVAR_NOTIFY, true, 0.0, true, 1.0);
g_fward_onBecome = CreateGlobalForward("warden_OnWardenCreated", ET_Ignore, Param_Cell);
g_fward_onRemoved = CreateGlobalForward("warden_OnWardenRemoved", ET_Ignore, Param_Cell);
g_fward_onRemove = CreateGlobalForward("warden_OnWardenRemove", ET_Ignore, Param_Cell);
g_fward_onDeath = CreateGlobalForward("wardeN_OnWardenDeath", ET_Ignore, Param_Cell);
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
CreateNative("warden_exist", Native_ExistWarden);
CreateNative("warden_iswarden", Native_IsWarden);
CreateNative("warden_set", Native_SetWarden);
CreateNative("warden_remove", Native_RemoveWarden);
RegPluginLibrary("warden");
return APLRes_Success;
}
public Action BecomeWarden(int client, int args)
{
if (Warden == -1) // There is no warden , so lets proceed
{
if (GetClientTeam(client) == 3) // The requested player is on the Counter-Terrorist side
{
if (IsPlayerAlive(client)) // A dead warden would be worthless >_<
{
SetTheWarden(client);
return Plugin_Handled;
}
else // Grr he is not alive -.-
{
PrintToChat(client, "[SM] %t", "warden_playerdead");
return Plugin_Handled;
}
}
else // Would be wierd if an terrorist would run the prison wouldn't it :p
{
PrintToChat(client, "[SM] %t", "warden_ctsonly");
return Plugin_Handled;
}
}
else // The warden already exist so there is no point setting a new one
{
PrintToChat(client, "[SM] %t", "warden_exist", Warden);
return Plugin_Handled;
}
}
public Action ExitWarden(int client, int args)
{
if (client == Warden) // The client is actually the current warden so lets proceed
{
PrintToChatAll("[SM] %t", "warden_retire", client);
if (g_cVar_mnotes.BoolValue)
{
PrintCenterTextAll("%t", "warden_retire", client);
PrintHintTextToAll("%t", "warden_retire", client);
}
Warden = -1; // Open for a new warden
Forward_OnWardenRemove(client);
SetEntityRenderColor(client, 255, 255, 255, 255); // Lets remove the awesome color
return Plugin_Handled;
}
else // Fake dude!
{
PrintToChat(client, "[SM] %t", "warden_notwarden");
return Plugin_Handled;
}
}
public void OnClientDisconnect(int client)
{
if (client == Warden) // The warden disconnected, action!
{
PrintToChatAll("[SM] %t", "warden_disconnected");
if (g_cVar_mnotes.BoolValue)
{
PrintCenterTextAll("%t", "warden_disconnected", client);
PrintHintTextToAll("%t", "warden_disconnected", client);
}
Warden = -1; // Lets open for a new warden
Forward_OnWardenRemoved(client);
}
}
public Action RemoveWarden(int client, int args)
{
if (Warden != -1) // Is there an warden at the moment ?
{
RemoveTheWarden(client);
return Plugin_Handled;
}
else
{
PrintToChatAll("[SM] %t", "warden_noexist");
return Plugin_Handled;
}
}
public Action RoundStart(Event event, const char[] name, bool dontBroadcast)
{
if (g_cvar_remove_startround.BoolValue && Warden != -1)
Warden = -1;
}
public Action OnClientDead(Event event, const char[] name, bool dontBroadcast)
{
if (Warden != -1)
{
int client = GetClientOfUserId(event.GetInt("userid"));
if (client == Warden)
{
Forward_OnWardenDeath(client);
if (g_cvar_remove_death.BoolValue)
{
Warden = -1;
PrintToChatAll("[SM] %t", "warden_dead");
if (g_cVar_mnotes.BoolValue)
{
PrintCenterTextAll("%t", "warden_dead");
PrintHintTextToAll("%t", "warden_dead");
}
}
}
}
}
public Action HookPlayerChat(int client, const char[] command, int argc)
{
if (Warden == client && client != 0) // Check so the player typing is warden and also checking so the client isn't console!
{
char szText[256];
GetCmdArg(1, szText, sizeof(szText));
if (IsPlayerAlive(client)) // Typing warden is alive and his team is Counter-Terrorist
{
PrintToChatAll(" \x0B[Warden] \x10%N : \x04%s", client, szText);
return Plugin_Handled;
}
else
{
PrintToChatAll(" \x02*DEAD* \x0B[Warden] \x10%N : \x04%s", client, szText);
return Plugin_Handled;
}
}
return Plugin_Continue;
}
void SetTheWarden(int client)
{
PrintToChatAll("[SM] %t", "warden_new", client);
if (g_cVar_mnotes.BoolValue)
{
PrintCenterTextAll("%t", "warden_new", client);
PrintHintTextToAll("%t", "warden_new", client);
}
Warden = client;
SetEntityRenderColor(client, 0, 175, 255, 255);
SetClientListeningFlags(client, VOICE_NORMAL);
Forward_OnWardenCreation(client);
}
void RemoveTheWarden(int client)
{
PrintToChatAll("[SM] %t", "warden_removed", client, Warden);
if (g_cVar_mnotes.BoolValue)
{
PrintCenterTextAll("%t", "warden_removed", client);
PrintHintTextToAll("%t", "warden_removed", client);
}
SetEntityRenderColor(Warden, 255, 255, 255, 255);
Warden = -1;
Forward_OnWardenRemoved(client);
}
public int Native_ExistWarden(Handle plugin, int numParams)
{
if (Warden != -1)
return true;
return false;
}
public int Native_IsWarden(Handle plugin, int numParams)
{
int client = GetNativeCell(1);
if (!IsClientInGame(client) && !IsClientConnected(client))
ThrowNativeError(SP_ERROR_INDEX, "Client index %i is invalid", client);
if (client == Warden)
return true;
return false;
}
public int Native_SetWarden(Handle plugin, int numParams)
{
int client = GetNativeCell(1);
if (!IsClientInGame(client) && !IsClientConnected(client))
ThrowNativeError(SP_ERROR_INDEX, "Client index %i is invalid", client);
if (Warden == -1)
SetTheWarden(client);
}
public int Native_RemoveWarden(Handle plugin, int numParams)
{
int client = GetNativeCell(1);
if (!IsClientInGame(client) && !IsClientConnected(client))
ThrowNativeError(SP_ERROR_INDEX, "Client index %i is invalid", client);
if (client == Warden)
RemoveTheWarden(client);
}
public void Forward_OnWardenCreation(int client)
{
Call_StartForward(g_fward_onBecome);
Call_PushCell(client);
Call_Finish();
}
public void Forward_OnWardenDeath(int client)
{
Call_StartForward(g_fward_onDeath);
Call_PushCell(client);
Call_Finish();
}
public void Forward_OnWardenRemoved(int client)
{
Call_StartForward(g_fward_onRemoved);
Call_PushCell(client);
Call_Finish();
}
public void Forward_OnWardenRemove(int client)
{
Call_StartForward(g_fward_onRemove);
Call_PushCell(client);
Call_Finish();
}