All pastes #896305 Raw Edit

Stuff

public cpp v1 · immutable
·published 2008-02-08 15:14 UTC
rendered paste body
/*	Amit's RCON Addition filterscript	------------------------------	Programmer: Amit "Amit_B" Barami	Creation Data: 7/2/2008	Version: 1.0	Compatibility: SanAndreas:MultiPlayer 0.2.2*///=[IncludeFiles]===============================================================#include "a_samp.inc"//=[Defines]====================================================================//=[Variables]==================================================================new mute[MAX_PLAYERS][2];new LockServ;//=[Forwards]===================================================================forward playermute(playerid);//=[OnFilterScriptInit]=========================================================public OnFilterScriptInit(){	print("\n=========================================");	print("RCON Addition filterscript v0.1 by Amit_B  ");	print("Loaded!									  ");	print("You can see the new RCON commands with \"ra\" command.");	print("=========================================\n");	return 1;}//=[OnFilterScriptExit]=========================================================public OnFilterScriptExit(){	print("\n=========================================");	print("RCON Addition filterscript v0.1 by Amit_B  ");	print("UnLoaded!								  ");	print("=========================================\n");	return 1;}//=[OnPlayerConnect]============================================================public OnPlayerConnect(playerid){	mute[playerid][0] = 0;	if(LockServ == 1)	{		Kick(playerid);	}	return 1;}//=[OnPlayerDisconnect]=========================================================public OnPlayerDisconnect(playerid, reason){	mute[playerid][0] = 0;	return 1;}//=[OnPlayerText]===============================================================public OnPlayerText(playerid){	if(mute[playerid][0] > 1)	{		return 0;	}	return 1;}//=[OnRconCommand]==============================================================public OnRconCommand(cmd[]){	new cmdEx[256], idx;	cmdEx = strtok(cmd,idx);	if(!strcmp(cmd,"ra",true))	{		SendRconCommand("echo  RCON Addition filterscript by Amit_B commands:");		SendRconCommand("echo  freeze [playerid]");		SendRconCommand("echo  unfreeze [playerid]");		SendRconCommand("echo  mute [playerid] [seconds 0 - 600]");		SendRconCommand("echo  unmute [playerid]");		SendRconCommand("echo  sethealth [playerid] [health 0 - 100]");		SendRconCommand("echo  setarmour [playerid] [armour 0 - 100]");		SendRconCommand("echo  setmoney [playerid] [money 0 - 99999999]");		SendRconCommand("echo  setwanted [playerid] [wanted 0 - 6]");		SendRconCommand("echo  announce [message]");		SendRconCommand("echo  lockserv [0/1]");		SendRconCommand("echo  kickall");		SendRconCommand("echo  kicksome [playerid] [playerid] etc...");		SendRconCommand("echo  eject [playerid]");		SendRconCommand("echo  disarm [playerid]");		SendRconCommand("echo  giveweapon [playerid] [weaponid] [ammo]");		SendRconCommand("echo  settime [hour]");		SendRconCommand("echo  admins");		SendRconCommand("echo  respawn [playerid]");		SendRconCommand("echo  setcolor [playerid] [color]");		SendRconCommand("echo  chatradius [radius]");		SendRconCommand("echo  fixrun");		SendRconCommand("echo  setname [playerid] [new name]");	}	if(!strcmp(cmdEx,"freeze",true))	{		new id;		cmdEx = strtok(cmd,idx);		if(!strlen(cmdEx))		{			SendRconCommand("echo freeze [Int:playerid]");			return 1;		}		id = strval(cmdEx);		if(!IsPlayerConnected(id))		{			SendRconCommand("echo Invalid player ID.");			return 1;		}		TogglePlayerControllable(id,0);	}	if(!strcmp(cmdEx,"unfreeze",true))	{		new id;		cmdEx = strtok(cmd,idx);		if(!strlen(cmdEx))		{			SendRconCommand("echo unfreeze [Int:playerid]");			return 1;		}		id = strval(cmdEx);		if(!IsPlayerConnected(id))		{			SendRconCommand("echo Invalid player ID.");			return 1;		}		TogglePlayerControllable(id,1);	}	if(!strcmp(cmdEx,"mute",true))	{		new id, seconds;		cmdEx = strtok(cmd,idx);		if(!strlen(cmdEx))		{			SendRconCommand("echo mute [Int:playerid] [Int:seconds 0 - 600]");			return 1;		}		id = strval(cmdEx);		cmdEx = strtok(cmd,idx);		if(!strlen(cmdEx))		{			SendRconCommand("echo mute [Int:playerid] [Int:seconds 0 - 600]");			return 1;		}		seconds = strval(cmdEx);		if(!IsPlayerConnected(id))		{			SendRconCommand("echo Invalid player ID.");			return 1;		}		if(seconds < 0 || seconds > 600)		{			SendRconCommand("echo The seconds must be 0 - 600.");			return 1;		}		mute[id][0] = seconds;		mute[id][1] = SetTimerEx("playermute",1000,1,"i",id);	}	if(!strcmp(cmdEx,"unmute",true))	{		new id;		cmdEx = strtok(cmd,idx);		if(!strlen(cmdEx))		{			SendRconCommand("echo unmute [Int:playerid]");			return 1;		}		id = strval(cmdEx);		if(!IsPlayerConnected(id))		{			SendRconCommand("echo Invalid player ID.");			return 1;		}		if(mute[id][0] == 0)		{		    new str[256];		    format(str,sizeof(str),"echo ID %i is not muted.",id);			SendRconCommand(str);			return 1;		}		mute[id][0] = 0;	}	if(!strcmp(cmdEx,"sethealth",true))	{		new id, health;		cmdEx = strtok(cmd,idx);		if(!strlen(cmdEx))		{			SendRconCommand("echo sethealth [Int:playerid] [Int:health 0 - 100]");			return 1;		}		id = strval(cmdEx);		cmdEx = strtok(cmd,idx);		if(!strlen(cmdEx))		{			SendRconCommand("echo sethealth [Int:playerid] [Int:health 0 - 100]");			return 1;		}		health = strval(cmdEx);		if(!IsPlayerConnected(id))		{			SendRconCommand("echo Invalid player ID.");			return 1;		}		if(health < 0 || health > 100)		{			SendRconCommand("echo The health must be 0 - 100.");			return 1;		}		SetPlayerHealth(id,health);	}	if(!strcmp(cmdEx,"setarmour",true))	{		new id, armour;		cmdEx = strtok(cmd,idx);		if(!strlen(cmdEx))		{			SendRconCommand("echo setarmour [Int:playerid] [Int:armour 0 - 100]");			return 1;		}		id = strval(cmdEx);		cmdEx = strtok(cmd,idx);		if(!strlen(cmdEx))		{			SendRconCommand("echo setarmour [Int:playerid] [Int:armour 0 - 100]");			return 1;		}		armour = strval(cmdEx);		if(!IsPlayerConnected(id))		{			SendRconCommand("echo Invalid player ID.");			return 1;		}		if(armour < 0 || armour > 100)		{			SendRconCommand("echo The armour must be 0 - 100.");			return 1;		}		SetPlayerArmour(id,armour);	}	if(!strcmp(cmdEx,"setmoney",true))	{		new id, money;		cmdEx = strtok(cmd,idx);		if(!strlen(cmdEx))		{			SendRconCommand("echo setmoney [Int:playerid] [Int:money 0 - 99999999]");			return 1;		}		id = strval(cmdEx);		cmdEx = strtok(cmd,idx);		if(!strlen(cmdEx))		{			SendRconCommand("echo setmoney [Int:playerid] [Int:money 0 - 99999999]");			return 1;		}		money = strval(cmdEx);		if(!IsPlayerConnected(id))		{			SendRconCommand("echo Invalid player ID.");			return 1;		}		if(money < 0 || money > 99999999)		{			SendRconCommand("echo The money must be 0 - 99999999.");			return 1;		}		GivePlayerMoney(id,money-GetPlayerMoney(id));	}	if(!strcmp(cmdEx,"setwanted",true))	{		new id, wanted;		cmdEx = strtok(cmd,idx);		if(!strlen(cmdEx))		{			SendRconCommand("echo setwanted [Int:playerid] [Int:wanted 0 - 6]");			return 1;		}		id = strval(cmdEx);		cmdEx = strtok(cmd,idx);		if(!strlen(cmdEx))		{			SendRconCommand("echo setwanted [Int:playerid] [Int:wanted 0 - 6]");			return 1;		}		wanted = strval(cmdEx);		if(!IsPlayerConnected(id))		{			SendRconCommand("echo Invalid player ID.");			return 1;		}		if(wanted < 0 || wanted > 6)		{			SendRconCommand("echo The wanted must be 0 - 6.");			return 1;		}		SetPlayerWantedLevel(id,wanted);	}	if(!strcmp(cmdEx,"announce",true))	{		cmdEx = strrest(cmd,idx);		if(!strlen(cmdEx))		{			SendRconCommand("echo announce [String:message]");			return 1;		}		GameTextForAll(cmdEx,3000,6);	}	if(!strcmp(cmdEx,"lockserv",true))	{		cmdEx = strtok(cmd,idx);		if(!strlen(cmdEx))		{			SendRconCommand("echo lockserv [Bool:0/1]");			return 1;		}		LockServ = strval(cmdEx);	}	if(!strcmp(cmd,"kickall",true))	{		for(new all=0;all<=GetMaxPlayers();all++)		{			if(IsPlayerConnected(all))			{				Kick(all);			}		}	}	if(!strcmp(cmdEx,"kicksome",true))	{		new id;		cmdEx = strtok(cmd,idx);		if(!strlen(cmdEx))		{			SendRconCommand("echo kicksome [Int:playerid] [Int:playerid] etc...");			return 1;		}		while(strlen(cmdEx) != 0)		{			id = strval(cmdEx);			if(IsPlayerConnected(id))			{				Kick(id);			}			cmdEx = strtok(cmd,idx);		}	}	if(!strcmp(cmdEx,"eject",true))	{		new id;		cmdEx = strtok(cmd,idx);		if(!strlen(cmdEx))		{			SendRconCommand("echo eject [Int:playerid]");			return 1;		}		id = strval(cmdEx);		if(!IsPlayerConnected(id))		{			SendRconCommand("echo Invalid player ID.");			return 1;		}		RemovePlayerFromVehicle(id);	}	if(!strcmp(cmdEx,"disarm",true))	{		new id;		cmdEx = strtok(cmd,idx);		if(!strlen(cmdEx))		{			SendRconCommand("echo disarm [Int:playerid]");			return 1;		}		id = strval(cmdEx);		if(!IsPlayerConnected(id))		{			SendRconCommand("echo Invalid player ID.");			return 1;		}		ResetPlayerWeapons(id);	}	if(!strcmp(cmdEx,"giveweapon",true))	{		new id, weaponid, ammo;		cmdEx = strtok(cmd,idx);		if(!strlen(cmdEx))		{			SendRconCommand("echo giveweapon [playerid] [weaponid] [ammo]");			return 1;		}		id = strval(cmdEx);		cmdEx = strtok(cmd,idx);		if(!strlen(cmdEx))		{			SendRconCommand("echo giveweapon [playerid] [weaponid] [ammo]");			return 1;		}		weaponid = strval(cmdEx);		cmdEx = strtok(cmd,idx);		if(!strlen(cmdEx))		{			ammo = 500;		}		else		{			ammo = strval(cmdEx);		}		if(!IsPlayerConnected(id))		{			SendRconCommand("echo Invalid player ID.");			return 1;		}		GivePlayerWeapon(id,weaponid,ammo);	}	if(!strcmp(cmdEx,"settime",true))	{		new hour;		cmdEx = strtok(cmd,idx);		if(!strlen(cmdEx))		{			SendRconCommand("echo settime [Int:hour]");			return 1;		}		hour = strval(cmdEx);		SetWorldTime(hour);	}	if(!strcmp(cmd,"admins",true))	{		new name[MAX_PLAYERS][MAX_PLAYER_NAME], admins=0, str[256];		for(new i=0;i<=GetMaxPlayers();i++)		{			if(IsPlayerConnected(i) && IsPlayerAdmin(i))			{				admins++;				GetPlayerName(i,name[i],sizeof(name));				format(str,sizeof(str),"echo RCON admins online (%i):",admins);				SendRconCommand(str);				for(new n=0;n<admins;n++)				{				    format(str,sizeof(str),"echo %i. %s [%i]",n,name[i],i);					SendRconCommand(str);				}			}		}	}	if(!strcmp(cmdEx,"respawn",true))	{		new id;		cmdEx = strtok(cmd,idx);		if(!strlen(cmdEx))		{			SendRconCommand("echo respawn [Int:playerid]");			return 1;		}		id = strval(cmdEx);		if(!IsPlayerConnected(id))		{			SendRconCommand("echo Invalid player ID.");			return 1;		}		SpawnPlayer(id);	}	if(!strcmp(cmdEx,"setcolor",true))	{		new id, color;		cmdEx = strtok(cmd,idx);		if(!strlen(cmdEx))		{			SendRconCommand("echo setcolor [Int:playerid] [Hex:color]");			return 1;		}		id = strval(cmdEx);		cmdEx = strtok(cmd,idx);		if(!strlen(cmdEx))		{			SendRconCommand("echo setcolor [Int:playerid] [Hex:color]");			return 1;		}		if(!IsPlayerConnected(id))		{			SendRconCommand("echo Invalid player ID.");			return 1;		}		if(!IsHex(cmdEx))		{			SendRconCommand("echo Invalid color.");			return 1;		}		color = strhex(cmdEx);		SetPlayerColor(id,color);	}	if(!strcmp(cmdEx,"chatradius",true))	{		new Float:radius;		cmdEx = strtok(cmd,idx);		if(!strlen(cmdEx))		{			SendRconCommand("echo chatradius [Float:radius]");			return 1;		}		radius = floatstr(cmdEx);		LimitGlobalChatRadius(radius);	}	if(!strcmp(cmdEx,"fixrun",true))	{		UsePlayerPedAnims();	}	if(!strcmp(cmdEx,"setname",true))	{		new id;		cmdEx = strtok(cmd,idx);		if(!strlen(cmdEx))		{			SendRconCommand("echo setname [Int:playerid] [String:new name]");			return 1;		}		id = strval(cmdEx);		cmdEx = strtok(cmd,idx);		if(!strlen(cmdEx))		{			SendRconCommand("echo setname [Int:playerid] [String:new name]");			return 1;		}		if(!IsPlayerConnected(id))		{			SendRconCommand("echo Invalid player ID.");			return 1;		}		new BadNameChars[][2] = {"/","`","~","!","@","#","$","%","^","&","*","(",")","-","=","+",".",",","<",">","[","]","{","}","|",":",";","'"};		for(new i=0;i<sizeof(BadNameChars);i++)		{			if(strfind(cmdEx,BadNameChars[i],true) != -1 || strlen(cmdEx) > MAX_PLAYERS)			{				SendRconCommand("echo Bad name.");				return 1;			}		}		SetPlayerName(id,cmdEx);	}	return 1;}//=[playermute]=================================================================public playermute(playerid){	while(mute[playerid][0] > 0)	{		mute[playerid][0]--;	}	if(mute[playerid][0] == 0)	{		KillTimer(mute[playerid][1]);	}	return 1;}//=[strtok]=====================================================================stock strtok(const string[], &index){	new length = strlen(string);	while ((index < length) && (string[index] <= ' '))	{		index++;	}	new offset = index;	new result[20];	while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))	{		result[index - offset] = string[index];		index++;	}	result[index - offset] = EOS;	return result;}//=[strrest]====================================================================stock strrest(const string[],index){	new length = strlen(string);	new offset = index;	new result[256];	while ((index < length) && ((index - offset) < (sizeof(result) - 1)) && (string[index] > '\r'))	{		result[index - offset] = string[index];		index++;	}	result[index - offset] = EOS;	return result;}//=[strhex]=====================================================================stock strhex(string[]) // Based on "hexstr" funcation by Y_Less (YSI){	new ret, val, i;	if(string[0] == '0' && (string[1] == 'x' || string[1] == 'X'))	{		i = 2;	}	while(string[i])	{		ret <<= 4;		val = (string[i++] - '0');		if(val > 0x09)		{			val -= 0x07;		}		if(val > 0x0F)		{			val -= 0x20;		}		if(val < 0x01)		{			continue;		}		if(val < 0x10)		{			ret += val;		}	}	return ret;}//=[IsHex]======================================================================stock IsHex(string[]) // Based on "ishex" funcation by Y_Less (YSI){	new i, cur;	if(string[0] == '0' && (string[1] == 'x' || string[1] == 'X'))	{		i = 2;	}	while(string[i])	{		cur = string[i++];		if((cur < '0') || (cur > '9' && cur < 'A') || (cur > 'F' && cur < 'a') || (cur > 'f'))		{			return false;		}	}	return true;}