plugins/basechat.sp
branchsourcemod-1.1.0
changeset 2283 03a67e41afbc
parent 1951 c7b4237fff50
child 2287 017a725c9d17
     1.1 --- a/plugins/basechat.sp	Fri Mar 28 06:21:34 2008 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,459 +0,0 @@
     1.4 -/**
     1.5 - * vim: set ts=4 :
     1.6 - * =============================================================================
     1.7 - * SourceMod Basic Chat Plugin
     1.8 - * Implements basic communication commands.
     1.9 - *
    1.10 - * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
    1.11 - * =============================================================================
    1.12 - *
    1.13 - * This program is free software; you can redistribute it and/or modify it under
    1.14 - * the terms of the GNU General Public License, version 3.0, as published by the
    1.15 - * Free Software Foundation.
    1.16 - * 
    1.17 - * This program is distributed in the hope that it will be useful, but WITHOUT
    1.18 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.19 - * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    1.20 - * details.
    1.21 - *
    1.22 - * You should have received a copy of the GNU General Public License along with
    1.23 - * this program.  If not, see <http://www.gnu.org/licenses/>.
    1.24 - *
    1.25 - * As a special exception, AlliedModders LLC gives you permission to link the
    1.26 - * code of this program (as well as its derivative works) to "Half-Life 2," the
    1.27 - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    1.28 - * by the Valve Corporation.  You must obey the GNU General Public License in
    1.29 - * all respects for all other code used.  Additionally, AlliedModders LLC grants
    1.30 - * this exception to all derivative works.  AlliedModders LLC defines further
    1.31 - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    1.32 - * or <http://www.sourcemod.net/license.php>.
    1.33 - *
    1.34 - * Version: $Id$
    1.35 - */
    1.36 -
    1.37 -#pragma semicolon 1
    1.38 -
    1.39 -#include <sourcemod>
    1.40 -
    1.41 -public Plugin:myinfo = 
    1.42 -{
    1.43 -	name = "Basic Chat",
    1.44 -	author = "AlliedModders LLC",
    1.45 -	description = "Basic Communication Commands",
    1.46 -	version = SOURCEMOD_VERSION,
    1.47 -	url = "http://www.sourcemod.net/"
    1.48 -};
    1.49 -
    1.50 -#define CHAT_SYMBOL '@'
    1.51 -
    1.52 -new String:g_ColorNames[13][10] = {"White", "Red", "Green", "Blue", "Yellow", "Purple", "Cyan", "Orange", "Pink", "Olive", "Lime", "Violet", "Lightblue"};
    1.53 -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}};
    1.54 -
    1.55 -new Handle:g_Cvar_Chatmode = INVALID_HANDLE;
    1.56 -
    1.57 -new bool:g_DoColor = true;
    1.58 -
    1.59 -public OnPluginStart()
    1.60 -{
    1.61 -	LoadTranslations("common.phrases");
    1.62 -
    1.63 -	g_Cvar_Chatmode = CreateConVar("sm_chat_mode", "1", "Allows player's to send messages to admin chat.", 0, true, 0.0, true, 1.0);
    1.64 -
    1.65 -	RegConsoleCmd("say", Command_SayChat);
    1.66 -	RegConsoleCmd("say_team", Command_SayAdmin);		
    1.67 -	RegAdminCmd("sm_say", Command_SmSay, ADMFLAG_CHAT, "sm_say <message> - sends message to all players");
    1.68 -	RegAdminCmd("sm_csay", Command_SmCsay, ADMFLAG_CHAT, "sm_csay <message> - sends centered message to all players");
    1.69 -	RegAdminCmd("sm_hsay", Command_SmHsay, ADMFLAG_CHAT, "sm_hsay <message> - sends hint message to all players");
    1.70 -	RegAdminCmd("sm_tsay", Command_SmTsay, ADMFLAG_CHAT, "sm_tsay [color] <message> - sends top-left message to all players");
    1.71 -	RegAdminCmd("sm_chat", Command_SmChat, ADMFLAG_CHAT, "sm_chat <message> - sends message to admins");
    1.72 -	RegAdminCmd("sm_psay", Command_SmPsay, ADMFLAG_CHAT, "sm_psay <name or #userid> <message> - sends private message");
    1.73 -	RegAdminCmd("sm_msay", Command_SmMsay, ADMFLAG_CHAT, "sm_msay <message> - sends message as a menu panel");
    1.74 -	
    1.75 -	decl String:modname[64];
    1.76 -	GetGameFolderName(modname, sizeof(modname));
    1.77 -	
    1.78 -	if (strcmp(modname, "hl2mp") == 0)
    1.79 -	{
    1.80 -		g_DoColor = false;
    1.81 -	}
    1.82 -}
    1.83 -
    1.84 -public Action:Command_SayChat(client, args)
    1.85 -{	
    1.86 -	decl String:text[192];
    1.87 -	if (IsChatTrigger() || GetCmdArgString(text, sizeof(text)) < 1)
    1.88 -	{
    1.89 -		return Plugin_Continue;
    1.90 -	}
    1.91 -	
    1.92 -	new startidx;
    1.93 -	if (text[strlen(text)-1] == '"')
    1.94 -	{
    1.95 -		text[strlen(text)-1] = '\0';
    1.96 -		startidx = 1;
    1.97 -	}
    1.98 -	
    1.99 -	if (text[startidx] != CHAT_SYMBOL)
   1.100 -		return Plugin_Continue;
   1.101 -	
   1.102 -	new msgStart = 1;
   1.103 -	
   1.104 -	if (text[startidx+1] == CHAT_SYMBOL)
   1.105 -	{
   1.106 -		msgStart = 2;
   1.107 -		
   1.108 -		if (text[startidx+2] == CHAT_SYMBOL)
   1.109 -			msgStart = 3;
   1.110 -	}
   1.111 -	
   1.112 -	decl String:message[192];
   1.113 -	strcopy(message, 192, text[startidx+msgStart]);
   1.114 -	
   1.115 -	decl String:name[64];
   1.116 -	GetClientName(client, name, sizeof(name));
   1.117 -	
   1.118 -	if (msgStart == 1 && CheckCommandAccess(client, "sm_say", ADMFLAG_CHAT)) // sm_say alias
   1.119 -	{
   1.120 -		SendChatToAll(name, message);
   1.121 -		LogAction(client, -1, "%L triggered sm_say (text %s)", client, message);
   1.122 -	}
   1.123 -	else if (msgStart == 3 && CheckCommandAccess(client, "sm_csay", ADMFLAG_CHAT)) // sm_csay alias
   1.124 -	{
   1.125 -		PrintCenterTextAll("%s: %s", name, message);
   1.126 -		LogAction(client, -1, "%L triggered sm_csay (text %s)", client, text);		
   1.127 -	}	
   1.128 -	else if (msgStart == 2 && CheckCommandAccess(client, "sm_psay", ADMFLAG_CHAT)) // sm_psay alias
   1.129 -	{
   1.130 -		decl String:arg[64];
   1.131 -	
   1.132 -		new len = BreakString(message, arg, sizeof(arg));
   1.133 -		new target = FindTarget(client, arg, true, false);
   1.134 -		
   1.135 -		if (target == -1)
   1.136 -			return Plugin_Handled;
   1.137 -		
   1.138 -		decl String:name2[64];
   1.139 -		GetClientName(target, name2, sizeof(name2));
   1.140 -	
   1.141 -		if (g_DoColor)
   1.142 -		{
   1.143 -			PrintToChat(client, "\x04(Private to %s) %s: \x01%s", name2, name, message[len]);
   1.144 -			PrintToChat(target, "\x04(Private to %s) %s: \x01%s", name2, name, message[len]);
   1.145 -		}
   1.146 -		else
   1.147 -		{
   1.148 -			PrintToChat(client, "(Private to %s) %s: %s", name2, name, message[len]);
   1.149 -			PrintToChat(target, "(Private to %s) %s: %s", name2, name, message[len]);			
   1.150 -		}
   1.151 -
   1.152 -		LogAction(client, -1, "%L triggered sm_psay to %L (text %s)", client, target, message);		
   1.153 -	}
   1.154 -	else
   1.155 -		return Plugin_Continue;
   1.156 -	
   1.157 -	return Plugin_Handled;	
   1.158 -}
   1.159 -
   1.160 -public Action:Command_SayAdmin(client, args)
   1.161 -{
   1.162 -	if (!CheckCommandAccess(client, "sm_chat", ADMFLAG_CHAT) && !GetConVarBool(g_Cvar_Chatmode))
   1.163 -	{
   1.164 -		return Plugin_Continue;	
   1.165 -	}
   1.166 -	
   1.167 -	decl String:text[192];
   1.168 -	if (IsChatTrigger() || GetCmdArgString(text, sizeof(text)) < 1)
   1.169 -	{
   1.170 -		return Plugin_Continue;
   1.171 -	}
   1.172 -	
   1.173 -	new startidx;
   1.174 -	if (text[strlen(text)-1] == '"')
   1.175 -	{
   1.176 -		text[strlen(text)-1] = '\0';
   1.177 -		startidx = 1;
   1.178 -	}
   1.179 -	
   1.180 -	if (text[startidx] != CHAT_SYMBOL)
   1.181 -		return Plugin_Continue;
   1.182 -	
   1.183 -	decl String:message[192];
   1.184 -	strcopy(message, 192, text[startidx+1]);
   1.185 -
   1.186 -	decl String:name[64];
   1.187 -	GetClientName(client, name, sizeof(name));
   1.188 -	
   1.189 -	SendChatToAdmins(name, message);
   1.190 -	LogAction(client, -1, "%L triggered sm_chat (text %s)", client, message);
   1.191 -	
   1.192 -	return Plugin_Handled;	
   1.193 -}
   1.194 -
   1.195 -public Action:Command_SmSay(client, args)
   1.196 -{
   1.197 -	if (args < 1)
   1.198 -	{
   1.199 -		ReplyToCommand(client, "[SM] Usage: sm_say <message>");
   1.200 -		return Plugin_Handled;	
   1.201 -	}
   1.202 -	
   1.203 -	decl String:text[192];
   1.204 -	GetCmdArgString(text, sizeof(text));
   1.205 -
   1.206 -	decl String:name[64];
   1.207 -	GetClientName(client, name, sizeof(name));
   1.208 -			
   1.209 -	SendChatToAll(name, text);
   1.210 -	LogAction(client, -1, "%L triggered sm_say (text %s)", client, text);
   1.211 -	
   1.212 -	return Plugin_Handled;		
   1.213 -}
   1.214 -
   1.215 -public Action:Command_SmCsay(client, args)
   1.216 -{
   1.217 -	if (args < 1)
   1.218 -	{
   1.219 -		ReplyToCommand(client, "[SM] Usage: sm_csay <message>");
   1.220 -		return Plugin_Handled;	
   1.221 -	}
   1.222 -	
   1.223 -	decl String:text[192];
   1.224 -	GetCmdArgString(text, sizeof(text));
   1.225 -
   1.226 -	new String:name[64];
   1.227 -	GetClientName(client, name, sizeof(name));
   1.228 -	
   1.229 -	PrintCenterTextAll("%s: %s", name, text);
   1.230 -	LogAction(client, -1, "%L triggered sm_csay (text %s)", client, text);
   1.231 -	
   1.232 -	return Plugin_Handled;		
   1.233 -}
   1.234 -
   1.235 -public Action:Command_SmHsay(client, args)
   1.236 -{
   1.237 -	if (args < 1)
   1.238 -	{
   1.239 -		ReplyToCommand(client, "[SM] Usage: sm_hsay <message>");
   1.240 -		return Plugin_Handled;  
   1.241 -	}
   1.242 -    
   1.243 -	decl String:text[192];
   1.244 -	GetCmdArgString(text, sizeof(text));
   1.245 - 
   1.246 -	decl String:name[64];
   1.247 -	GetClientName(client, name, sizeof(name));
   1.248 -    
   1.249 -	PrintHintTextToAll("%s: %s", name, text);
   1.250 -	LogAction(client, -1, "%L triggered sm_hsay (text %s)", client, text);
   1.251 -    
   1.252 -	return Plugin_Handled;    
   1.253 -}
   1.254 -
   1.255 -public Action:Command_SmTsay(client, args)
   1.256 -{
   1.257 -	if (args < 1)
   1.258 -	{
   1.259 -		ReplyToCommand(client, "[SM] Usage: sm_tsay <message>");
   1.260 -		return Plugin_Handled;  
   1.261 -	}
   1.262 -    
   1.263 -	decl String:text[192], String:colorStr[16];
   1.264 -	GetCmdArgString(text, sizeof(text));
   1.265 -	
   1.266 -	new len = BreakString(text, colorStr, 16);
   1.267 - 
   1.268 -	decl String:name[64];
   1.269 -	GetClientName(client, name, sizeof(name));
   1.270 -		
   1.271 -	new color = FindColor(colorStr);
   1.272 -
   1.273 -	if (color == -1)    
   1.274 -		SendDialogToAll(_, "%s: %s", name, text);
   1.275 -	else
   1.276 -		SendDialogToAll(color, "%s: %s", name, text[len]);
   1.277 -
   1.278 -	LogAction(client, -1, "%L triggered sm_tsay (text %s)", client, text);
   1.279 -    
   1.280 -	return Plugin_Handled;    
   1.281 -}
   1.282 -
   1.283 -public Action:Command_SmChat(client, args)
   1.284 -{
   1.285 -	if (args < 1)
   1.286 -	{
   1.287 -		ReplyToCommand(client, "[SM] Usage: sm_chat <message>");
   1.288 -		return Plugin_Handled;	
   1.289 -	}	
   1.290 -	
   1.291 -	decl String:text[192];
   1.292 -	GetCmdArgString(text, sizeof(text));
   1.293 -
   1.294 -	decl String:name[64];
   1.295 -	GetClientName(client, name, sizeof(name));
   1.296 -	
   1.297 -	SendChatToAdmins(name, text);
   1.298 -	LogAction(client, -1, "%L triggered sm_chat (text %s)", client, text);
   1.299 -	
   1.300 -	return Plugin_Handled;	
   1.301 -}
   1.302 -
   1.303 -public Action:Command_SmPsay(client, args)
   1.304 -{
   1.305 -	if (args < 2)
   1.306 -	{
   1.307 -		ReplyToCommand(client, "[SM] Usage: sm_psay <name or #userid> <message>");
   1.308 -		return Plugin_Handled;	
   1.309 -	}	
   1.310 -	
   1.311 -	decl String:text[192], String:arg[64], String:message[192];
   1.312 -	GetCmdArgString(text, sizeof(text));
   1.313 -
   1.314 -	new len = BreakString(text, arg, sizeof(arg));
   1.315 -	BreakString(text[len], message, sizeof(message));
   1.316 -	
   1.317 -	new target = FindTarget(client, arg, true, false);
   1.318 -		
   1.319 -	if (target == -1)
   1.320 -		return Plugin_Handled;	
   1.321 -		
   1.322 -	decl String:name[64], String:name2[64];
   1.323 -	GetClientName(client, name, sizeof(name));
   1.324 -	GetClientName(target, name2, sizeof(name2));
   1.325 -
   1.326 -	if (g_DoColor)
   1.327 -	{
   1.328 -		PrintToChat(client, "\x04(Private: %s) %s: \x01%s", name2, name, message);
   1.329 -		PrintToChat(target, "\x04(Private: %s) %s: \x01%s", name2, name, message);
   1.330 -	}
   1.331 -	else
   1.332 -	{
   1.333 -		PrintToChat(client, "(Private: %s) %s: %s", name2, name, message);
   1.334 -		PrintToChat(target, "(Private: %s) %s: %s", name2, name, message);		
   1.335 -	}
   1.336 -
   1.337 -	LogAction(client, -1, "%L triggered sm_psay to %L (text %s)", client, target, message);
   1.338 -	
   1.339 -	return Plugin_Handled;	
   1.340 -}
   1.341 -
   1.342 -public Action:Command_SmMsay(client, args)
   1.343 -{
   1.344 -	if (args < 1)
   1.345 -	{
   1.346 -		ReplyToCommand(client, "[SM] Usage: sm_msay <message>");
   1.347 -		return Plugin_Handled;	
   1.348 -	}
   1.349 -	
   1.350 -	decl String:text[192];
   1.351 -	GetCmdArgString(text, sizeof(text));
   1.352 -
   1.353 -	decl String:name[64];
   1.354 -	GetClientName(client, name, sizeof(name));
   1.355 -		
   1.356 -	SendPanelToAll(name, text);
   1.357 -
   1.358 -	LogAction(client, -1, "%L triggered sm_msay (text %s)", client, text);
   1.359 -	
   1.360 -	return Plugin_Handled;		
   1.361 -}
   1.362 -
   1.363 -FindColor(String:color[])
   1.364 -{
   1.365 -	for (new i = 0; i < 13; i++)
   1.366 -	{
   1.367 -		if (strcmp(color, g_ColorNames[i], false) == 0)
   1.368 -			return i;
   1.369 -	}
   1.370 -	
   1.371 -	return -1;
   1.372 -}
   1.373 -
   1.374 -SendChatToAll(String:name[], String:message[])
   1.375 -{
   1.376 -	if (g_DoColor)
   1.377 -	{
   1.378 -		PrintToChatAll("\x04(ALL) %s: \x01%s", name, message);
   1.379 -	}
   1.380 -	else
   1.381 -	{
   1.382 -		PrintToChatAll("(ALL) %s: %s", name, message);
   1.383 -	}
   1.384 -}
   1.385 -
   1.386 -SendChatToAdmins(String:name[], String:message[])
   1.387 -{
   1.388 -	new iMaxClients = GetMaxClients();
   1.389 -	
   1.390 -	for (new i = 1; i <= iMaxClients; i++)
   1.391 -	{
   1.392 -		if (IsClientInGame(i))
   1.393 -		{
   1.394 -			if (CheckCommandAccess(i, "sm_chat", ADMFLAG_CHAT))
   1.395 -			{
   1.396 -				if (g_DoColor)
   1.397 -				{
   1.398 -					PrintToChat(i, "\x04(ADMINS) %s: \x01%s", name, message);
   1.399 -				}
   1.400 -				else
   1.401 -				{
   1.402 -					PrintToChat(i, "(ADMINS) %s: %s", name, message);
   1.403 -				}
   1.404 -			}
   1.405 -		}	
   1.406 -	}
   1.407 -}
   1.408 -
   1.409 -SendDialogToAll(color = 0, String:text[], any:...)
   1.410 -{
   1.411 -	new String:message[100];
   1.412 -	VFormat(message, sizeof(message), text, 3);	
   1.413 -	
   1.414 -	new MaxClients = GetMaxClients();
   1.415 -	for(new i = 1; i < MaxClients; i++)
   1.416 -	{
   1.417 -		if(IsClientInGame(i))
   1.418 -		{
   1.419 -			new Handle:kv = CreateKeyValues("Stuff", "title", message);
   1.420 -			KvSetColor(kv, "color", g_Colors[color][0], g_Colors[color][1], g_Colors[color][2], 255);
   1.421 -			KvSetNum(kv, "level", 1);
   1.422 -			KvSetNum(kv, "time", 10);
   1.423 -			
   1.424 -			CreateDialog(i, kv, DialogType_Msg);
   1.425 -			
   1.426 -			CloseHandle(kv);
   1.427 -		}
   1.428 -	}	
   1.429 -}
   1.430 -
   1.431 -SendPanelToAll(String:name[], String:message[])
   1.432 -{
   1.433 -	decl String:title[100];
   1.434 -	Format(title, 64, "%s:", name);
   1.435 -	
   1.436 -	ReplaceString(message, 192, "\\n", "\n");
   1.437 -	
   1.438 -	new Handle:mSayPanel = CreatePanel();
   1.439 -	SetPanelTitle(mSayPanel, title);
   1.440 -	DrawPanelItem(mSayPanel, "", ITEMDRAW_SPACER);
   1.441 -	DrawPanelText(mSayPanel, message);
   1.442 -	DrawPanelItem(mSayPanel, "", ITEMDRAW_SPACER);
   1.443 -
   1.444 -	SetPanelCurrentKey(mSayPanel, 10);
   1.445 -	DrawPanelItem(mSayPanel, "Exit", ITEMDRAW_CONTROL);
   1.446 -
   1.447 -	new MaxClients = GetMaxClients();
   1.448 -	for(new i = 1; i < MaxClients; i++)
   1.449 -	{
   1.450 -		if(IsClientInGame(i) && !IsFakeClient(i))
   1.451 -		{
   1.452 -			SendPanelToClient(mSayPanel, i, Handler_DoNothing, 10);
   1.453 -		}
   1.454 -	}
   1.455 -
   1.456 -	CloseHandle(mSayPanel);
   1.457 -}
   1.458 -
   1.459 -public Handler_DoNothing(Handle:menu, MenuAction:action, param1, param2)
   1.460 -{
   1.461 -	/* Do nothing */
   1.462 -}