-
-
Notifications
You must be signed in to change notification settings - Fork 466
Expand file tree
/
Copy pathbasechat.sp
More file actions
469 lines (371 loc) · 12.5 KB
/
basechat.sp
File metadata and controls
469 lines (371 loc) · 12.5 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
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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
/**
* vim: set ts=4 :
* =============================================================================
* SourceMod Basic Chat Plugin
* Implements basic communication commands.
*
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>.
*
* Version: $Id$
*/
#pragma semicolon 1
#include <sourcemod>
#pragma newdecls required
public Plugin myinfo =
{
name = "Basic Chat",
author = "AlliedModders LLC",
description = "Basic Communication Commands",
version = SOURCEMOD_VERSION,
url = "http://www.sourcemod.net/"
};
#define CHAT_SYMBOL '@'
char g_ColorNames[13][10] = {"White", "Red", "Green", "Blue", "Yellow", "Purple", "Cyan", "Orange", "Pink", "Olive", "Lime", "Violet", "Lightblue"};
int g_Colors[13][3] = {{255,255,255},{255,0,0},{0,255,0},{0,0,255},{255,255,0},{255,0,255},{0,255,255},{255,128,0},{255,0,128},{128,255,0},{0,255,128},{128,0,255},{0,128,255}};
ConVar g_Cvar_Chatmode;
EngineVersion g_GameEngine = Engine_Unknown;
public void OnPluginStart()
{
LoadTranslations("common.phrases");
g_GameEngine = GetEngineVersion();
g_Cvar_Chatmode = CreateConVar("sm_chat_mode", "1", "Allows player's to send messages to admin chat.", 0, true, 0.0, true, 1.0);
RegAdminCmd("sm_say", Command_SmSay, ADMFLAG_CHAT, "sm_say <message> - sends message to all players");
RegAdminCmd("sm_csay", Command_SmCsay, ADMFLAG_CHAT, "sm_csay <message> - sends centered message to all players");
/* HintText does not work on Dark Messiah */
if (g_GameEngine != Engine_DarkMessiah)
{
RegAdminCmd("sm_hsay", Command_SmHsay, ADMFLAG_CHAT, "sm_hsay <message> - sends hint message to all players");
}
RegAdminCmd("sm_dsay", Command_SmDsay, ADMFLAG_CHAT, "sm_dsay <message> - sends hud message to all players");
RegAdminCmd("sm_tsay", Command_SmTsay, ADMFLAG_CHAT, "sm_tsay [color] <message> - sends top-left message to all players");
RegAdminCmd("sm_chat", Command_SmChat, ADMFLAG_CHAT, "sm_chat <message> - sends message to admins");
RegAdminCmd("sm_psay", Command_SmPsay, ADMFLAG_CHAT, "sm_psay <name or #userid> <message> - sends private message");
RegAdminCmd("sm_msay", Command_SmMsay, ADMFLAG_CHAT, "sm_msay <message> - sends message as a menu panel");
}
public Action OnClientSayCommand(int client, const char[] command, const char[] sArgs)
{
int startidx;
if (sArgs[startidx] != CHAT_SYMBOL)
return Plugin_Continue;
startidx++;
if (strcmp(command, "say", false) == 0)
{
if (sArgs[startidx] != CHAT_SYMBOL) // sm_say alias
{
if (!CheckCommandAccess(client, "sm_say", ADMFLAG_CHAT))
{
return Plugin_Continue;
}
SendChatToAll(client, sArgs[startidx]);
LogAction(client, -1, "\"%L\" triggered sm_say (text %s)", client, sArgs[startidx]);
return Plugin_Stop;
}
startidx++;
if (sArgs[startidx] != CHAT_SYMBOL) // sm_psay alias
{
if (!CheckCommandAccess(client, "sm_psay", ADMFLAG_CHAT))
{
return Plugin_Continue;
}
char arg[64];
int len = BreakString(sArgs[startidx], arg, sizeof(arg));
int target = FindTarget(client, arg, true, false);
if (target == -1 || len == -1)
return Plugin_Stop;
SendPrivateChat(client, target, sArgs[startidx+len]);
return Plugin_Stop;
}
startidx++;
// sm_csay alias
if (!CheckCommandAccess(client, "sm_csay", ADMFLAG_CHAT))
{
return Plugin_Continue;
}
DisplayCenterTextToAll(client, sArgs[startidx]);
LogAction(client, -1, "\"%L\" triggered sm_csay (text %s)", client, sArgs[startidx]);
return Plugin_Stop;
}
else if (strcmp(command, "say_team", false) == 0 || strcmp(command, "say_squad", false) == 0)
{
if (!CheckCommandAccess(client, "sm_chat", ADMFLAG_CHAT) && !g_Cvar_Chatmode.BoolValue)
{
return Plugin_Continue;
}
SendChatToAdmins(client, sArgs[startidx]);
LogAction(client, -1, "\"%L\" triggered sm_chat (text %s)", client, sArgs[startidx]);
return Plugin_Stop;
}
return Plugin_Continue;
}
public Action Command_SmSay(int client, int args)
{
if (args < 1)
{
ReplyToCommand(client, "[SM] Usage: sm_say <message>");
return Plugin_Handled;
}
char text[192];
GetCmdArgString(text, sizeof(text));
SendChatToAll(client, text);
LogAction(client, -1, "\"%L\" triggered sm_say (text %s)", client, text);
return Plugin_Handled;
}
public Action Command_SmCsay(int client, int args)
{
if (args < 1)
{
ReplyToCommand(client, "[SM] Usage: sm_csay <message>");
return Plugin_Handled;
}
char text[192];
GetCmdArgString(text, sizeof(text));
DisplayCenterTextToAll(client, text);
LogAction(client, -1, "\"%L\" triggered sm_csay (text %s)", client, text);
return Plugin_Handled;
}
public Action Command_SmHsay(int client, int args)
{
if (args < 1)
{
ReplyToCommand(client, "[SM] Usage: sm_hsay <message>");
return Plugin_Handled;
}
char text[192];
GetCmdArgString(text, sizeof(text));
char nameBuf[MAX_NAME_LENGTH];
for (int i = 1; i <= MaxClients; i++)
{
if (!IsClientInGame(i) || IsFakeClient(i))
{
continue;
}
FormatActivitySource(client, i, nameBuf, sizeof(nameBuf));
PrintHintText(i, "%s: %s", nameBuf, text);
}
LogAction(client, -1, "\"%L\" triggered sm_hsay (text %s)", client, text);
return Plugin_Handled;
}
public Action Command_SmDsay(int client, int args)
{
if (args < 1)
{
ReplyToCommand(client, "[SM] Usage: sm_dsay <message>");
return Plugin_Handled;
}
char text[192];
GetCmdArgString(text, sizeof(text));
char nameBuf[MAX_NAME_LENGTH];
SetHudTextParams(-1.0, 0.25, 3.0, 0, 255, 127, 255, 1);
for (int i = 1; i <= MaxClients; i++)
{
if (!IsClientInGame(i) || IsFakeClient(i))
{
continue;
}
FormatActivitySource(client, i, nameBuf, sizeof(nameBuf));
ShowHudText(i, -1, "%s: %s", nameBuf, text);
}
LogAction(client, -1, "\"%L\" triggered sm_dsay (text %s)", client, text);
return Plugin_Handled;
}
public Action Command_SmTsay(int client, int args)
{
if (args < 1)
{
ReplyToCommand(client, "[SM] Usage: sm_tsay <message>");
return Plugin_Handled;
}
char text[192], colorStr[16];
GetCmdArgString(text, sizeof(text));
int len = BreakString(text, colorStr, 16);
int color = FindColor(colorStr);
char nameBuf[MAX_NAME_LENGTH];
if (color == -1)
{
color = 0;
len = 0;
}
for (int i = 1; i <= MaxClients; i++)
{
if (!IsClientInGame(i) || IsFakeClient(i))
{
continue;
}
FormatActivitySource(client, i, nameBuf, sizeof(nameBuf));
SendDialogToOne(i, color, "%s: %s", nameBuf, text[len]);
}
LogAction(client, -1, "\"%L\" triggered sm_tsay (text %s)", client, text);
return Plugin_Handled;
}
public Action Command_SmChat(int client, int args)
{
if (args < 1)
{
ReplyToCommand(client, "[SM] Usage: sm_chat <message>");
return Plugin_Handled;
}
char text[192];
GetCmdArgString(text, sizeof(text));
SendChatToAdmins(client, text);
LogAction(client, -1, "\"%L\" triggered sm_chat (text %s)", client, text);
return Plugin_Handled;
}
public Action Command_SmPsay(int client, int args)
{
if (args < 2)
{
ReplyToCommand(client, "[SM] Usage: sm_psay <name or #userid> <message>");
return Plugin_Handled;
}
char text[192], arg[64];
GetCmdArgString(text, sizeof(text));
int len = BreakString(text, arg, sizeof(arg));
int target = FindTarget(client, arg, true, false);
if (target == -1)
return Plugin_Handled;
SendPrivateChat(client, target, text[len]);
return Plugin_Handled;
}
public Action Command_SmMsay(int client, int args)
{
if (args < 1)
{
ReplyToCommand(client, "[SM] Usage: sm_msay <message>");
return Plugin_Handled;
}
char text[192];
GetCmdArgString(text, sizeof(text));
SendPanelToAll(client, text);
LogAction(client, -1, "\"%L\" triggered sm_msay (text %s)", client, text);
return Plugin_Handled;
}
int FindColor(const char[] color)
{
for (int i = 0; i < sizeof(g_ColorNames); i++)
{
if (strcmp(color, g_ColorNames[i], false) == 0)
return i;
}
return -1;
}
void SendChatToAll(int client, const char[] message)
{
char nameBuf[MAX_NAME_LENGTH];
for (int i = 1; i <= MaxClients; i++)
{
if (!IsClientInGame(i) || IsFakeClient(i))
{
continue;
}
FormatActivitySource(client, i, nameBuf, sizeof(nameBuf));
if (g_GameEngine == Engine_CSGO)
PrintToChat(i, " \x01\x0B\x04%t: \x01%s", "Say all", nameBuf, message);
else
PrintToChat(i, "\x04%t: \x01%s", "Say all", nameBuf, message);
}
}
void DisplayCenterTextToAll(int client, const char[] message)
{
char nameBuf[MAX_NAME_LENGTH];
for (int i = 1; i <= MaxClients; i++)
{
if (!IsClientInGame(i) || IsFakeClient(i))
{
continue;
}
FormatActivitySource(client, i, nameBuf, sizeof(nameBuf));
PrintCenterText(i, "%s: %s", nameBuf, message);
}
}
void SendChatToAdmins(int from, const char[] message)
{
int fromAdmin = CheckCommandAccess(from, "sm_chat", ADMFLAG_CHAT);
for (int i = 1; i <= MaxClients; i++)
{
if (IsClientInGame(i) && (from == i || CheckCommandAccess(i, "sm_chat", ADMFLAG_CHAT)))
{
if (g_GameEngine == Engine_CSGO)
PrintToChat(i, " \x01\x0B\x04%t: \x01%s", fromAdmin ? "Chat admins" : "Chat to admins", from, message);
else
PrintToChat(i, "\x04%t: \x01%s", fromAdmin ? "Chat admins" : "Chat to admins", from, message);
}
}
}
void SendDialogToOne(int client, int color, const char[] text, any ...)
{
char message[100];
VFormat(message, sizeof(message), text, 4);
KeyValues kv = new KeyValues("Stuff", "title", message);
kv.SetColor("color", g_Colors[color][0], g_Colors[color][1], g_Colors[color][2], 255);
kv.SetNum("level", 1);
kv.SetNum("time", 10);
CreateDialog(client, kv, DialogType_Msg);
delete kv;
}
void SendPrivateChat(int client, int target, const char[] message)
{
if (!client)
{
PrintToServer("(Private to %N) %N: %s", target, client, message);
}
else if (target != client)
{
if (g_GameEngine == Engine_CSGO)
PrintToChat(client, " \x01\x0B\x04%t: \x01%s", "Private say to", target, client, message);
else
PrintToChat(client, "\x04%t: \x01%s", "Private say to", target, client, message);
}
if (g_GameEngine == Engine_CSGO)
PrintToChat(target, " \x01\x0B\x04%t: \x01%s", "Private say to", target, client, message);
else
PrintToChat(target, "\x04%t: \x01%s", "Private say to", target, client, message);
LogAction(client, target, "\"%L\" triggered sm_psay to \"%L\" (text %s)", client, target, message);
}
void SendPanelToAll(int from, char[] message)
{
char title[100];
Format(title, 64, "%N:", from);
ReplaceString(message, 192, "\\n", "\n");
Panel mSayPanel = new Panel();
mSayPanel.SetTitle(title);
mSayPanel.DrawItem("", ITEMDRAW_SPACER);
mSayPanel.DrawText(message);
mSayPanel.DrawItem("", ITEMDRAW_SPACER);
mSayPanel.CurrentKey = GetMaxPageItems(mSayPanel.Style);
mSayPanel.DrawItem("Exit", ITEMDRAW_CONTROL);
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i) && !IsFakeClient(i))
{
mSayPanel.Send(i, Handler_DoNothing, 10);
}
}
delete mSayPanel;
}
public int Handler_DoNothing(Menu menu, MenuAction action, int param1, int param2)
{
/* Do nothing */
return 0;
}