//
// Created: 05.09.06
// Aurthor: Iain Gilbert
//

#if defined _commandhandler_included
#endinput
#endif

#define _commandhandler_included
#pragma library commandhandler
#include "base"
#include "utils\gtoutils"
#include "player"
#include "account"

#define MONEY_CMD1 50000;		//SkyDiving
#define MONEY_CMD2 100000;		//RepairCar

forward CommandHandler(playerid,text[]);

public CommandHandler(playerid,text[]) // process player commands
{
	if (!IsPlayerConnected(playerid)) return 0;
	new cmd[20];
	new idx;
	set(cmd,strcharsplit(text, idx,strchar(" ")));

	if(strcomp(cmd, "/sound", true) == 1)
	{
	new string[MAX_STRING];
	set(string,text);
	strdel(string, 0, idx);
	new soundid;
	soundid = strval(strcharsplit(text, idx,strchar(" ")));
	if (soundid <= 0)
	{
		SendPlayerFormattedText(playerid, lang_texts[15] , 0,COLOUR_RED);
		return 1;
	}
	PlaySoundForPlayer(playerid,soundid);
	format(string,sizeof(string), lang_texts[16] ,soundid);
	SendPlayerFormattedText(playerid,string, 0,COLOUR_XP_GOOD);
	return 1;
	}

	if(strcomp(cmd, "/dropammo", true) == 1)
	{
	ADMDropAmmo(playerid);
//	for (new i=1;i<MAX_WEAPONS;i++)
//		{
//		PlayerWeapons[playerid][i] = 0;
//		}
	SendPlayerFormattedText(playerid, lang_texts[33] , 0,COLOUR_WHITE);
	CheckPlayerLevel(playerid);
	return 1;
	}


	if(strcomp(cmd, "/me", true) == 1)
	{
	new txtme[MAX_STRING];
	strmid(txtme,text,4,strlen(text));
	if (!strlen(txtme)) return 1;

//	new txtme[MAX_STRING] = strval(strcharsplit(text, idx,strchar(" ")));
	new string[MAX_STRING];
	format(string, sizeof(string), ">>> %s %s", oGetPlayerName(playerid), txtme);
	SendClientMessageToAll(COLOUR_GREY, string);
	return 1;
	}

	if(strcomp(cmd, "/help", true) == 1)
	{
	  SendClientMessage(playerid, COLOUR_WHITE, lang_texts[566]);
	  SendClientMessage(playerid, COLOUR_LIGHTRED, lang_texts[567]);
	  SendClientMessage(playerid, COLOUR_WHITE, lang_texts[568]);
	  SendClientMessage(playerid, COLOUR_WHITE, lang_texts[569]);

//		for (new i=2; i<9; i++) SendPlayerScrollingText(playerid, lang_texts[15][i]);

	return 1;
	}

	if( (strcomp(cmd, "/objective", true) == 1) || (strcomp(cmd, "/info", true) == 1) )
	{
	  SendClientMessage(playerid, COLOUR_LIGHTGREEN, lang_texts[570]);
	  SendClientMessage(playerid, COLOUR_LIGHTGREEN, lang_texts[571]);
	  SendClientMessage(playerid, COLOUR_LIGHTGREEN, lang_texts[572]);
	  SendClientMessage(playerid, COLOUR_LIGHTGREEN, lang_texts[573]);
	  SendClientMessage(playerid, COLOUR_LIGHTGREEN, lang_texts[574]);
	  SendClientMessage(playerid, COLOUR_LIGHTGREEN, lang_texts[575]);
	  SendClientMessage(playerid, COLOUR_LIGHTGREEN, lang_texts[576]);
	  SendClientMessage(playerid, COLOUR_LIGHTGREEN, lang_texts[577]);

//		for (new i=10; i<17; i++) SendPlayerScrollingText(playerid, lang_texts[15][i]);

		return 1;
	}


//lang_texts[579]-lang_texts[593]
	if(strcomp(cmd, "/commands", true) == 1)
	{
	  SendClientMessage(playerid, COLOUR_PURPLE, "__ACC: '/help', '/register <password> <email>', '/login <password>', '/savechar', '/quit'");
	  SendClientMessage(playerid, COLOUR_WHITE, "_TEXT: '/me <text>', '/pm <ID> <text>', '@ <text>', '# <text>'");
	  SendClientMessage(playerid, COLOUR_PURPLE, "_USER: '/commands', '/info' ('/objective'), '/version', '/status' ('/stats', '/stat'), '/level', '/statshow'");
	  SendClientMessage(playerid, COLOUR_LIGHTGREEN, "MONEY: '/givecash <ID> <money>'  ONLY BANK: '/bank <money>' ('/deposit <money>'), '/withdraw <money>'");
	  SendClientMessage(playerid, COLOUR_PURPLE, "GANGS: '/gang help', '/gang commands', '/gang create <colour> <gangname>', '/gang colours'");
	  SendClientMessage(playerid, COLOUR_PURPLE, "GANGS: '/gang quit', '/gang accept', '/gang stats', '/gang members', '/g <message>', '! <message>");
	  SendClientMessage(playerid, COLOUR_PURPLE, "GANGS: '/gang invite <playername>', '/gang kick <playername>', '/gang colour <colour>'");
	  SendClientMessage(playerid, COLOUR_LIGHTBLUE, "_AMMÎ: '/weapons', '/wl' ('/weaponlist'), '/wb <ID> <bullets>' ('/weaponbuy')");
	  SendClientMessage(playerid, COLOUR_WHITE, "BUSIN: '/businesses', '/mybusinesses' ONCHECK: '/binfo', '/bbuy', '/bsell', '/collect', '/setbbuyout'");
	  SendClientMessage(playerid, COLOUR_WHITE, "HOUSE: '/houses', '/myhouses' ONCHECK: '/hinfo', '/hbuy', '/hsell', '/upkeep', '/sethbuyout'");
	  SendClientMessage(playerid, COLOUR_PURPLE, "RACES: '/races', '/race join <ID>', '/race quit', '/race leave'");
	  SendClientMessage(playerid, COLOUR_PURPLE, "__DMS: '/dms', '/dm join <ID>', '/dm quit', '/dm leave'");
	  SendClientMessage(playerid, COLOUR_LIGHTRED, "_CARS: ('/lock', '/unlock'), '/taxi', '/call taxi', '/gasloc'");
	  SendClientMessage(playerid, COLOUR_PURPLE, "OTHER: '/kill', '/time', '/admins', '/dropammo', '/sound <IDsound>', '/box', '/boxlom'");
	  SendClientMessage(playerid, COLOUR_LIGHTRED, "SALED: '/repair', '/skydive'");
	  SendClientMessage(playerid, COLOUR_WHITE, "ANIMS: '/animlist', '/dance [1-3]', '/handsup'");
	return 1;
	}

	if((strcomp(cmd, "/stats", true) == 1) || (strcomp(cmd, "/status", true) == 1) || (strcomp(cmd, "/stat", true) == 1))
	{
		new string[MAX_STRING];
		SendClientMessage(playerid,COLOUR_GREEN,  lang_texts[599] );

		new sid;
		sid=Player[playerid][Status];
		if (sid>=1 && sid<=10) {format(string,sizeof(string),lang_texts[523],sid);}
		else if (sid>10) {format(string,sizeof(string),lang_texts[522],sid);}
		else {format(string,sizeof(string),lang_texts[524]);}
		//Status
		SendClientMessage(playerid,COLOUR_LIGHTRED,string);

		format(string, sizeof(string),  lang_texts[601] , GetLevelName(Player[playerid][Level]), PlayerGangName[playerid] );
		SendClientMessage(playerid,COLOUR_LIGHTBLUE,string);
		format(string, sizeof(string),  lang_texts[602] , Player[playerid][Level], Player[playerid][XP], Player[playerid][Money], Player[playerid][Bank], GetPlayerTotalMoney(playerid) );
		SendClientMessage(playerid,COLOUR_LIGHTBLUE,string);
		format(string, sizeof(string),  lang_texts[603] , Player[playerid][Deaths], Player[playerid][Kills], Player[playerid][Jaileds], Player[playerid][Muted] );
		SendClientMessage(playerid,COLOUR_LIGHTRED,string);

	//ÊýøÁîêñû %d, Ïîäêîâû n/a, Óñòðèöû n/a, Ñïðÿòàííûå ïàêåòû n/a
		format(string,sizeof(string), lang_texts[539] ,Player[playerid][CB] );
		SendClientMessage(playerid,COLOUR_WHITE,string);

	//Òà÷åê Èìï./Ýêñï. n/a, Ïèöö n/a, Íàðêîòèêîâ n/a, Ãðóçîâ n/a
		format(string,sizeof(string), lang_texts[540] );
		SendClientMessage(playerid,COLOUR_WHITE,string);

		return 1;
	}

	if(strcomp(cmd, "/level", true) == 1)
	{
		CheckPlayerLevel(playerid);
		new string[256];
		SendClientMessage(playerid,COLOUR_GREEN,  lang_texts[634] );
		format(string, sizeof(string),  lang_texts[635] , Player[playerid][Level]);
		SendClientMessage(playerid,COLOUR_XP_GOOD, string);
		format(string, sizeof(string),  lang_texts[636] , Player[playerid][XP]);
		SendClientMessage(playerid,COLOUR_XP_GOOD, string);
		format(string, sizeof(string),  lang_texts[637] , GetXPToLevel(playerid, Player[playerid][Level] + 1));
		SendClientMessage(playerid,COLOUR_XP_BAD, string);
		return 1;
	}

	if(strcomp(cmd, "/statshow", true) == 1)
	{
	if (Player[playerid][StatShow]==0)
		{
		Player[playerid][StatShow]++;
		SendClientMessage(playerid,COLOUR_GREEN, "ON view Player State");
		} else {
			Player[playerid][StatShow]=0;
			SendClientMessage(playerid,COLOUR_GREEN, "OFF view Player State");
			}
	return 1;
	}

	if(strcomp(cmd, "/version", true) == 1)
	{
		new string[MAX_STRING];
		SendClientMessage(playerid, COLOUR_MISC,  lang_texts[638] );
		format(string, sizeof(string),  lang_texts[639] , VERSION);
		SendClientMessage(playerid, COLOUR_GREEN,string);
		SendClientMessage(playerid, COLOUR_MISC,  lang_texts[640] );
		return 1;
	}

	if ( (strcomp(cmd, "/kill", true) == 1) && !IsPlayerInAnyDM(playerid) )
	{
		SetPlayerHealth(playerid,0.0);
		return 1;
	}

	if(strcomp(cmd, "/handsup", true) == 1)
	{
	if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
		{
		SetPlayerSpecialAction(playerid,SPECIAL_ACTION_HANDSUP);
//		PlaySoundForPlayer(playerid,1187);
  	  	return 1;
		}
	}

 	if(strcomp(cmd, "/dance", true) == 1)
	{
	new dancestyle;
	dancestyle = strval(strcharsplit(text, idx,strchar(" ")));
	if ((dancestyle < 1) || (dancestyle > 3))
	{
	SendPlayerFormattedText(playerid, lang_texts[647] , 0,COLOUR_RED);
	return 1;
	}

	if(dancestyle == 1) {
		SetPlayerSpecialAction(playerid,SPECIAL_ACTION_DANCE1);
		} else if(dancestyle == 2) {
		SetPlayerSpecialAction(playerid,SPECIAL_ACTION_DANCE2);
		} else if(dancestyle == 3) {
		SetPlayerSpecialAction(playerid,SPECIAL_ACTION_DANCE3);
		}
	return 1;
	}



if(strcomp(cmd, "/admins", true) == 1)
{
new string[MAX_STRING];
new idsa=0;
SendClientMessage(playerid, COLOUR_WHITE, lang_texts[28]);

	for (new id = 0; id < MAX_PLAYERS; id++)
	{
		if ( (IsPlayerConnected(id) && IsPlayerAdmin(id)) || (IsPlayerConnected(id) && IsPlayerAdm(id)) )
		{
		format(string, sizeof(string), lang_texts[29] , oGetPlayerName(id), id);
		SendClientMessage(playerid, COLOUR_LIGHTBLUE,string);
		idsa++;
		}
	}
	for (new id = 0; id < MAX_PLAYERS; id++)
	{
		if ( IsPlayerConnected(id) && IsPlayerMod(id) )
		{
		format(string, sizeof(string), lang_texts[30] , oGetPlayerName(id), id);
		SendClientMessage(playerid, COLOUR_LIGHTGREEN,string);
		idsa++;
		}
	}

	if (idsa==0)
	{
	SendClientMessage(playerid, COLOUR_GREY,lang_texts[31]);
	}
return 1;
}


if(strcomp(cmd, "/time", true) == 1)
{
new string[MAX_STRING];
//new hour,minute,second;
//gettime(hour,minute,second);
//if ( (hour <= 9) && (minute <= 9) ) {format(string,sizeof(string),"0%d:0%d",hour,minute);}
//if ( (hour <= 9) && (minute > 9) )  {format(string,sizeof(string),"0%d:%d",hour,minute);}
//if ( (hour > 9) && (minute <= 9) ) {format(string,sizeof(string),"%d:0%d",hour,minute);}
//if ( (hour > 9) && (minute > 9) )  {format(string,sizeof(string),"%d:%d",hour,minute);}

GameTextForPlayer(playerid,GetStringGettime(),999,1);
//SendClientMessage(playerid, COLOUR_WHITE,string );

PlaySoundForPlayer(playerid,1085);

format(string, sizeof(string),lang_texts[32], oGetPlayerName(playerid), playerid);
SendClientMessageToAll(COLOUR_GREY, string);
return 1;
}


	if(strcomp(cmd, "/givecash", true) == 1)
	{
		new string[256];
		new giveplayerid, moneys;
		new sendername[MAX_PLAYER_NAME];
		new playermoney;
		new giveplayer[MAX_PLAYER_NAME];
		new tmp[256];
		tmp = strcharsplit(text, idx,strchar(" "));

		if(!strlen(tmp))
		{
			SendClientMessage(playerid, COLOUR_MISC,  lang_texts[641] );
			return 1;
		}
		giveplayerid = strval(tmp);

		tmp = strcharsplit(text, idx,strchar(" "));
		if(!strlen(tmp))
		{
			SendClientMessage(playerid, COLOUR_MISC,  lang_texts[642] );
			return 1;
		}
		moneys = strval(tmp);

		if (IsPlayerConnected(giveplayerid))
		{
			GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
			GetPlayerName(playerid, sendername, sizeof(sendername));
			playermoney = oGetPlayerMoney(playerid);
			if (moneys > 0 && playermoney >= moneys)
			{
				oGivePlayerMoney(playerid, (0 - moneys),1);
				oGivePlayerMoney(giveplayerid, moneys,1);
				format(string, sizeof(string),  lang_texts[643] , giveplayer,giveplayerid, moneys);
				SendClientMessage(playerid, COLOUR_MONEY_GOOD, string);
				format(string, sizeof(string),  lang_texts[644] , moneys, sendername, playerid);
				SendClientMessage(giveplayerid, COLOUR_MONEY_GOOD, string);

				new logstring[256];
				format(logstring, sizeof (logstring), "%s(playerid:%d) has transfered %d to %s(playerid:%d)",sendername, playerid, moneys, giveplayer, giveplayerid);
				WriteLog(logstring);
			}
			else
			{
				SendClientMessage(playerid, COLOUR_MISC,  lang_texts[645] );
			}
		}
		else
		{
			format(string, sizeof(string),  lang_texts[646] , giveplayerid);
			SendClientMessage(playerid, COLOUR_MISC, string);
	}
	return 1;
	}



//ÏËÀÒÍÛÅ ÊÎÌÀÍÄÛ

	if ( (strcomp(cmd, "/skydive", true) == 1) && !IsPlayerInAnyDM(playerid) )
	{
	if (Player[playerid][Jailed] == 1) {return 0;}
	new string[MAX_STRING];
	SendPlayerFormattedText(playerid, lang_texts[19] , 0,COLOUR_WHITE);
	new Float:playerx,Float:playery,Float:playerz;
	GivePlayerWeapon(playerid,46,1);
	GetPlayerPos(playerid,playerx,playery,playerz);
	PlaySoundForPlayer(playerid,1057);
	SetPlayerPos(playerid,playerx,playery,playerz+1200);
//	format(string,sizeof(string), lang_texts[16] ,soundid);
//	SendPlayerFormattedText(playerid,string, 0,COLOUR_XP_GOOD);
	format(string,sizeof(string), lang_texts[20]);
	GameTextForPlayer(playerid,string,4000,5);
	format(string,sizeof(string), lang_texts[21] ,oGetPlayerName(playerid),playerid);
	SendClientMessageToRegistered(COLOUR_GREY, string);
	PlaySoundForPlayer(playerid,1039);
	return 1;
	}



	if(strcomp(cmd, "/repair", true) == 1)
	{

	return 0;
	}





return 0;
}
