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 public OnPluginStart()
58 LoadTranslations("common.phrases");
60 g_Cvar_Chatmode = CreateConVar("sm_chat_mode", "1", "Allows player's to send messages to admin chat.", 0, true, 0.0, true, 1.0);
62 RegConsoleCmd("say", Command_SayChat);
63 RegConsoleCmd("say_team", Command_SayAdmin);
64 RegAdminCmd("sm_say", Command_SmSay, ADMFLAG_CHAT, "sm_say <message> - sends message to all players");
65 RegAdminCmd("sm_csay", Command_SmCsay, ADMFLAG_CHAT, "sm_csay <message> - sends centered message to all players");
66 RegAdminCmd("sm_hsay", Command_SmHsay, ADMFLAG_CHAT, "sm_hsay <message> - sends hint message to all players");
67 RegAdminCmd("sm_tsay", Command_SmTsay, ADMFLAG_CHAT, "sm_tsay [color] <message> - sends top-left message to all players");
68 RegAdminCmd("sm_chat", Command_SmChat, ADMFLAG_CHAT, "sm_chat <message> - sends message to admins");
69 RegAdminCmd("sm_psay", Command_SmPsay, ADMFLAG_CHAT, "sm_psay <name or #userid> <message> - sends private message");
70 RegAdminCmd("sm_msay", Command_SmMsay, ADMFLAG_CHAT, "sm_msay <message> - sends message as a menu panel");
72 decl String:modname[64];
73 GetGameFolderName(modname, sizeof(modname));
75 if (strcmp(modname, "hl2mp") == 0)
81 public Action:Command_SayChat(client, args)
83 decl String:text[192];
84 if (IsChatTrigger() || GetCmdArgString(text, sizeof(text)) < 1)
86 return Plugin_Continue;
90 if (text[strlen(text)-1] == '"')
92 text[strlen(text)-1] = '\0';
96 if (text[startidx] != CHAT_SYMBOL)
97 return Plugin_Continue;
101 if (text[startidx+1] == CHAT_SYMBOL)
105 if (text[startidx+2] == CHAT_SYMBOL)
109 decl String:message[192];
110 strcopy(message, 192, text[startidx+msgStart]);
112 decl String:name[64];
113 GetClientName(client, name, sizeof(name));
115 if (msgStart == 1 && CheckCommandAccess(client, "sm_say", ADMFLAG_CHAT)) // sm_say alias
117 SendChatToAll(client, message);
118 LogAction(client, -1, "%L triggered sm_say (text %s)", client, message);
120 else if (msgStart == 3 && CheckCommandAccess(client, "sm_csay", ADMFLAG_CHAT)) // sm_csay alias
122 DisplayCenterTextToAll(client, message);
123 LogAction(client, -1, "%L triggered sm_csay (text %s)", client, text);
125 else if (msgStart == 2 && CheckCommandAccess(client, "sm_psay", ADMFLAG_CHAT)) // sm_psay alias
129 new len = BreakString(message, arg, sizeof(arg));
130 new target = FindTarget(client, arg, true, false);
132 if (target == -1 || len == -1)
133 return Plugin_Handled;
135 decl String:name2[64];
136 GetClientName(target, name2, sizeof(name2));
140 PrintToChat(client, "\x04(Private to %s) %s: \x01%s", name2, name, message[len]);
141 PrintToChat(target, "\x04(Private to %s) %s: \x01%s", name2, name, message[len]);
145 PrintToChat(client, "(Private to %s) %s: %s", name2, name, message[len]);
146 PrintToChat(target, "(Private to %s) %s: %s", name2, name, message[len]);
149 LogAction(client, -1, "%L triggered sm_psay to %L (text %s)", client, target, message);
152 return Plugin_Continue;
154 return Plugin_Handled;
157 public Action:Command_SayAdmin(client, args)
159 if (!CheckCommandAccess(client, "sm_chat", ADMFLAG_CHAT) && !GetConVarBool(g_Cvar_Chatmode))
161 return Plugin_Continue;
164 decl String:text[192];
165 if (IsChatTrigger() || GetCmdArgString(text, sizeof(text)) < 1)
167 return Plugin_Continue;
171 if (text[strlen(text)-1] == '"')
173 text[strlen(text)-1] = '\0';
177 if (text[startidx] != CHAT_SYMBOL)
178 return Plugin_Continue;
180 decl String:message[192];
181 strcopy(message, 192, text[startidx+1]);
183 decl String:name[64];
184 GetClientName(client, name, sizeof(name));
186 SendChatToAdmins(name, message);
187 LogAction(client, -1, "%L triggered sm_chat (text %s)", client, message);
189 return Plugin_Handled;
192 public Action:Command_SmSay(client, args)
196 ReplyToCommand(client, "[SM] Usage: sm_say <message>");
197 return Plugin_Handled;
200 decl String:text[192];
201 GetCmdArgString(text, sizeof(text));
203 SendChatToAll(client, text);
204 LogAction(client, -1, "%L triggered sm_say (text %s)", client, text);
206 return Plugin_Handled;
209 public Action:Command_SmCsay(client, args)
213 ReplyToCommand(client, "[SM] Usage: sm_csay <message>");
214 return Plugin_Handled;
217 decl String:text[192];
218 GetCmdArgString(text, sizeof(text));
220 DisplayCenterTextToAll(client, text);
222 LogAction(client, -1, "%L triggered sm_csay (text %s)", client, text);
224 return Plugin_Handled;
227 public Action:Command_SmHsay(client, args)
231 ReplyToCommand(client, "[SM] Usage: sm_hsay <message>");
232 return Plugin_Handled;
235 decl String:text[192];
236 GetCmdArgString(text, sizeof(text));
238 decl String:nameBuf[MAX_NAME_LENGTH];
240 new maxClients = GetMaxClients();
241 for (new i = 1; i <= maxClients; i++)
243 if (!IsClientConnected(i) || IsFakeClient(i))
247 FormatActivitySource(client, i, nameBuf, sizeof(nameBuf));
248 PrintHintText(i, "%s: %s", nameBuf, text);
251 LogAction(client, -1, "%L triggered sm_hsay (text %s)", client, text);
253 return Plugin_Handled;
256 public Action:Command_SmTsay(client, args)
260 ReplyToCommand(client, "[SM] Usage: sm_tsay <message>");
261 return Plugin_Handled;
264 decl String:text[192], String:colorStr[16];
265 GetCmdArgString(text, sizeof(text));
267 new len = BreakString(text, colorStr, 16);
269 decl String:name[64];
270 GetClientName(client, name, sizeof(name));
272 new color = FindColor(colorStr);
273 new maxClients = GetMaxClients();
274 new String:nameBuf[MAX_NAME_LENGTH];
282 for (new i = 1; i <= maxClients; i++)
284 if (!IsClientConnected(i) || IsFakeClient(i))
288 FormatActivitySource(client, i, nameBuf, sizeof(nameBuf));
289 SendDialogToOne(i, color, "%s: %s", nameBuf, text[len]);
292 LogAction(client, -1, "%L triggered sm_tsay (text %s)", client, text);
294 return Plugin_Handled;
297 public Action:Command_SmChat(client, args)
301 ReplyToCommand(client, "[SM] Usage: sm_chat <message>");
302 return Plugin_Handled;
305 decl String:text[192];
306 GetCmdArgString(text, sizeof(text));
308 decl String:name[64];
309 GetClientName(client, name, sizeof(name));
311 SendChatToAdmins(name, text);
312 LogAction(client, -1, "%L triggered sm_chat (text %s)", client, text);
314 return Plugin_Handled;
317 public Action:Command_SmPsay(client, args)
321 ReplyToCommand(client, "[SM] Usage: sm_psay <name or #userid> <message>");
322 return Plugin_Handled;
325 decl String:text[192], String:arg[64], String:message[192];
326 GetCmdArgString(text, sizeof(text));
328 new len = BreakString(text, arg, sizeof(arg));
329 BreakString(text[len], message, sizeof(message));
331 new target = FindTarget(client, arg, true, false);
334 return Plugin_Handled;
336 decl String:name[64], String:name2[64];
344 GetClientName(client, name, sizeof(name));
347 GetClientName(target, name2, sizeof(name2));
351 PrintToServer("(Private: %s) %s: %s", name2, name, message);
355 PrintToChat(client, "\x04(Private: %s) %s: \x01%s", name2, name, message);
359 PrintToChat(client, "(Private: %s) %s: %s", name2, name, message);
364 PrintToChat(target, "\x04(Private: %s) %s: \x01%s", name2, name, message);
368 PrintToChat(target, "(Private: %s) %s: %s", name2, name, message);
371 LogAction(client, -1, "%L triggered sm_psay to %L (text %s)", client, target, message);
373 return Plugin_Handled;
376 public Action:Command_SmMsay(client, args)
380 ReplyToCommand(client, "[SM] Usage: sm_msay <message>");
381 return Plugin_Handled;
384 decl String:text[192];
385 GetCmdArgString(text, sizeof(text));
387 decl String:name[64];
388 GetClientName(client, name, sizeof(name));
390 SendPanelToAll(name, text);
392 LogAction(client, -1, "%L triggered sm_msay (text %s)", client, text);
394 return Plugin_Handled;
397 FindColor(String:color[])
399 for (new i = 0; i < 13; i++)
401 if (strcmp(color, g_ColorNames[i], false) == 0)
408 SendChatToAll(client, String:message[])
411 new String:nameBuf[MAX_NAME_LENGTH];
413 maxClients = GetMaxClients();
414 for (new i = 1; i <= maxClients; i++)
416 if (!IsClientConnected(i) || IsFakeClient(i))
420 FormatActivitySource(client, i, nameBuf, sizeof(nameBuf));
424 PrintToChat(i, "\x04(ALL) %s: \x01%s", nameBuf, message);
428 PrintToChat(i, "%s: %s", nameBuf, message);
433 DisplayCenterTextToAll(client, String:message[])
435 new String:nameBuf[MAX_NAME_LENGTH];
436 new maxClients = GetMaxClients();
438 for (new i = 1; i < maxClients; i++)
440 if (!IsClientConnected(i) || IsFakeClient(i))
444 FormatActivitySource(client, i, nameBuf, sizeof(nameBuf));
445 PrintCenterText(i, "%s: %s", nameBuf, message);
449 SendChatToAdmins(String:name[], String:message[])
451 new iMaxClients = GetMaxClients();
453 for (new i = 1; i <= iMaxClients; i++)
455 if (IsClientInGame(i))
457 if (CheckCommandAccess(i, "sm_chat", ADMFLAG_CHAT))
461 PrintToChat(i, "\x04(ADMINS) %s: \x01%s", name, message);
465 PrintToChat(i, "(ADMINS) %s: %s", name, message);
472 SendDialogToOne(client, color, String:text[], any:...)
474 new String:message[100];
475 VFormat(message, sizeof(message), text, 4);
477 new Handle:kv = CreateKeyValues("Stuff", "title", message);
478 KvSetColor(kv, "color", g_Colors[color][0], g_Colors[color][1], g_Colors[color][2], 255);
479 KvSetNum(kv, "level", 1);
480 KvSetNum(kv, "time", 10);
482 CreateDialog(client, kv, DialogType_Msg);
487 SendPanelToAll(String:name[], String:message[])
489 decl String:title[100];
490 Format(title, 64, "%s:", name);
492 ReplaceString(message, 192, "\\n", "\n");
494 new Handle:mSayPanel = CreatePanel();
495 SetPanelTitle(mSayPanel, title);
496 DrawPanelItem(mSayPanel, "", ITEMDRAW_SPACER);
497 DrawPanelText(mSayPanel, message);
498 DrawPanelItem(mSayPanel, "", ITEMDRAW_SPACER);
500 SetPanelCurrentKey(mSayPanel, 10);
501 DrawPanelItem(mSayPanel, "Exit", ITEMDRAW_CONTROL);
503 new MaxClients = GetMaxClients();
504 for(new i = 1; i < MaxClients; i++)
506 if(IsClientInGame(i) && !IsFakeClient(i))
508 SendPanelToClient(mSayPanel, i, Handler_DoNothing, 10);
512 CloseHandle(mSayPanel);
515 public Handler_DoNothing(Handle:menu, MenuAction:action, param1, param2)