3 * =============================================================================
4 * SourceMod Basic Chat Plugin
5 * Implements basic communication commands.
7 * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
8 * =============================================================================
10 * This program is free software; you can redistribute it and/or modify it under
11 * the terms of the GNU General Public License, version 3.0, as published by the
12 * Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
22 * As a special exception, AlliedModders LLC gives you permission to link the
23 * code of this program (as well as its derivative works) to "Half-Life 2," the
24 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
25 * by the Valve Corporation. You must obey the GNU General Public License in
26 * all respects for all other code used. Additionally, AlliedModders LLC grants
27 * this exception to all derivative works. AlliedModders LLC defines further
28 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
29 * or <http://www.sourcemod.net/license.php>.
38 public Plugin:myinfo =
41 author = "AlliedModders LLC",
42 description = "Basic Communication Commands",
43 version = SOURCEMOD_VERSION,
44 url = "http://www.sourcemod.net/"
47 #define CHAT_SYMBOL '@'
49 new String:g_ColorNames[13][10] = {"White", "Red", "Green", "Blue", "Yellow", "Purple", "Cyan", "Orange", "Pink", "Olive", "Lime", "Violet", "Lightblue"};
50 new 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}};
52 new Handle:g_Cvar_Chatmode = INVALID_HANDLE;
54 new bool:g_DoColor = true;
56 new g_GameEngine = SOURCE_SDK_UNKNOWN;
58 public OnPluginStart()
60 LoadTranslations("common.phrases");
62 g_GameEngine = GuessSDKVersion();
64 g_Cvar_Chatmode = CreateConVar("sm_chat_mode", "1", "Allows player's to send messages to admin chat.", 0, true, 0.0, true, 1.0);
66 RegConsoleCmd("say", Command_SayChat);
67 RegConsoleCmd("say_team", Command_SayAdmin);
68 RegAdminCmd("sm_say", Command_SmSay, ADMFLAG_CHAT, "sm_say <message> - sends message to all players");
69 RegAdminCmd("sm_csay", Command_SmCsay, ADMFLAG_CHAT, "sm_csay <message> - sends centered message to all players");
71 /* HintText does not work on Dark Messiah */
72 if (g_GameEngine != SOURCE_SDK_DARKMESSIAH)
74 RegAdminCmd("sm_hsay", Command_SmHsay, ADMFLAG_CHAT, "sm_hsay <message> - sends hint message to all players");
77 RegAdminCmd("sm_tsay", Command_SmTsay, ADMFLAG_CHAT, "sm_tsay [color] <message> - sends top-left message to all players");
78 RegAdminCmd("sm_chat", Command_SmChat, ADMFLAG_CHAT, "sm_chat <message> - sends message to admins");
79 RegAdminCmd("sm_psay", Command_SmPsay, ADMFLAG_CHAT, "sm_psay <name or #userid> <message> - sends private message");
80 RegAdminCmd("sm_msay", Command_SmMsay, ADMFLAG_CHAT, "sm_msay <message> - sends message as a menu panel");
82 decl String:modname[64];
83 GetGameFolderName(modname, sizeof(modname));
85 if (strcmp(modname, "hl2mp") == 0)
91 public Action:Command_SayChat(client, args)
93 decl String:text[192];
94 if (IsChatTrigger() || GetCmdArgString(text, sizeof(text)) < 1)
96 return Plugin_Continue;
100 if (text[strlen(text)-1] == '"')
102 text[strlen(text)-1] = '\0';
106 if (text[startidx] != CHAT_SYMBOL)
107 return Plugin_Continue;
111 if (text[startidx+1] == CHAT_SYMBOL)
115 if (text[startidx+2] == CHAT_SYMBOL)
119 decl String:message[192];
120 strcopy(message, 192, text[startidx+msgStart]);
122 decl String:name[64];
123 GetClientName(client, name, sizeof(name));
125 if (msgStart == 1 && CheckCommandAccess(client, "sm_say", ADMFLAG_CHAT)) // sm_say alias
127 SendChatToAll(client, message);
128 LogAction(client, -1, "%L triggered sm_say (text %s)", client, message);
130 else if (msgStart == 3 && CheckCommandAccess(client, "sm_csay", ADMFLAG_CHAT)) // sm_csay alias
132 DisplayCenterTextToAll(client, message);
133 LogAction(client, -1, "%L triggered sm_csay (text %s)", client, text);
135 else if (msgStart == 2 && CheckCommandAccess(client, "sm_psay", ADMFLAG_CHAT)) // sm_psay alias
139 new len = BreakString(message, arg, sizeof(arg));
140 new target = FindTarget(client, arg, true, false);
142 if (target == -1 || len == -1)
143 return Plugin_Handled;
145 decl String:name2[64];
146 GetClientName(target, name2, sizeof(name2));
150 PrintToChat(client, "\x04(Private to %s) %s: \x01%s", name2, name, message[len]);
151 PrintToChat(target, "\x04(Private to %s) %s: \x01%s", name2, name, message[len]);
155 PrintToChat(client, "(Private to %s) %s: %s", name2, name, message[len]);
156 PrintToChat(target, "(Private to %s) %s: %s", name2, name, message[len]);
159 LogAction(client, -1, "%L triggered sm_psay to %L (text %s)", client, target, message);
162 return Plugin_Continue;
164 return Plugin_Handled;
167 public Action:Command_SayAdmin(client, args)
169 if (!CheckCommandAccess(client, "sm_chat", ADMFLAG_CHAT) && !GetConVarBool(g_Cvar_Chatmode))
171 return Plugin_Continue;
174 decl String:text[192];
175 if (IsChatTrigger() || GetCmdArgString(text, sizeof(text)) < 1)
177 return Plugin_Continue;
181 if (text[strlen(text)-1] == '"')
183 text[strlen(text)-1] = '\0';
187 if (text[startidx] != CHAT_SYMBOL)
188 return Plugin_Continue;
190 decl String:message[192];
191 strcopy(message, 192, text[startidx+1]);
193 decl String:name[64];
194 GetClientName(client, name, sizeof(name));
196 SendChatToAdmins(name, message);
197 LogAction(client, -1, "%L triggered sm_chat (text %s)", client, message);
199 return Plugin_Handled;
202 public Action:Command_SmSay(client, args)
206 ReplyToCommand(client, "[SM] Usage: sm_say <message>");
207 return Plugin_Handled;
210 decl String:text[192];
211 GetCmdArgString(text, sizeof(text));
213 SendChatToAll(client, text);
214 LogAction(client, -1, "%L triggered sm_say (text %s)", client, text);
216 return Plugin_Handled;
219 public Action:Command_SmCsay(client, args)
223 ReplyToCommand(client, "[SM] Usage: sm_csay <message>");
224 return Plugin_Handled;
227 decl String:text[192];
228 GetCmdArgString(text, sizeof(text));
230 DisplayCenterTextToAll(client, text);
232 LogAction(client, -1, "%L triggered sm_csay (text %s)", client, text);
234 return Plugin_Handled;
237 public Action:Command_SmHsay(client, args)
241 ReplyToCommand(client, "[SM] Usage: sm_hsay <message>");
242 return Plugin_Handled;
245 decl String:text[192];
246 GetCmdArgString(text, sizeof(text));
248 decl String:nameBuf[MAX_NAME_LENGTH];
250 for (new i = 1; i <= MaxClients; i++)
252 if (!IsClientInGame(i) || IsFakeClient(i))
256 FormatActivitySource(client, i, nameBuf, sizeof(nameBuf));
257 PrintHintText(i, "%s: %s", nameBuf, text);
260 LogAction(client, -1, "%L triggered sm_hsay (text %s)", client, text);
262 return Plugin_Handled;
265 public Action:Command_SmTsay(client, args)
269 ReplyToCommand(client, "[SM] Usage: sm_tsay <message>");
270 return Plugin_Handled;
273 decl String:text[192], String:colorStr[16];
274 GetCmdArgString(text, sizeof(text));
276 new len = BreakString(text, colorStr, 16);
278 decl String:name[64];
279 GetClientName(client, name, sizeof(name));
281 new color = FindColor(colorStr);
282 new String:nameBuf[MAX_NAME_LENGTH];
290 for (new i = 1; i <= MaxClients; i++)
292 if (!IsClientInGame(i) || IsFakeClient(i))
296 FormatActivitySource(client, i, nameBuf, sizeof(nameBuf));
297 SendDialogToOne(i, color, "%s: %s", nameBuf, text[len]);
300 LogAction(client, -1, "%L triggered sm_tsay (text %s)", client, text);
302 return Plugin_Handled;
305 public Action:Command_SmChat(client, args)
309 ReplyToCommand(client, "[SM] Usage: sm_chat <message>");
310 return Plugin_Handled;
313 decl String:text[192];
314 GetCmdArgString(text, sizeof(text));
316 decl String:name[64];
317 GetClientName(client, name, sizeof(name));
319 SendChatToAdmins(name, text);
320 LogAction(client, -1, "%L triggered sm_chat (text %s)", client, text);
322 return Plugin_Handled;
325 public Action:Command_SmPsay(client, args)
329 ReplyToCommand(client, "[SM] Usage: sm_psay <name or #userid> <message>");
330 return Plugin_Handled;
333 decl String:text[192], String:arg[64], String:message[192];
334 GetCmdArgString(text, sizeof(text));
336 new len = BreakString(text, arg, sizeof(arg));
337 BreakString(text[len], message, sizeof(message));
339 new target = FindTarget(client, arg, true, false);
342 return Plugin_Handled;
344 decl String:name[64], String:name2[64];
352 GetClientName(client, name, sizeof(name));
355 GetClientName(target, name2, sizeof(name2));
359 PrintToServer("(Private: %s) %s: %s", name2, name, message);
363 PrintToChat(client, "\x04(Private: %s) %s: \x01%s", name2, name, message);
367 PrintToChat(client, "(Private: %s) %s: %s", name2, name, message);
372 PrintToChat(target, "\x04(Private: %s) %s: \x01%s", name2, name, message);
376 PrintToChat(target, "(Private: %s) %s: %s", name2, name, message);
379 LogAction(client, -1, "%L triggered sm_psay to %L (text %s)", client, target, message);
381 return Plugin_Handled;
384 public Action:Command_SmMsay(client, args)
388 ReplyToCommand(client, "[SM] Usage: sm_msay <message>");
389 return Plugin_Handled;
392 decl String:text[192];
393 GetCmdArgString(text, sizeof(text));
395 decl String:name[64];
396 GetClientName(client, name, sizeof(name));
398 SendPanelToAll(name, text);
400 LogAction(client, -1, "%L triggered sm_msay (text %s)", client, text);
402 return Plugin_Handled;
405 FindColor(String:color[])
407 for (new i = 0; i < 13; i++)
409 if (strcmp(color, g_ColorNames[i], false) == 0)
416 SendChatToAll(client, String:message[])
418 new String:nameBuf[MAX_NAME_LENGTH];
420 for (new i = 1; i <= MaxClients; i++)
422 if (!IsClientInGame(i) || IsFakeClient(i))
426 FormatActivitySource(client, i, nameBuf, sizeof(nameBuf));
430 PrintToChat(i, "\x04(ALL) %s: \x01%s", nameBuf, message);
434 PrintToChat(i, "%s: %s", nameBuf, message);
439 DisplayCenterTextToAll(client, String:message[])
441 new String:nameBuf[MAX_NAME_LENGTH];
443 for (new i = 1; i < MaxClients; i++)
445 if (!IsClientInGame(i) || IsFakeClient(i))
449 FormatActivitySource(client, i, nameBuf, sizeof(nameBuf));
450 PrintCenterText(i, "%s: %s", nameBuf, message);
454 SendChatToAdmins(String:name[], String:message[])
456 for (new i = 1; i <= MaxClients; i++)
458 if (IsClientInGame(i))
460 if (CheckCommandAccess(i, "sm_chat", ADMFLAG_CHAT))
464 PrintToChat(i, "\x04(ADMINS) %s: \x01%s", name, message);
468 PrintToChat(i, "(ADMINS) %s: %s", name, message);
475 SendDialogToOne(client, color, String:text[], any:...)
477 new String:message[100];
478 VFormat(message, sizeof(message), text, 4);
480 new Handle:kv = CreateKeyValues("Stuff", "title", message);
481 KvSetColor(kv, "color", g_Colors[color][0], g_Colors[color][1], g_Colors[color][2], 255);
482 KvSetNum(kv, "level", 1);
483 KvSetNum(kv, "time", 10);
485 CreateDialog(client, kv, DialogType_Msg);
490 SendPanelToAll(String:name[], String:message[])
492 decl String:title[100];
493 Format(title, 64, "%s:", name);
495 ReplaceString(message, 192, "\\n", "\n");
497 new Handle:mSayPanel = CreatePanel();
498 SetPanelTitle(mSayPanel, title);
499 DrawPanelItem(mSayPanel, "", ITEMDRAW_SPACER);
500 DrawPanelText(mSayPanel, message);
501 DrawPanelItem(mSayPanel, "", ITEMDRAW_SPACER);
503 SetPanelCurrentKey(mSayPanel, 10);
504 DrawPanelItem(mSayPanel, "Exit", ITEMDRAW_CONTROL);
506 for(new i = 1; i <= MaxClients; i++)
508 if(IsClientInGame(i) && !IsFakeClient(i))
510 SendPanelToClient(mSayPanel, i, Handler_DoNothing, 10);
514 CloseHandle(mSayPanel);
517 public Handler_DoNothing(Handle:menu, MenuAction:action, param1, param2)