3 * Implements basic communication commands
4 * This file is part of SourceMod, Copyright (C) 2004-2007 AlliedModders LLC
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 public Plugin:myinfo =
30 author = "AlliedModders LLC",
31 description = "Basic Communication Commands",
32 version = SOURCEMOD_VERSION,
33 url = "http://www.sourcemod.net/"
36 decl String:g_ColorNames[13][10] = {"White", "Red", "Green", "Blue", "Yellow", "Purple", "Cyan", "Orange", "Pink", "Olive", "Lime", "Violet", "Lightblue"};
37 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}};
39 new Handle:g_Cvar_Chatmode = INVALID_HANDLE;
40 new Handle:g_Cvar_Psaymode = INVALID_HANDLE;
42 new bool:g_DoColor = false;
48 public OnPluginStart()
50 LoadTranslations("common.phrases");
51 LoadTranslations("plugin.basecommands");
53 g_Cvar_Chatmode = CreateConVar("sm_chat_mode", "1", "Allows player's to send messages to admin chat.", 0, true, 0.0, true, 1.0);
54 g_Cvar_Psaymode = CreateConVar("sm_psay_mode", "0", "Allows player's to use psay 'say @@' alias.", 0, true, 0.0, true, 1.0);
56 RegConsoleCmd("say", Command_SayChat);
57 RegConsoleCmd("say_team", Command_SayAdmin);
58 RegAdminCmd("sm_say", Command_SmSay, ADMFLAG_CHAT, "sm_say <message> - sends message to all players");
59 RegAdminCmd("sm_csay", Command_SmCsay, ADMFLAG_CHAT, "sm_csay <message> - sends centered message to all players");
60 //RegAdminCmd("sm_hsay", Command_SmHsay, ADMFLAG_CHAT, "sm_hsay <message> - sends hint message to all players");
61 RegAdminCmd("sm_tsay", Command_SmTsay, ADMFLAG_CHAT, "sm_tsay [color] <message> - sends top-left message to all players");
62 RegAdminCmd("sm_chat", Command_SmChat, ADMFLAG_CHAT, "sm_chat <message> - sends message to admins");
63 RegAdminCmd("sm_psay", Command_SmPsay, ADMFLAG_CHAT, "sm_psay <name or #userid> <message> - sends private message");
64 RegAdminCmd("sm_msay", Command_SmMsay, ADMFLAG_CHAT, "sm_msay <message> - sends message as a menu panel");
66 decl String:modname[64];
67 GetGameFolderName(modname, sizeof(modname));
69 if (strcmp(modname, "cstrike") == 0)
72 RegAdminCmd("sm_hsay", Command_SmHsay, ADMFLAG_CHAT, "sm_hsay <message> - sends hint message to all players");
76 if (strcmp(modname, "ins") == 0)
78 RegConsoleCmd("say2", Command_SayChat);
84 public Action:Command_SayChat(client, args)
86 decl String:text[192];
87 GetCmdArgString(text, sizeof(text));
90 if (text[strlen(text)-1] == '"')
92 text[strlen(text)-1] = '\0';
103 if (text[startidx] != '@')
104 return Plugin_Continue;
108 if (text[startidx+1] == '@')
112 if (text[startidx+2] == '@')
116 decl String:message[192];
117 strcopy(message, 192, text[startidx+msgStart]);
119 decl String:name[64];
120 GetClientName(client, name, sizeof(name));
122 if (msgStart == 1 && CheckAdminForChat(client)) // sm_say alias
124 SendChatToAll(name, message);
125 LogMessage("%L triggered sm_say (text %s)", client, message);
127 else if (msgStart == 3 && CheckAdminForChat(client)) // sm_csay alias
129 PrintCenterTextAll("%s: %s", name, message);
130 LogMessage("%L triggered sm_csay (text %s)", client, text);
132 else if (msgStart == 2 && (CheckAdminForChat(client) || GetConVarBool(g_Cvar_Psaymode))) // sm_psay alias
136 new len = BreakString(message, arg, sizeof(target));
137 new target = FindTarget(client, arg, true, false);
140 return Plugin_Handled;
142 decl String:name2[64];
143 GetClientName(target, name2, sizeof(name2));
147 PrintToChat(client, "\x04(Private to %s) %s: \x01%s", name2, name, message[len]);
148 PrintToChat(target, "\x04(Private to %s) %s: \x01%s", name2, name, message[len]);
152 PrintToChat(client, "(Private to %s) %s: %s", name2, name, message[len]);
153 PrintToChat(target, "(Private to %s) %s: %s", name2, name, message[len]);
156 LogMessage("%L triggered sm_psay to %L (text %s)", client, target, message);
159 return Plugin_Continue;
161 return Plugin_Handled;
164 public Action:Command_SayAdmin(client, args)
166 if (!CheckAdminForChat(client) && !GetConVarBool(g_Cvar_Chatmode))
167 return Plugin_Continue;
169 decl String:text[192];
170 GetCmdArgString(text, sizeof(text));
173 if (text[strlen(text)-1] == '"')
175 text[strlen(text)-1] = '\0';
186 if (text[startidx] != '@')
187 return Plugin_Continue;
189 decl String:message[192];
190 strcopy(message, 192, text[startidx+1]);
192 decl String:name[64];
193 GetClientName(client, name, sizeof(name));
195 SendChatToAdmins(name, message);
196 LogMessage("%L triggered sm_chat (text %s)", client, message);
198 return Plugin_Handled;
201 public Action:Command_SmSay(client, args)
205 ReplyToCommand(client, "[SM] Usage: sm_say <message>");
206 return Plugin_Handled;
209 decl String:text[192];
210 GetCmdArgString(text, sizeof(text));
212 decl String:name[64];
213 GetClientName(client, name, sizeof(name));
215 SendChatToAll(name, text);
216 LogMessage("%L triggered sm_say (text %s)", client, text);
218 return Plugin_Handled;
221 public Action:Command_SmCsay(client, args)
225 ReplyToCommand(client, "[SM] Usage: sm_csay <message>");
226 return Plugin_Handled;
229 decl String:text[192];
230 GetCmdArgString(text, sizeof(text));
233 GetClientName(client, name, sizeof(name));
235 PrintCenterTextAll("%s: %s", name, text);
236 LogMessage("%L triggered sm_csay (text %s)", client, text);
238 return Plugin_Handled;
241 public Action:Command_SmHsay(client, args)
245 ReplyToCommand(client, "[SM] Usage: sm_hsay <message>");
246 return Plugin_Handled;
249 decl String:text[192];
250 GetCmdArgString(text, sizeof(text));
252 decl String:name[64];
253 GetClientName(client, name, sizeof(name));
255 SendHintToAll("%s: %s", name, text);
256 LogMessage("%L triggered sm_hsay (text %s)", client, text);
258 return Plugin_Handled;
261 public Action:Command_SmTsay(client, args)
265 ReplyToCommand(client, "[SM] Usage: sm_tsay <message>");
266 return Plugin_Handled;
269 decl String:text[192], String:colorStr[16];
270 GetCmdArgString(text, sizeof(text));
272 new len = BreakString(text, colorStr, 16);
274 decl String:name[64];
275 GetClientName(client, name, sizeof(name));
277 new color = FindColor(colorStr);
280 SendDialogToAll(_, "%s: %s", name, text);
282 SendDialogToAll(color, "%s: %s", name, text[len]);
284 LogMessage("%L triggered sm_tsay (text %s)", client, text);
286 return Plugin_Handled;
289 public Action:Command_SmChat(client, args)
293 ReplyToCommand(client, "[SM] Usage: sm_chat <message>");
294 return Plugin_Handled;
297 decl String:text[192];
298 GetCmdArgString(text, sizeof(text));
300 decl String:name[64];
301 GetClientName(client, name, sizeof(name));
303 SendChatToAdmins(name, text);
304 LogMessage("%L triggered sm_chat (text %s)", client, text);
306 return Plugin_Handled;
309 public Action:Command_SmPsay(client, args)
313 ReplyToCommand(client, "[SM] Usage: sm_psay <name or #userid> <message>");
314 return Plugin_Handled;
317 decl String:text[192], String:arg[64], String:message[192];
318 GetCmdArgString(text, sizeof(text));
320 new len = BreakString(text, arg, sizeof(arg));
321 BreakString(text[len], message, sizeof(message));
323 new target = FindTarget(client, arg, true, false);
326 return Plugin_Handled;
328 decl String:name[64], String:name2[64];
329 GetClientName(client, name, sizeof(name));
330 GetClientName(target, name2, sizeof(name2));
334 PrintToChat(client, "\x04(Private: %s) %s: \x01%s", name2, name, message);
335 PrintToChat(target, "\x04(Private: %s) %s: \x01%s", name2, name, message);
339 PrintToChat(client, "(Private: %s) %s: %s", name2, name, message);
340 PrintToChat(target, "(Private: %s) %s: %s", name2, name, message);
343 LogMessage("%L triggered sm_psay to %L (text %s)", client, target, message);
345 return Plugin_Handled;
348 public Action:Command_SmMsay(client, args)
352 ReplyToCommand(client, "[SM] Usage: sm_msay <message>");
353 return Plugin_Handled;
356 decl String:text[192];
357 GetCmdArgString(text, sizeof(text));
359 decl String:name[64];
360 GetClientName(client, name, sizeof(name));
362 SendPanelToAll(name, text);
364 LogMessage("%L triggered sm_msay (text %s)", client, text);
366 return Plugin_Handled;
369 bool:CheckAdminForChat(client)
371 new AdminId:aid = GetUserAdmin(client);
373 if (aid == INVALID_ADMIN_ID)
378 return GetAdminFlag(aid, Admin_Chat, Access_Effective);
381 FindColor(String:color[])
383 for (new i = 0; i < 13; i++)
385 if (strcmp(color, g_ColorNames[i], false) == 0)
392 SendChatToAll(String:name[], String:message[])
396 PrintToChatAll("\x04(ALL) %s: \x01%s", name, message);
400 PrintToChatAll("(ALL) %s: %s", name, message);
404 SendChatToAdmins(String:name[], String:message[])
406 new iMaxClients = GetMaxClients();
408 for (new i = 1; i <= iMaxClients; i++)
410 if (IsClientInGame(i))
412 if (CheckAdminForChat(i))
416 PrintToChat(i, "\x04(ADMINS) %s: \x01%s", name, message);
420 PrintToChat(i, "(ADMINS) %s: %s", name, message);
427 SendHintToAll(String:text[], any:...)
429 new String:message[192];
430 VFormat(message, 191, text, 2);
432 new iLen = strlen(message);
438 for (new i = 0; i < iLen; i++)
440 if((message[i] == ' ' && iLastAdded > 30 && (iLen - i) > 10) || ((GetNextSpaceCount(text, i + 1) + iLastAdded) > 34))
450 new Handle:hHintMessage = StartMessageAll("HintText");
451 BfWriteByte(hHintMessage, -1);
452 BfWriteString(hHintMessage, message);
456 GetNextSpaceCount(String:text[], iCurIndex)
459 new iLen = strlen(text);
461 for (new i = iCurIndex; i < iLen; i++)
472 SendDialogToAll(color = 0, String:text[], any:...)
474 new String:message[100];
475 VFormat(message, sizeof(message), text, 3);
477 new MaxClients = GetMaxClients();
478 for(new i = 1; i < MaxClients; i++)
480 if(IsClientInGame(i))
482 new Handle:kv = CreateKeyValues("Stuff", "title", message);
483 KvSetColor(kv, "color", g_Colors[color][0], g_Colors[color][1], g_Colors[color][2], 255);
484 KvSetNum(kv, "level", 1);
485 KvSetNum(kv, "time", 10);
487 CreateDialog(i, kv, DialogType_Msg);
494 SendPanelToAll(String:name[], String:message[])
496 decl String:title[100];
497 Format(title, 64, "%s:", name);
499 ReplaceString(message, 192, "\\n", "\n");
501 new Handle:mSayPanel = CreatePanel();
502 SetPanelTitle(mSayPanel, title);
503 DrawPanelItem(mSayPanel, "", ITEMDRAW_SPACER);
504 DrawPanelText(mSayPanel, message);
505 DrawPanelItem(mSayPanel, "", ITEMDRAW_SPACER);
507 SetPanelCurrentKey(mSayPanel, 10);
508 DrawPanelItem(mSayPanel, "Exit", ITEMDRAW_CONTROL);
510 new MaxClients = GetMaxClients();
511 for(new i = 1; i < MaxClients; i++)
513 if(IsClientInGame(i) && !IsFakeClient(i))
515 SendPanelToClient(mSayPanel, i, Handler_DoNothing, 10);
519 CloseHandle(mSayPanel);
522 public Handler_DoNothing(Handle:menu, MenuAction:action, param1, param2)