plugins/basechat.sp
author Ruben Gonzalez <drifter01620@gmail.com>
Thu May 22 09:49:27 2014 -0400 (2014-05-22)
changeset 4378 568f4497ef4a
parent 4298 a9ea10a66000
permissions -rw-r--r--
Update CS:GO team score gamedata.
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod Basic Chat Plugin
     5  * Implements basic communication commands.
     6  *
     7  * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
     8  * =============================================================================
     9  *
    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.
    13  * 
    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
    17  * details.
    18  *
    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/>.
    21  *
    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>.
    30  *
    31  * Version: $Id$
    32  */
    33 
    34 #pragma semicolon 1
    35 
    36 #include <sourcemod>
    37 
    38 public Plugin:myinfo = 
    39 {
    40 	name = "Basic Chat",
    41 	author = "AlliedModders LLC",
    42 	description = "Basic Communication Commands",
    43 	version = SOURCEMOD_VERSION,
    44 	url = "http://www.sourcemod.net/"
    45 };
    46 
    47 #define CHAT_SYMBOL '@'
    48 
    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}};
    51 
    52 new Handle:g_Cvar_Chatmode = INVALID_HANDLE;
    53 
    54 new EngineVersion:g_GameEngine = Engine_Unknown;
    55 
    56 public OnPluginStart()
    57 {
    58 	LoadTranslations("common.phrases");
    59 	
    60 	g_GameEngine = GetEngineVersion();
    61 
    62 	g_Cvar_Chatmode = CreateConVar("sm_chat_mode", "1", "Allows player's to send messages to admin chat.", 0, true, 0.0, true, 1.0);
    63 
    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 	
    67 	/* HintText does not work on Dark Messiah */
    68 	if (g_GameEngine != Engine_DarkMessiah)
    69 	{
    70 		RegAdminCmd("sm_hsay", Command_SmHsay, ADMFLAG_CHAT, "sm_hsay <message> - sends hint message to all players");	
    71 	}
    72 	
    73 	RegAdminCmd("sm_tsay", Command_SmTsay, ADMFLAG_CHAT, "sm_tsay [color] <message> - sends top-left message to all players");
    74 	RegAdminCmd("sm_chat", Command_SmChat, ADMFLAG_CHAT, "sm_chat <message> - sends message to admins");
    75 	RegAdminCmd("sm_psay", Command_SmPsay, ADMFLAG_CHAT, "sm_psay <name or #userid> <message> - sends private message");
    76 	RegAdminCmd("sm_msay", Command_SmMsay, ADMFLAG_CHAT, "sm_msay <message> - sends message as a menu panel");
    77 }
    78 
    79 public Action:OnClientSayCommand(client, const String:command[], const String:sArgs[])
    80 {
    81 	new startidx;
    82 	if (sArgs[startidx] != CHAT_SYMBOL)
    83 		return Plugin_Continue;
    84 	
    85 	startidx++;
    86 	
    87 	if (strcmp(command, "say", false) == 0)
    88 	{
    89 		if (sArgs[startidx] != CHAT_SYMBOL) // sm_say alias
    90 		{
    91 			if (!CheckCommandAccess(client, "sm_say", ADMFLAG_CHAT))
    92 			{
    93 				return Plugin_Continue;
    94 			}
    95 			
    96 			SendChatToAll(client, sArgs[startidx]);
    97 			LogAction(client, -1, "\"%L\" triggered sm_say (text %s)", client, sArgs[startidx]);
    98 			
    99 			return Plugin_Stop;
   100 		}
   101 		
   102 		startidx++;
   103 
   104 		if (sArgs[startidx] != CHAT_SYMBOL) // sm_psay alias
   105 		{
   106 			if (!CheckCommandAccess(client, "sm_psay", ADMFLAG_CHAT))
   107 			{
   108 				return Plugin_Continue;
   109 			}
   110 			
   111 			decl String:arg[64];
   112 			
   113 			new len = BreakString(sArgs[startidx], arg, sizeof(arg));
   114 			new target = FindTarget(client, arg, true, false);
   115 			
   116 			if (target == -1 || len == -1)
   117 				return Plugin_Stop;
   118 			
   119 			SendPrivateChat(client, target, sArgs[startidx+len]);
   120 			
   121 			return Plugin_Stop;
   122 		}
   123 		
   124 		startidx++;
   125 		
   126 		// sm_csay alias
   127 		if (!CheckCommandAccess(client, "sm_csay", ADMFLAG_CHAT))
   128 		{
   129 			return Plugin_Continue;
   130 		}
   131 		
   132 		DisplayCenterTextToAll(client, sArgs[startidx]);
   133 		LogAction(client, -1, "\"%L\" triggered sm_csay (text %s)", client, sArgs[startidx]);
   134 		
   135 		return Plugin_Stop;
   136 	}
   137 	else if (strcmp(command, "say_team", false) == 0 || strcmp(command, "say_squad", false) == 0)
   138 	{
   139 		if (!CheckCommandAccess(client, "sm_chat", ADMFLAG_CHAT) && !GetConVarBool(g_Cvar_Chatmode))
   140 		{
   141 			return Plugin_Continue;
   142 		}
   143 		
   144 		SendChatToAdmins(client, sArgs[startidx]);
   145 		LogAction(client, -1, "\"%L\" triggered sm_chat (text %s)", client, sArgs[startidx]);
   146 		
   147 		return Plugin_Stop;
   148 	}
   149 	
   150 	return Plugin_Continue;
   151 }
   152 
   153 public Action:Command_SmSay(client, args)
   154 {
   155 	if (args < 1)
   156 	{
   157 		ReplyToCommand(client, "[SM] Usage: sm_say <message>");
   158 		return Plugin_Handled;	
   159 	}
   160 	
   161 	decl String:text[192];
   162 	GetCmdArgString(text, sizeof(text));
   163 
   164 	SendChatToAll(client, text);
   165 	LogAction(client, -1, "\"%L\" triggered sm_say (text %s)", client, text);
   166 	
   167 	return Plugin_Handled;		
   168 }
   169 
   170 public Action:Command_SmCsay(client, args)
   171 {
   172 	if (args < 1)
   173 	{
   174 		ReplyToCommand(client, "[SM] Usage: sm_csay <message>");
   175 		return Plugin_Handled;	
   176 	}
   177 	
   178 	decl String:text[192];
   179 	GetCmdArgString(text, sizeof(text));
   180 	
   181 	DisplayCenterTextToAll(client, text);
   182 	
   183 	LogAction(client, -1, "\"%L\" triggered sm_csay (text %s)", client, text);
   184 	
   185 	return Plugin_Handled;		
   186 }
   187 
   188 public Action:Command_SmHsay(client, args)
   189 {
   190 	if (args < 1)
   191 	{
   192 		ReplyToCommand(client, "[SM] Usage: sm_hsay <message>");
   193 		return Plugin_Handled;  
   194 	}
   195 	
   196 	decl String:text[192];
   197 	GetCmdArgString(text, sizeof(text));
   198  
   199 	decl String:nameBuf[MAX_NAME_LENGTH];
   200 	
   201 	for (new i = 1; i <= MaxClients; i++)
   202 	{
   203 		if (!IsClientInGame(i) || IsFakeClient(i))
   204 		{
   205 			continue;
   206 		}
   207 		FormatActivitySource(client, i, nameBuf, sizeof(nameBuf));
   208 		PrintHintText(i, "%s: %s", nameBuf, text);
   209 	}
   210 	
   211 	LogAction(client, -1, "\"%L\" triggered sm_hsay (text %s)", client, text);
   212 	
   213 	return Plugin_Handled;	
   214 }
   215 
   216 public Action:Command_SmTsay(client, args)
   217 {
   218 	if (args < 1)
   219 	{
   220 		ReplyToCommand(client, "[SM] Usage: sm_tsay <message>");
   221 		return Plugin_Handled;  
   222 	}
   223 	
   224 	decl String:text[192], String:colorStr[16];
   225 	GetCmdArgString(text, sizeof(text));
   226 	
   227 	new len = BreakString(text, colorStr, 16);
   228 		
   229 	new color = FindColor(colorStr);
   230 	new String:nameBuf[MAX_NAME_LENGTH];
   231 	
   232 	if (color == -1)
   233 	{
   234 		color = 0;
   235 		len = 0;
   236 	}
   237 	
   238 	for (new i = 1; i <= MaxClients; i++)
   239 	{
   240 		if (!IsClientInGame(i) || IsFakeClient(i))
   241 		{
   242 			continue;
   243 		}
   244 		FormatActivitySource(client, i, nameBuf, sizeof(nameBuf));
   245 		SendDialogToOne(i, color, "%s: %s", nameBuf, text[len]);
   246 	}
   247 
   248 	LogAction(client, -1, "\"%L\" triggered sm_tsay (text %s)", client, text);
   249 	
   250 	return Plugin_Handled;	
   251 }
   252 
   253 public Action:Command_SmChat(client, args)
   254 {
   255 	if (args < 1)
   256 	{
   257 		ReplyToCommand(client, "[SM] Usage: sm_chat <message>");
   258 		return Plugin_Handled;	
   259 	}	
   260 	
   261 	decl String:text[192];
   262 	GetCmdArgString(text, sizeof(text));
   263 
   264 	SendChatToAdmins(client, text);
   265 	LogAction(client, -1, "\"%L\" triggered sm_chat (text %s)", client, text);
   266 	
   267 	return Plugin_Handled;	
   268 }
   269 
   270 public Action:Command_SmPsay(client, args)
   271 {
   272 	if (args < 2)
   273 	{
   274 		ReplyToCommand(client, "[SM] Usage: sm_psay <name or #userid> <message>");
   275 		return Plugin_Handled;	
   276 	}	
   277 	
   278 	decl String:text[192], String:arg[64], String:message[192];
   279 	GetCmdArgString(text, sizeof(text));
   280 
   281 	new len = BreakString(text, arg, sizeof(arg));
   282 	BreakString(text[len], message, sizeof(message));
   283 	
   284 	new target = FindTarget(client, arg, true, false);
   285 		
   286 	if (target == -1)
   287 		return Plugin_Handled;	
   288 	
   289 	SendPrivateChat(client, target, message);
   290 	
   291 	return Plugin_Handled;	
   292 }
   293 
   294 public Action:Command_SmMsay(client, args)
   295 {
   296 	if (args < 1)
   297 	{
   298 		ReplyToCommand(client, "[SM] Usage: sm_msay <message>");
   299 		return Plugin_Handled;	
   300 	}
   301 	
   302 	decl String:text[192];
   303 	GetCmdArgString(text, sizeof(text));
   304 
   305 	SendPanelToAll(client, text);
   306 
   307 	LogAction(client, -1, "\"%L\" triggered sm_msay (text %s)", client, text);
   308 	
   309 	return Plugin_Handled;		
   310 }
   311 
   312 FindColor(String:color[])
   313 {
   314 	for (new i = 0; i < 13; i++)
   315 	{
   316 		if (strcmp(color, g_ColorNames[i], false) == 0)
   317 			return i;
   318 	}
   319 	
   320 	return -1;
   321 }
   322 
   323 SendChatToAll(client, const String:message[])
   324 {
   325 	new String:nameBuf[MAX_NAME_LENGTH];
   326 	
   327 	for (new i = 1; i <= MaxClients; i++)
   328 	{
   329 		if (!IsClientInGame(i) || IsFakeClient(i))
   330 		{
   331 			continue;
   332 		}
   333 		FormatActivitySource(client, i, nameBuf, sizeof(nameBuf));
   334 		
   335 		PrintToChat(i, "\x04(ALL) %s: \x01%s", nameBuf, message);
   336 	}
   337 }
   338 
   339 DisplayCenterTextToAll(client, const String:message[])
   340 {
   341 	new String:nameBuf[MAX_NAME_LENGTH];
   342 	
   343 	for (new i = 1; i <= MaxClients; i++)
   344 	{
   345 		if (!IsClientInGame(i) || IsFakeClient(i))
   346 		{
   347 			continue;
   348 		}
   349 		FormatActivitySource(client, i, nameBuf, sizeof(nameBuf));
   350 		PrintCenterText(i, "%s: %s", nameBuf, message);
   351 	}
   352 }
   353 
   354 SendChatToAdmins(from, const String:message[])
   355 {
   356 	new fromAdmin = CheckCommandAccess(from, "sm_chat", ADMFLAG_CHAT);
   357 	for (new i = 1; i <= MaxClients; i++)
   358 	{
   359 		if (IsClientInGame(i) && (from == i || CheckCommandAccess(i, "sm_chat", ADMFLAG_CHAT)))
   360 		{
   361 			PrintToChat(i, "\x04(%sADMINS) %N: \x01%s", fromAdmin ? "" : "TO ", from, message);
   362 		}	
   363 	}
   364 }
   365 
   366 SendDialogToOne(client, color, const String:text[], any:...)
   367 {
   368 	new String:message[100];
   369 	VFormat(message, sizeof(message), text, 4);	
   370 	
   371 	new Handle:kv = CreateKeyValues("Stuff", "title", message);
   372 	KvSetColor(kv, "color", g_Colors[color][0], g_Colors[color][1], g_Colors[color][2], 255);
   373 	KvSetNum(kv, "level", 1);
   374 	KvSetNum(kv, "time", 10);
   375 	
   376 	CreateDialog(client, kv, DialogType_Msg);
   377 	
   378 	CloseHandle(kv);	
   379 }
   380 
   381 SendPrivateChat(client, target, const String:message[])
   382 {
   383 	if (!client)
   384 	{
   385 		PrintToServer("(Private to %N) %N: %s", target, client, message);
   386 	}
   387 	else if (target != client)
   388 	{
   389 		PrintToChat(client, "\x04(Private to %N) %N: \x01%s", target, client, message);
   390 	}
   391 
   392 	PrintToChat(target, "\x04(Private to %N) %N: \x01%s", target, client, message);
   393 	LogAction(client, -1, "\"%L\" triggered sm_psay to \"%L\" (text %s)", client, target, message);
   394 }
   395 
   396 SendPanelToAll(from, String:message[])
   397 {
   398 	decl String:title[100];
   399 	Format(title, 64, "%N:", from);
   400 	
   401 	ReplaceString(message, 192, "\\n", "\n");
   402 	
   403 	new Handle:mSayPanel = CreatePanel();
   404 	SetPanelTitle(mSayPanel, title);
   405 	DrawPanelItem(mSayPanel, "", ITEMDRAW_SPACER);
   406 	DrawPanelText(mSayPanel, message);
   407 	DrawPanelItem(mSayPanel, "", ITEMDRAW_SPACER);
   408 
   409 	SetPanelCurrentKey(mSayPanel, 10);
   410 	DrawPanelItem(mSayPanel, "Exit", ITEMDRAW_CONTROL);
   411 
   412 	for(new i = 1; i <= MaxClients; i++)
   413 	{
   414 		if(IsClientInGame(i) && !IsFakeClient(i))
   415 		{
   416 			SendPanelToClient(mSayPanel, i, Handler_DoNothing, 10);
   417 		}
   418 	}
   419 
   420 	CloseHandle(mSayPanel);
   421 }
   422 
   423 public Handler_DoNothing(Handle:menu, MenuAction:action, param1, param2)
   424 {
   425 	/* Do nothing */
   426 }