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 new 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");
52 g_Cvar_Chatmode = CreateConVar("sm_chat_mode", "1", "Allows player's to send messages to admin chat.", 0, true, 0.0, true, 1.0);
53 g_Cvar_Psaymode = CreateConVar("sm_psay_mode", "0", "Allows player's to use psay 'say @@' alias.", 0, true, 0.0, true, 1.0);
55 RegConsoleCmd("say", Command_SayChat);
56 RegConsoleCmd("say_team", Command_SayAdmin);
57 RegAdminCmd("sm_say", Command_SmSay, ADMFLAG_CHAT, "sm_say <message> - sends message to all players");
58 RegAdminCmd("sm_csay", Command_SmCsay, ADMFLAG_CHAT, "sm_csay <message> - sends centered message to all players");
59 //RegAdminCmd("sm_hsay", Command_SmHsay, ADMFLAG_CHAT, "sm_hsay <message> - sends hint message to all players");
60 RegAdminCmd("sm_tsay", Command_SmTsay, ADMFLAG_CHAT, "sm_tsay [color] <message> - sends top-left message to all players");
61 RegAdminCmd("sm_chat", Command_SmChat, ADMFLAG_CHAT, "sm_chat <message> - sends message to admins");
62 RegAdminCmd("sm_psay", Command_SmPsay, ADMFLAG_CHAT, "sm_psay <name or #userid> <message> - sends private message");
63 RegAdminCmd("sm_msay", Command_SmMsay, ADMFLAG_CHAT, "sm_msay <message> - sends message as a menu panel");
65 decl String:modname[64];
66 GetGameFolderName(modname, sizeof(modname));
68 if (strcmp(modname, "cstrike") == 0)
71 RegAdminCmd("sm_hsay", Command_SmHsay, ADMFLAG_CHAT, "sm_hsay <message> - sends hint message to all players");
75 if (strcmp(modname, "ins") == 0)
77 RegConsoleCmd("say2", Command_SayChat);
83 public Action:Command_SayChat(client, args)
85 decl String:text[192];
86 GetCmdArgString(text, sizeof(text));
89 if (text[strlen(text)-1] == '"')
91 text[strlen(text)-1] = '\0';
102 if (text[startidx] != '@')
103 return Plugin_Continue;
107 if (text[startidx+1] == '@')
111 if (text[startidx+2] == '@')
115 decl String:message[192];
116 strcopy(message, 192, text[startidx+msgStart]);
118 decl String:name[64];
119 GetClientName(client, name, sizeof(name));
121 if (msgStart == 1 && CheckAdminForChat(client)) // sm_say alias
123 SendChatToAll(name, message);
124 LogMessage("%L triggered sm_say (text %s)", client, message);
126 else if (msgStart == 3 && CheckAdminForChat(client)) // sm_csay alias
128 PrintCenterTextAll("%s: %s", name, message);
129 LogMessage("%L triggered sm_csay (text %s)", client, text);
131 else if (msgStart == 2 && (CheckAdminForChat(client) || GetConVarBool(g_Cvar_Psaymode))) // sm_psay alias
135 new len = BreakString(message, arg, sizeof(arg));
136 new target = FindTarget(client, arg, true, false);
139 return Plugin_Handled;
141 decl String:name2[64];
142 GetClientName(target, name2, sizeof(name2));
146 PrintToChat(client, "\x04(Private to %s) %s: \x01%s", name2, name, message[len]);
147 PrintToChat(target, "\x04(Private to %s) %s: \x01%s", name2, name, message[len]);
151 PrintToChat(client, "(Private to %s) %s: %s", name2, name, message[len]);
152 PrintToChat(target, "(Private to %s) %s: %s", name2, name, message[len]);
155 LogMessage("%L triggered sm_psay to %L (text %s)", client, target, message);
158 return Plugin_Continue;
160 return Plugin_Handled;
163 public Action:Command_SayAdmin(client, args)
165 if (!CheckAdminForChat(client) && !GetConVarBool(g_Cvar_Chatmode))
166 return Plugin_Continue;
168 decl String:text[192];
169 GetCmdArgString(text, sizeof(text));
172 if (text[strlen(text)-1] == '"')
174 text[strlen(text)-1] = '\0';
185 if (text[startidx] != '@')
186 return Plugin_Continue;
188 decl String:message[192];
189 strcopy(message, 192, text[startidx+1]);
191 decl String:name[64];
192 GetClientName(client, name, sizeof(name));
194 SendChatToAdmins(name, message);
195 LogMessage("%L triggered sm_chat (text %s)", client, message);
197 return Plugin_Handled;
200 public Action:Command_SmSay(client, args)
204 ReplyToCommand(client, "[SM] Usage: sm_say <message>");
205 return Plugin_Handled;
208 decl String:text[192];
209 GetCmdArgString(text, sizeof(text));
211 decl String:name[64];
212 GetClientName(client, name, sizeof(name));
214 SendChatToAll(name, text);
215 LogMessage("%L triggered sm_say (text %s)", client, text);
217 return Plugin_Handled;
220 public Action:Command_SmCsay(client, args)
224 ReplyToCommand(client, "[SM] Usage: sm_csay <message>");
225 return Plugin_Handled;
228 decl String:text[192];
229 GetCmdArgString(text, sizeof(text));
232 GetClientName(client, name, sizeof(name));
234 PrintCenterTextAll("%s: %s", name, text);
235 LogMessage("%L triggered sm_csay (text %s)", client, text);
237 return Plugin_Handled;
240 public Action:Command_SmHsay(client, args)
244 ReplyToCommand(client, "[SM] Usage: sm_hsay <message>");
245 return Plugin_Handled;
248 decl String:text[192];
249 GetCmdArgString(text, sizeof(text));
251 decl String:name[64];
252 GetClientName(client, name, sizeof(name));
254 SendHintToAll("%s: %s", name, text);
255 LogMessage("%L triggered sm_hsay (text %s)", client, text);
257 return Plugin_Handled;
260 public Action:Command_SmTsay(client, args)
264 ReplyToCommand(client, "[SM] Usage: sm_tsay <message>");
265 return Plugin_Handled;
268 decl String:text[192], String:colorStr[16];
269 GetCmdArgString(text, sizeof(text));
271 new len = BreakString(text, colorStr, 16);
273 decl String:name[64];
274 GetClientName(client, name, sizeof(name));
276 new color = FindColor(colorStr);
279 SendDialogToAll(_, "%s: %s", name, text);
281 SendDialogToAll(color, "%s: %s", name, text[len]);
283 LogMessage("%L triggered sm_tsay (text %s)", client, text);
285 return Plugin_Handled;
288 public Action:Command_SmChat(client, args)
292 ReplyToCommand(client, "[SM] Usage: sm_chat <message>");
293 return Plugin_Handled;
296 decl String:text[192];
297 GetCmdArgString(text, sizeof(text));
299 decl String:name[64];
300 GetClientName(client, name, sizeof(name));
302 SendChatToAdmins(name, text);
303 LogMessage("%L triggered sm_chat (text %s)", client, text);
305 return Plugin_Handled;
308 public Action:Command_SmPsay(client, args)
312 ReplyToCommand(client, "[SM] Usage: sm_psay <name or #userid> <message>");
313 return Plugin_Handled;
316 decl String:text[192], String:arg[64], String:message[192];
317 GetCmdArgString(text, sizeof(text));
319 new len = BreakString(text, arg, sizeof(arg));
320 BreakString(text[len], message, sizeof(message));
322 new target = FindTarget(client, arg, true, false);
325 return Plugin_Handled;
327 decl String:name[64], String:name2[64];
328 GetClientName(client, name, sizeof(name));
329 GetClientName(target, name2, sizeof(name2));
333 PrintToChat(client, "\x04(Private: %s) %s: \x01%s", name2, name, message);
334 PrintToChat(target, "\x04(Private: %s) %s: \x01%s", name2, name, message);
338 PrintToChat(client, "(Private: %s) %s: %s", name2, name, message);
339 PrintToChat(target, "(Private: %s) %s: %s", name2, name, message);
342 LogMessage("%L triggered sm_psay to %L (text %s)", client, target, message);
344 return Plugin_Handled;
347 public Action:Command_SmMsay(client, args)
351 ReplyToCommand(client, "[SM] Usage: sm_msay <message>");
352 return Plugin_Handled;
355 decl String:text[192];
356 GetCmdArgString(text, sizeof(text));
358 decl String:name[64];
359 GetClientName(client, name, sizeof(name));
361 SendPanelToAll(name, text);
363 LogMessage("%L triggered sm_msay (text %s)", client, text);
365 return Plugin_Handled;
368 bool:CheckAdminForChat(client)
370 new AdminId:aid = GetUserAdmin(client);
372 if (aid == INVALID_ADMIN_ID)
377 return GetAdminFlag(aid, Admin_Chat, Access_Effective);
380 FindColor(String:color[])
382 for (new i = 0; i < 13; i++)
384 if (strcmp(color, g_ColorNames[i], false) == 0)
391 SendChatToAll(String:name[], String:message[])
395 PrintToChatAll("\x04(ALL) %s: \x01%s", name, message);
399 PrintToChatAll("(ALL) %s: %s", name, message);
403 SendChatToAdmins(String:name[], String:message[])
405 new iMaxClients = GetMaxClients();
407 for (new i = 1; i <= iMaxClients; i++)
409 if (IsClientInGame(i))
411 if (CheckAdminForChat(i))
415 PrintToChat(i, "\x04(ADMINS) %s: \x01%s", name, message);
419 PrintToChat(i, "(ADMINS) %s: %s", name, message);
426 SendHintToAll(String:text[], any:...)
428 new String:message[192];
429 VFormat(message, 191, text, 2);
431 new iLen = strlen(message);
437 for (new i = 0; i < iLen; i++)
439 if((message[i] == ' ' && iLastAdded > 30 && (iLen - i) > 10) || ((GetNextSpaceCount(text, i + 1) + iLastAdded) > 34))
449 new Handle:hHintMessage = StartMessageAll("HintText");
450 BfWriteByte(hHintMessage, -1);
451 BfWriteString(hHintMessage, message);
455 GetNextSpaceCount(String:text[], iCurIndex)
458 new iLen = strlen(text);
460 for (new i = iCurIndex; i < iLen; i++)
471 SendDialogToAll(color = 0, String:text[], any:...)
473 new String:message[100];
474 VFormat(message, sizeof(message), text, 3);
476 new MaxClients = GetMaxClients();
477 for(new i = 1; i < MaxClients; i++)
479 if(IsClientInGame(i))
481 new Handle:kv = CreateKeyValues("Stuff", "title", message);
482 KvSetColor(kv, "color", g_Colors[color][0], g_Colors[color][1], g_Colors[color][2], 255);
483 KvSetNum(kv, "level", 1);
484 KvSetNum(kv, "time", 10);
486 CreateDialog(i, kv, DialogType_Msg);
493 SendPanelToAll(String:name[], String:message[])
495 decl String:title[100];
496 Format(title, 64, "%s:", name);
498 ReplaceString(message, 192, "\\n", "\n");
500 new Handle:mSayPanel = CreatePanel();
501 SetPanelTitle(mSayPanel, title);
502 DrawPanelItem(mSayPanel, "", ITEMDRAW_SPACER);
503 DrawPanelText(mSayPanel, message);
504 DrawPanelItem(mSayPanel, "", ITEMDRAW_SPACER);
506 SetPanelCurrentKey(mSayPanel, 10);
507 DrawPanelItem(mSayPanel, "Exit", ITEMDRAW_CONTROL);
509 new MaxClients = GetMaxClients();
510 for(new i = 1; i < MaxClients; i++)
512 if(IsClientInGame(i) && !IsFakeClient(i))
514 SendPanelToClient(mSayPanel, i, Handler_DoNothing, 10);
518 CloseHandle(mSayPanel);
521 public Handler_DoNothing(Handle:menu, MenuAction:action, param1, param2)