
/*
*	AMXMOD script.
*	(plugin_slash.sma)
*	by mike_cao <mike@mikecao.com>
*	This file is provided as is (no warranties).
*
*	This plugin allows admins to execute amx commands
*	using 'say' and a slash '/'. It can also execute
*	a command on all players or a team using '@all' and
*	'@team' in place of the authid/nick parameter.
*
*	Examples:
*	To kick a player type '/kick playername'
*	To kick all players type '/kick @all'
*	To kick all players on a team type '/kick @team:TEAMID'
*	To ban all players for 10 minutes, type '/ban 10 @all'
*
*
*	Important: place this plugin at the bottom of your plugins.ini file 
*	so it doesn't interfere with other plugin that may use the '/'.
*
*/ 

#include <amxmodx>

#define MAX_NAME_LENGTH 32
#define MAX_TEXT_LENGTH 192
#define MAX_PLAYERS 32

public admin_slash(id)
{
	new sName[MAX_NAME_LENGTH+1]
	new sArg[MAX_NAME_LENGTH+1]
	
	read_argv(1,sArg,MAX_NAME_LENGTH)
	
	// Check for '/' char
	if ( sArg[0] == '/' ) {
		
		new sCommand[MAX_TEXT_LENGTH+1]
		new sMessage[MAX_TEXT_LENGTH+1]
		new sTemp[MAX_TEXT_LENGTH+1]
		
		read_args(sMessage,MAX_TEXT_LENGTH)
		remove_quotes(sMessage)
		replace(sMessage,MAX_TEXT_LENGTH,"/","")
		
		if ( containi(sMessage,"@all") != -1 ) {
			
			new iPlayers[MAX_PLAYERS], iNumPlayers
			get_players(iPlayers,iNumPlayers)
			
			for (new i = 0; i < iNumPlayers; i++) {
				
				get_user_name(iPlayers[i],sName,MAX_NAME_LENGTH)
				
				copy(sTemp,MAX_TEXT_LENGTH,sMessage)
				replace(sTemp,MAX_TEXT_LENGTH,"@all","^"@name^"")
				replace(sTemp,MAX_TEXT_LENGTH,"@name",sName)
				format(sCommand,MAX_TEXT_LENGTH,"amx_%s",sTemp)
				client_cmd(id,sCommand)
				
			}
			copyc(sCommand,MAX_NAME_LENGTH,sTemp,' ')
			client_print(id,print_chat,"[AMXX] Command ^"%s^" executed on all players",sCommand)
		}
		
		else if ( containi(sMessage,"@team:") != -1 ) {
			
			new sTeam[MAX_NAME_LENGTH+1]
			new sRemove[MAX_TEXT_LENGTH+1]
			
			copy(sTemp,MAX_TEXT_LENGTH,sMessage)
			copyc(sRemove,MAX_TEXT_LENGTH,sTemp,'@')
			replace(sTemp,MAX_TEXT_LENGTH,sRemove,"")
			copyc(sTeam,MAX_TEXT_LENGTH,sTemp,' ')
			
			if ( containi(sTeam,"@team:") != -1 ) {
				
				replace(sMessage,MAX_TEXT_LENGTH,sTeam,"^"@name^"")
				replace(sTeam,MAX_TEXT_LENGTH,"@team:","")
				
				if ( equal(sTeam,"T") ) {
					copy(sTeam,MAX_NAME_LENGTH,"TERRORIST")
				}
				else if ( equal(sTeam,"S") ) {
					copy(sTeam,MAX_NAME_LENGTH,"SPECTATOR")
				}
			}
			else {
				client_print(id,print_chat,"[AMXX] Team identifier not recognized")
				return PLUGIN_HANDLED
			}
			
			new iPlayers[MAX_PLAYERS], iNumPlayers
			get_players(iPlayers,iNumPlayers,"e",sTeam)
			
			if ( iNumPlayers ) {
				
				for (new i = 0; i < iNumPlayers; i++) {
					
					get_user_name(iPlayers[i],sName,MAX_NAME_LENGTH)
					
					copy(sTemp,MAX_TEXT_LENGTH,sMessage)
					replace(sTemp,MAX_TEXT_LENGTH,"@name",sName)
					format(sCommand,MAX_TEXT_LENGTH,"amx_%s",sTemp)
					client_cmd(id,sCommand)
				}
				copyc(sCommand,MAX_NAME_LENGTH,sTemp,' ')
				client_print(id,print_chat,"[AMXX] Command ^"%s^" executed on team ^"%s^"",sCommand,sTeam)
			}
			
			else 	{
				client_print(id,print_chat,"[AMXX] There are no players on team ^"%s^"",sTeam)
			}
		}
		
		else 	{
			format(sCommand,MAX_TEXT_LENGTH,"amx_%s",sMessage)
			client_cmd(id,sCommand)
		}
		
		return PLUGIN_HANDLED
	}
	return PLUGIN_CONTINUE
}

public plugin_init()
{
	register_plugin("Admin Slash","1.2","mike_cao")
	register_clcmd("say","admin_slash",0,"say /command < params >")
	return PLUGIN_CONTINUE
}

/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1033\\ f0\\ fs16 \n\\ par }
*/
