3 * =============================================================================
4 * SourceMod Basic Chat Plugin
5 * Implements basic communication commands.
7 * SourceMod (C)2004-2007 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;
53 new Handle:g_Cvar_Psaymode = INVALID_HANDLE;
55 new bool:g_DoColor = true;
57 public OnPluginStart()
59 LoadTranslations("common.phrases");
61 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 g_Cvar_Psaymode = CreateConVar("sm_psay_mode", "0", "Allows player's to use psay 'say @@' alias.", 0, true, 0.0, true, 1.0);
64 RegConsoleCmd("say", Command_SayChat);
65 RegConsoleCmd("say_team", Command_SayAdmin);
66 RegAdminCmd("sm_say", Command_SmSay, ADMFLAG_CHAT, "sm_say <message> - sends message to all players");
67 RegAdminCmd("sm_csay", Command_SmCsay, ADMFLAG_CHAT, "sm_csay <message> - sends centered message to all players");
68 RegAdminCmd("sm_hsay", Command_SmHsay, ADMFLAG_CHAT, "sm_hsay <message> - sends hint message to all players");
69 RegAdminCmd("sm_tsay", Command_SmTsay, ADMFLAG_CHAT, "sm_tsay [color] <message> - sends top-left message to all players");
70 RegAdminCmd("sm_chat", Command_SmChat, ADMFLAG_CHAT, "sm_chat <message> - sends message to admins");
71 RegAdminCmd("sm_psay", Command_SmPsay, ADMFLAG_CHAT, "sm_psay <name or #userid> <message> - sends private message");
72 RegAdminCmd("sm_msay", Command_SmMsay, ADMFLAG_CHAT, "sm_msay <message> - sends message as a menu panel");
74 decl String:modname[64];
75 GetGameFolderName(modname, sizeof(modname));
77 if (strcmp(modname, "hl2mp") == 0)
83 public Action:Command_SayChat(client, args)
85 decl String:text[192];
86 if (IsChatTrigger() || GetCmdArgString(text, sizeof(text)) < 1)
88 return Plugin_Continue;
92 if (text[strlen(text)-1] == '"')
94 text[strlen(text)-1] = '\0';
98 if (text[startidx] != CHAT_SYMBOL)
99 return Plugin_Continue;
103 if (text[startidx+1] == CHAT_SYMBOL)
107 if (text[startidx+2] == CHAT_SYMBOL)
111 decl String:message[192];
112 strcopy(message, 192, text[startidx+msgStart]);
114 decl String:name[64];
115 GetClientName(client, name, sizeof(name));
117 if (msgStart == 1 && CheckAdminForChat(client)) // sm_say alias
119 SendChatToAll(name, message);
120 LogAction(client, -1, "%L triggered sm_say (text %s)", client, message);
122 else if (msgStart == 3 && CheckAdminForChat(client)) // sm_csay alias
124 PrintCenterTextAll("%s: %s", name, message);
125 LogAction(client, -1, "%L triggered sm_csay (text %s)", client, text);
127 else if (msgStart == 2 && (CheckAdminForChat(client) || GetConVarBool(g_Cvar_Psaymode))) // sm_psay alias
131 new len = BreakString(message, arg, sizeof(arg));
132 new target = FindTarget(client, arg, true, false);
135 return Plugin_Handled;
137 decl String:name2[64];
138 GetClientName(target, name2, sizeof(name2));
142 PrintToChat(client, "\x04(Private to %s) %s: \x01%s", name2, name, message[len]);
143 PrintToChat(target, "\x04(Private to %s) %s: \x01%s", name2, name, message[len]);
147 PrintToChat(client, "(Private to %s) %s: %s", name2, name, message[len]);
148 PrintToChat(target, "(Private to %s) %s: %s", name2, name, message[len]);
151 LogAction(client, -1, "%L triggered sm_psay to %L (text %s)", client, target, message);
154 return Plugin_Continue;
156 return Plugin_Handled;
159 public Action:Command_SayAdmin(client, args)
161 if (!CheckAdminForChat(client) && !GetConVarBool(g_Cvar_Chatmode))
163 return Plugin_Continue;
166 decl String:text[192];
167 if (IsChatTrigger() || GetCmdArgString(text, sizeof(text)) < 1)
169 return Plugin_Continue;
173 if (text[strlen(text)-1] == '"')
175 text[strlen(text)-1] = '\0';
179 if (text[startidx] != CHAT_SYMBOL)
180 return Plugin_Continue;
182 decl String:message[192];
183 strcopy(message, 192, text[startidx+1]);
185 decl String:name[64];
186 GetClientName(client, name, sizeof(name));
188 SendChatToAdmins(name, message);
189 LogAction(client, -1, "%L triggered sm_chat (text %s)", client, message);
191 return Plugin_Handled;
194 public Action:Command_SmSay(client, args)
198 ReplyToCommand(client, "[SM] Usage: sm_say <message>");
199 return Plugin_Handled;
202 decl String:text[192];
203 GetCmdArgString(text, sizeof(text));
205 decl String:name[64];
206 GetClientName(client, name, sizeof(name));
208 SendChatToAll(name, text);
209 LogAction(client, -1, "%L triggered sm_say (text %s)", client, text);
211 return Plugin_Handled;
214 public Action:Command_SmCsay(client, args)
218 ReplyToCommand(client, "[SM] Usage: sm_csay <message>");
219 return Plugin_Handled;
222 decl String:text[192];
223 GetCmdArgString(text, sizeof(text));
226 GetClientName(client, name, sizeof(name));
228 PrintCenterTextAll("%s: %s", name, text);
229 LogAction(client, -1, "%L triggered sm_csay (text %s)", client, text);
231 return Plugin_Handled;
234 public Action:Command_SmHsay(client, args)
238 ReplyToCommand(client, "[SM] Usage: sm_hsay <message>");
239 return Plugin_Handled;
242 decl String:text[192];
243 GetCmdArgString(text, sizeof(text));
245 decl String:name[64];
246 GetClientName(client, name, sizeof(name));
248 PrintHintTextToAll("%s: %s", name, text);
249 LogAction(client, -1, "%L triggered sm_hsay (text %s)", client, text);
251 return Plugin_Handled;
254 public Action:Command_SmTsay(client, args)
258 ReplyToCommand(client, "[SM] Usage: sm_tsay <message>");
259 return Plugin_Handled;
262 decl String:text[192], String:colorStr[16];
263 GetCmdArgString(text, sizeof(text));
265 new len = BreakString(text, colorStr, 16);
267 decl String:name[64];
268 GetClientName(client, name, sizeof(name));
270 new color = FindColor(colorStr);
273 SendDialogToAll(_, "%s: %s", name, text);
275 SendDialogToAll(color, "%s: %s", name, text[len]);
277 LogAction(client, -1, "%L triggered sm_tsay (text %s)", client, text);
279 return Plugin_Handled;
282 public Action:Command_SmChat(client, args)
286 ReplyToCommand(client, "[SM] Usage: sm_chat <message>");
287 return Plugin_Handled;
290 decl String:text[192];
291 GetCmdArgString(text, sizeof(text));
293 decl String:name[64];
294 GetClientName(client, name, sizeof(name));
296 SendChatToAdmins(name, text);
297 LogAction(client, -1, "%L triggered sm_chat (text %s)", client, text);
299 return Plugin_Handled;
302 public Action:Command_SmPsay(client, args)
306 ReplyToCommand(client, "[SM] Usage: sm_psay <name or #userid> <message>");
307 return Plugin_Handled;
310 decl String:text[192], String:arg[64], String:message[192];
311 GetCmdArgString(text, sizeof(text));
313 new len = BreakString(text, arg, sizeof(arg));
314 BreakString(text[len], message, sizeof(message));
316 new target = FindTarget(client, arg, true, false);
319 return Plugin_Handled;
321 decl String:name[64], String:name2[64];
322 GetClientName(client, name, sizeof(name));
323 GetClientName(target, name2, sizeof(name2));
327 PrintToChat(client, "\x04(Private: %s) %s: \x01%s", name2, name, message);
328 PrintToChat(target, "\x04(Private: %s) %s: \x01%s", name2, name, message);
332 PrintToChat(client, "(Private: %s) %s: %s", name2, name, message);
333 PrintToChat(target, "(Private: %s) %s: %s", name2, name, message);
336 LogAction(client, -1, "%L triggered sm_psay to %L (text %s)", client, target, message);
338 return Plugin_Handled;
341 public Action:Command_SmMsay(client, args)
345 ReplyToCommand(client, "[SM] Usage: sm_msay <message>");
346 return Plugin_Handled;
349 decl String:text[192];
350 GetCmdArgString(text, sizeof(text));
352 decl String:name[64];
353 GetClientName(client, name, sizeof(name));
355 SendPanelToAll(name, text);
357 LogAction(client, -1, "%L triggered sm_msay (text %s)", client, text);
359 return Plugin_Handled;
362 bool:CheckAdminForChat(client)
369 return CheckCommandAccess(client, "sm_chat", ADMFLAG_CHAT);
372 FindColor(String:color[])
374 for (new i = 0; i < 13; i++)
376 if (strcmp(color, g_ColorNames[i], false) == 0)
383 SendChatToAll(String:name[], String:message[])
387 PrintToChatAll("\x04(ALL) %s: \x01%s", name, message);
391 PrintToChatAll("(ALL) %s: %s", name, message);
395 SendChatToAdmins(String:name[], String:message[])
397 new iMaxClients = GetMaxClients();
399 for (new i = 1; i <= iMaxClients; i++)
401 if (IsClientInGame(i))
403 if (CheckAdminForChat(i))
407 PrintToChat(i, "\x04(ADMINS) %s: \x01%s", name, message);
411 PrintToChat(i, "(ADMINS) %s: %s", name, message);
418 SendDialogToAll(color = 0, String:text[], any:...)
420 new String:message[100];
421 VFormat(message, sizeof(message), text, 3);
423 new MaxClients = GetMaxClients();
424 for(new i = 1; i < MaxClients; i++)
426 if(IsClientInGame(i))
428 new Handle:kv = CreateKeyValues("Stuff", "title", message);
429 KvSetColor(kv, "color", g_Colors[color][0], g_Colors[color][1], g_Colors[color][2], 255);
430 KvSetNum(kv, "level", 1);
431 KvSetNum(kv, "time", 10);
433 CreateDialog(i, kv, DialogType_Msg);
440 SendPanelToAll(String:name[], String:message[])
442 decl String:title[100];
443 Format(title, 64, "%s:", name);
445 ReplaceString(message, 192, "\\n", "\n");
447 new Handle:mSayPanel = CreatePanel();
448 SetPanelTitle(mSayPanel, title);
449 DrawPanelItem(mSayPanel, "", ITEMDRAW_SPACER);
450 DrawPanelText(mSayPanel, message);
451 DrawPanelItem(mSayPanel, "", ITEMDRAW_SPACER);
453 SetPanelCurrentKey(mSayPanel, 10);
454 DrawPanelItem(mSayPanel, "Exit", ITEMDRAW_CONTROL);
456 new MaxClients = GetMaxClients();
457 for(new i = 1; i < MaxClients; i++)
459 if(IsClientInGame(i) && !IsFakeClient(i))
461 SendPanelToClient(mSayPanel, i, Handler_DoNothing, 10);
465 CloseHandle(mSayPanel);
468 public Handler_DoNothing(Handle:menu, MenuAction:action, param1, param2)