Switched to hinttext native and added sm_hsay back to non-CSS mods. Color is still CSS only.
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;
44 public OnPluginStart()
46 LoadTranslations("common.phrases");
48 g_Cvar_Chatmode = CreateConVar("sm_chat_mode", "1", "Allows player's to send messages to admin chat.", 0, true, 0.0, true, 1.0);
49 g_Cvar_Psaymode = CreateConVar("sm_psay_mode", "0", "Allows player's to use psay 'say @@' alias.", 0, true, 0.0, true, 1.0);
51 RegConsoleCmd("say", Command_SayChat);
52 RegConsoleCmd("say_team", Command_SayAdmin);
53 RegAdminCmd("sm_say", Command_SmSay, ADMFLAG_CHAT, "sm_say <message> - sends message to all players");
54 RegAdminCmd("sm_csay", Command_SmCsay, ADMFLAG_CHAT, "sm_csay <message> - sends centered message to all players");
55 RegAdminCmd("sm_hsay", Command_SmHsay, ADMFLAG_CHAT, "sm_hsay <message> - sends hint message to all players");
56 RegAdminCmd("sm_tsay", Command_SmTsay, ADMFLAG_CHAT, "sm_tsay [color] <message> - sends top-left message to all players");
57 RegAdminCmd("sm_chat", Command_SmChat, ADMFLAG_CHAT, "sm_chat <message> - sends message to admins");
58 RegAdminCmd("sm_psay", Command_SmPsay, ADMFLAG_CHAT, "sm_psay <name or #userid> <message> - sends private message");
59 RegAdminCmd("sm_msay", Command_SmMsay, ADMFLAG_CHAT, "sm_msay <message> - sends message as a menu panel");
61 decl String:modname[64];
62 GetGameFolderName(modname, sizeof(modname));
64 if (strcmp(modname, "cstrike") == 0)
70 public Action:Command_SayChat(client, args)
72 decl String:text[192];
73 GetCmdArgString(text, sizeof(text));
76 if (text[strlen(text)-1] == '"')
78 text[strlen(text)-1] = '\0';
82 if (text[startidx] != '@')
83 return Plugin_Continue;
87 if (text[startidx+1] == '@')
91 if (text[startidx+2] == '@')
95 decl String:message[192];
96 strcopy(message, 192, text[startidx+msgStart]);
99 GetClientName(client, name, sizeof(name));
101 if (msgStart == 1 && CheckAdminForChat(client)) // sm_say alias
103 SendChatToAll(name, message);
104 LogMessage("%L triggered sm_say (text %s)", client, message);
106 else if (msgStart == 3 && CheckAdminForChat(client)) // sm_csay alias
108 PrintCenterTextAll("%s: %s", name, message);
109 LogMessage("%L triggered sm_csay (text %s)", client, text);
111 else if (msgStart == 2 && (CheckAdminForChat(client) || GetConVarBool(g_Cvar_Psaymode))) // sm_psay alias
115 new len = BreakString(message, arg, sizeof(arg));
116 new target = FindTarget(client, arg, true, false);
119 return Plugin_Handled;
121 decl String:name2[64];
122 GetClientName(target, name2, sizeof(name2));
126 PrintToChat(client, "\x04(Private to %s) %s: \x01%s", name2, name, message[len]);
127 PrintToChat(target, "\x04(Private to %s) %s: \x01%s", name2, name, message[len]);
131 PrintToChat(client, "(Private to %s) %s: %s", name2, name, message[len]);
132 PrintToChat(target, "(Private to %s) %s: %s", name2, name, message[len]);
135 LogMessage("%L triggered sm_psay to %L (text %s)", client, target, message);
138 return Plugin_Continue;
140 return Plugin_Handled;
143 public Action:Command_SayAdmin(client, args)
145 if (!CheckAdminForChat(client) && !GetConVarBool(g_Cvar_Chatmode))
146 return Plugin_Continue;
148 decl String:text[192];
149 GetCmdArgString(text, sizeof(text));
152 if (text[strlen(text)-1] == '"')
154 text[strlen(text)-1] = '\0';
158 if (text[startidx] != '@')
159 return Plugin_Continue;
161 decl String:message[192];
162 strcopy(message, 192, text[startidx+1]);
164 decl String:name[64];
165 GetClientName(client, name, sizeof(name));
167 SendChatToAdmins(name, message);
168 LogMessage("%L triggered sm_chat (text %s)", client, message);
170 return Plugin_Handled;
173 public Action:Command_SmSay(client, args)
177 ReplyToCommand(client, "[SM] Usage: sm_say <message>");
178 return Plugin_Handled;
181 decl String:text[192];
182 GetCmdArgString(text, sizeof(text));
184 decl String:name[64];
185 GetClientName(client, name, sizeof(name));
187 SendChatToAll(name, text);
188 LogMessage("%L triggered sm_say (text %s)", client, text);
190 return Plugin_Handled;
193 public Action:Command_SmCsay(client, args)
197 ReplyToCommand(client, "[SM] Usage: sm_csay <message>");
198 return Plugin_Handled;
201 decl String:text[192];
202 GetCmdArgString(text, sizeof(text));
205 GetClientName(client, name, sizeof(name));
207 PrintCenterTextAll("%s: %s", name, text);
208 LogMessage("%L triggered sm_csay (text %s)", client, text);
210 return Plugin_Handled;
213 public Action:Command_SmHsay(client, args)
217 ReplyToCommand(client, "[SM] Usage: sm_hsay <message>");
218 return Plugin_Handled;
221 decl String:text[192];
222 GetCmdArgString(text, sizeof(text));
224 decl String:name[64];
225 GetClientName(client, name, sizeof(name));
227 PrintHintTextToAll("%s: %s", name, text);
228 LogMessage("%L triggered sm_hsay (text %s)", client, text);
230 return Plugin_Handled;
233 public Action:Command_SmTsay(client, args)
237 ReplyToCommand(client, "[SM] Usage: sm_tsay <message>");
238 return Plugin_Handled;
241 decl String:text[192], String:colorStr[16];
242 GetCmdArgString(text, sizeof(text));
244 new len = BreakString(text, colorStr, 16);
246 decl String:name[64];
247 GetClientName(client, name, sizeof(name));
249 new color = FindColor(colorStr);
252 SendDialogToAll(_, "%s: %s", name, text);
254 SendDialogToAll(color, "%s: %s", name, text[len]);
256 LogMessage("%L triggered sm_tsay (text %s)", client, text);
258 return Plugin_Handled;
261 public Action:Command_SmChat(client, args)
265 ReplyToCommand(client, "[SM] Usage: sm_chat <message>");
266 return Plugin_Handled;
269 decl String:text[192];
270 GetCmdArgString(text, sizeof(text));
272 decl String:name[64];
273 GetClientName(client, name, sizeof(name));
275 SendChatToAdmins(name, text);
276 LogMessage("%L triggered sm_chat (text %s)", client, text);
278 return Plugin_Handled;
281 public Action:Command_SmPsay(client, args)
285 ReplyToCommand(client, "[SM] Usage: sm_psay <name or #userid> <message>");
286 return Plugin_Handled;
289 decl String:text[192], String:arg[64], String:message[192];
290 GetCmdArgString(text, sizeof(text));
292 new len = BreakString(text, arg, sizeof(arg));
293 BreakString(text[len], message, sizeof(message));
295 new target = FindTarget(client, arg, true, false);
298 return Plugin_Handled;
300 decl String:name[64], String:name2[64];
301 GetClientName(client, name, sizeof(name));
302 GetClientName(target, name2, sizeof(name2));
306 PrintToChat(client, "\x04(Private: %s) %s: \x01%s", name2, name, message);
307 PrintToChat(target, "\x04(Private: %s) %s: \x01%s", name2, name, message);
311 PrintToChat(client, "(Private: %s) %s: %s", name2, name, message);
312 PrintToChat(target, "(Private: %s) %s: %s", name2, name, message);
315 LogMessage("%L triggered sm_psay to %L (text %s)", client, target, message);
317 return Plugin_Handled;
320 public Action:Command_SmMsay(client, args)
324 ReplyToCommand(client, "[SM] Usage: sm_msay <message>");
325 return Plugin_Handled;
328 decl String:text[192];
329 GetCmdArgString(text, sizeof(text));
331 decl String:name[64];
332 GetClientName(client, name, sizeof(name));
334 SendPanelToAll(name, text);
336 LogMessage("%L triggered sm_msay (text %s)", client, text);
338 return Plugin_Handled;
341 bool:CheckAdminForChat(client)
343 new AdminId:aid = GetUserAdmin(client);
345 if (aid == INVALID_ADMIN_ID)
350 return GetAdminFlag(aid, Admin_Chat, Access_Effective);
353 FindColor(String:color[])
355 for (new i = 0; i < 13; i++)
357 if (strcmp(color, g_ColorNames[i], false) == 0)
364 SendChatToAll(String:name[], String:message[])
368 PrintToChatAll("\x04(ALL) %s: \x01%s", name, message);
372 PrintToChatAll("(ALL) %s: %s", name, message);
376 SendChatToAdmins(String:name[], String:message[])
378 new iMaxClients = GetMaxClients();
380 for (new i = 1; i <= iMaxClients; i++)
382 if (IsClientInGame(i))
384 if (CheckAdminForChat(i))
388 PrintToChat(i, "\x04(ADMINS) %s: \x01%s", name, message);
392 PrintToChat(i, "(ADMINS) %s: %s", name, message);
399 SendDialogToAll(color = 0, String:text[], any:...)
401 new String:message[100];
402 VFormat(message, sizeof(message), text, 3);
404 new MaxClients = GetMaxClients();
405 for(new i = 1; i < MaxClients; i++)
407 if(IsClientInGame(i))
409 new Handle:kv = CreateKeyValues("Stuff", "title", message);
410 KvSetColor(kv, "color", g_Colors[color][0], g_Colors[color][1], g_Colors[color][2], 255);
411 KvSetNum(kv, "level", 1);
412 KvSetNum(kv, "time", 10);
414 CreateDialog(i, kv, DialogType_Msg);
421 SendPanelToAll(String:name[], String:message[])
423 decl String:title[100];
424 Format(title, 64, "%s:", name);
426 ReplaceString(message, 192, "\\n", "\n");
428 new Handle:mSayPanel = CreatePanel();
429 SetPanelTitle(mSayPanel, title);
430 DrawPanelItem(mSayPanel, "", ITEMDRAW_SPACER);
431 DrawPanelText(mSayPanel, message);
432 DrawPanelItem(mSayPanel, "", ITEMDRAW_SPACER);
434 SetPanelCurrentKey(mSayPanel, 10);
435 DrawPanelItem(mSayPanel, "Exit", ITEMDRAW_CONTROL);
437 new MaxClients = GetMaxClients();
438 for(new i = 1; i < MaxClients; i++)
440 if(IsClientInGame(i) && !IsFakeClient(i))
442 SendPanelToClient(mSayPanel, i, Handler_DoNothing, 10);
446 CloseHandle(mSayPanel);
449 public Handler_DoNothing(Handle:menu, MenuAction:action, param1, param2)