Easy help .. thnx in advance
#1

Guys i have a gang system i want that when player will use /acceptg so player name should be change like this
[gangtag]Playername .....
And when player will use /leavegang
so player name should be like this
PlayerName

i tryed to make it but i cant ... i am trying from 2 hour please help ...

Gang System Code
Код:
/*
		  X337 SIMPLE GANG SYSTEM
	Required Plugins : sscanf, mysql R39-2
*/
#include <a_samp> // SA-MP Team
#include <a_mysql> // BlueG
#include <sscanf2> // Y-Less
#include <YSI(2)\y_iterate> // Y-Less
#include <YSI(2)\y_areas> // Y-Less
#include <zcmd> // Zeex

/*
							DATABASE CONNECTION
	You must define database connection below and recompile this filterscript
*/
#define HOSTNAME		"127.0.0.1	"
#define USERNAME		""
#define PASSWORD		""
#define DATABASENAME	""
#define Error(%1,%2) SendClientMessage(%1, COLOR_GREY3, ""RED_E"ERROR: "GREY3_E""%2)
/*

	-------------------------------------------------------------------------
*/

/*==============================================================================
         					     Colors
===============================================================================*/
#define COLOR_WHITE 		0xFFFFFFFF
#define COLOR_WHITEP 		0xFFE4C4FF
#define COLOR_ORANGE   		0xDB881AFF
#define COLOR_ORANGE2		0xFF5000FF
#define COLOR_IVORY 		0xFFFF82FF
#define COLOR_LIME 			0xD2D2ABFF
#define COLOR_BLUE			0x004BFFFF
#define COLOR_SBLUE			0x56A4E4FF
#define COLOR_RCONBLUE      0x0080FF99
#define COLOR_PURPLE 		0x5A00FFFF
#define COLOR_RED 			0xFF0000FF
#define COLOR_LRED 			0xE65555FF
#define COLOR_LIGHTGREEN 	0x00FF00FF
#define COLOR_YELLOW 		0xFFFF00FF
#define COLOR_YELLOW2 		0xF5DEB3FF
#define COLOR_LB 			0x15D4EDFF
#define COLOR_PINK			0xEE82EEFF
#define COLOR_GOLD			0xFFD700FF
#define COLOR_FIREBRICK 	0xB22222FF
#define COLOR_GREEN 		0x3BBD44FF
#define COLOR_GREY			0xBABABAFF
#define COLOR_GREY2 		0x778899FF
#define COLOR_GREY3			0xC8C8C8FF
#define COLOR_DARK 			0x7A7A7AFF
#define COLOR_BROWN 		0x8B4513FF
#define COLOR_SYSTEM 		0xEFEFF7FF


#define RED_E 		"{FFFF00}"
#define BLUE_E 		"{004BFF}"
#define SBLUE_E 	"{56A4E4}"
#define PINK_E 		"{FFB6C1}"
#define YELLOW_E 	"{00FF00}"
#define LG_E 		"{00FF00}"
#define LB_E 		"{15D4ED}"
#define LB2_E 		"{87CEFA}"
#define GREY_E 		"{BABABA}"
#define GREY2_E 	"{778899}"
#define GREY3_E 	"{C8C8C8}"
#define DARK_E 		"{7A7A7A}"
#define WHITE_E 	"{FFFFFF}"
#define WHITEP_E 	"{FFE4C4}"
#define IVORY_E 	"{FFFF82}"
#define ORANGE_E 	"{DB881A}"
#define GREEN_E 	"{3BBD44}"
#define PURPLE_E 	"{5A00FF}"
#define LIME_E 		"{D2D2AB}"
#define LRED_E		"{E65555}"

//=== Color ===
#define COLOR_RGB(%1,%2,%3,%4) (((((%1) & 0xff) << 24) | (((%2) & 0xff) << 16) | (((%3) & 0xff) << 8) | ((%4) & 0xff)))
#define StripAlpha(%0) ((%0) >>> 8)

#define AUTOSAVE					30 // Save Player, Gangs, Zones data automatically! (In - Minutes);
#define MAX_ZONES					100 // Maximum Gang Zone
#define MAX_GANGS					100 // Maximum Gang
#define CAPTURE_TIME				500 // Capture Time
#define LOCKED_MINUTES              4
#define DIALOG_UNUSED				1337 // Dialog ID
#define DEFAULT_ZONE_COLOR			"000000AA" // Default hex colour for gang zone
#define REQUIRED_SCORE				100 // Required score to make a new gang
#define MAX_GANG_MEMBER				8 // Maximum gang member
#undef 	MAX_PLAYERS
	#define MAX_PLAYERS				50 // MAX_PLAYERS
#define DIALOG_SAVEZONE				DIALOG_UNUSED+1
#define DIALOG_CREATEGANG			DIALOG_UNUSED+2
#define DIALOG_GANGTAG				DIALOG_UNUSED+3
#define DIALOG_GANGCOLOUR			DIALOG_UNUSED+4
#define DIALOG_HEXCOLOUR			DIALOG_UNUSED+5
#define DIALOG_CREATEGANG_CONFIRM	DIALOG_UNUSED+6
#define DIALOG_GCP					DIALOG_UNUSED+7
#define strcpy(%0,%1) \
	strcat((%0[0] = '\0', %0), %1)
#define GANG_MEMBER					1
#define GANG_STAFF					2
#define GANG_LEADER					3

//
new Cantuse[MAX_PLAYERS];
new usfg1,
	usfg2,
	usfg3,
	usfg4,
	usfg5,
	usfg6,
	usfg7,
	usfg8;

enum _gangzone
{
	ZoneID,
	Float:ZoneMinPos[2],
	Float:ZoneMaxPos[2],
	ZoneOwner,
	ZoneName[50],
	ZoneHolder,
	ZoneArea,
	ZoneLocked,
	bool:ZoneStatus,
	ZoneTimer
}
enum _player
{
	PlayerID,
	bool:CreatingZone,
	PlayerText:TDZone[2],
	PlayerGang,
	PlayerStatus,
	GangRequest,
	PlayerText:CaptureTD[2]
}
enum _gang
{
	GangID,
	GangColor[7],
	GangName[30],
	GangTag[4],
	GangScore,
	CurrentZone,
	GangTimer
}

new Player[MAX_PLAYERS][_player],
GangZone[MAX_ZONES][_gangzone],
Gang[MAX_GANGS][_gang],
Iterator:GangZones<MAX_ZONES>,
Iterator:Gangs<MAX_GANGS>,
Float:MinPos[MAX_PLAYERS][2],
Float:MaxPos[MAX_PLAYERS][2],
PlayerZone[MAX_PLAYERS],
TempGangName[MAX_PLAYERS][30],
TempGangTag[MAX_PLAYERS][4],
TempGangColour[MAX_PLAYERS][7],
connection,
AutoSaveTimer;

stock bool:CheckGang(gangid)
{
	new total = 0, query[128];
	mysql_format(connection, query, sizeof(query), "SELECT count(*) AS `total` FROM `member` WHERE `gang` = %d", Gang[gangid][GangID]);
	mysql_query(connection, query, true);
	total = (cache_num_rows() > 0) ? cache_get_field_content_int(0, "total") : 0;
	return (total >= MAX_GANG_MEMBER) ? false : true;
}

stock IsAlpha(const string[])
{
	for(new i = 0; i < strlen(string); i++)
	{
		if(string[i] == 45 || (string[i] >= 48 && string[i] <= 57) || (string[i] >= 65 && string[i] <= 90) || (string[i] >= 97 && string[i] <= 122))
			continue;

		return false;
	}
	return true;
}
stock HexToInt(string[]) // DracoBlue
{
	if (string[0] == 0) return 0;
	new i, cur=1, res = 0;
	for (i=strlen(string);i>0;i--) {
		if (string[i-1]<58) res=res+cur*(string[i-1]-48); else res=res+cur*(string[i-1]-65+10);

		cur=cur*16;
	}
	return res;
}

stock GetGangID(id)
{
	foreach(new i : Gangs)
		if(Gang[i][GangID] == id)
			return i;
	return -1;
}

stock GetID(const name[])
{
	foreach(new i : Player)
	{
		if(!strcmp(name, Name(i)))
			return i;
	}
	return -1;
}

SaveStats(playerid)
{
	new query[128], name[MAX_PLAYER_NAME], i = Player[playerid][PlayerGang];
	GetPlayerName(playerid, name, MAX_PLAYER_NAME);
	if(Iter_Contains(Gangs, i) && i != -1)
		mysql_format(connection, query, sizeof(query), "UPDATE `member` SET `gang` = %d, `status` = %d, `name` = '%e' WHERE `id` = '%d'", Gang[i][GangID], Player[playerid][PlayerStatus], name, Player[playerid][PlayerID]);
	else
		mysql_format(connection, query, sizeof(query), "UPDATE `member` SET `gang` = -1, `name` = '%e' WHERE `id` = %d", name, Player[playerid][PlayerID]);
	mysql_query(connection, query, false);
	return 1;
}

SaveGang(i)
{
	new query[128];
	mysql_format(connection, query, sizeof(query), "UPDATE `gang` SET `color` = '%e', `score` = %d WHERE `id` = '%d'", Gang[i][GangColor], Gang[i][GangScore], Gang[i][GangID]);
	mysql_query(connection, query, false);
	return 1;
}

SaveZone(i)
{
	if(GangZone[i][ZoneOwner] != -1 && Iter_Contains(Gangs, GangZone[i][ZoneOwner]))
	{
		new query[128];
		mysql_format(connection, query, sizeof(query), "UPDATE `zone` SET `owner` = '%d' WHERE `id` = '%d'", Gang[GangZone[i][ZoneOwner]][GangID], GangZone[i][ZoneID]);
		mysql_query(connection, query, false);
	}
	return 1;
}

LoadPlayerGang(playerid)
{
	Player[playerid][PlayerGang] = -1;
	Player[playerid][PlayerStatus] = GANG_MEMBER;
	Player[playerid][GangRequest] = -1;
	new name[MAX_PLAYER_NAME], query[128];
	GetPlayerName(playerid, name, MAX_PLAYER_NAME);
	mysql_format(connection, query, sizeof(query), "SELECT * FROM `member` WHERE `name` = '%e'", name);
	mysql_query(connection, query, true);
	new count = cache_num_rows();
	if(count > 0)
	{
		new id = cache_get_field_content_int(0, "gang");
		foreach(new i : Gangs)
		{
			if(Gang[i][GangID] == id)
			{
				Player[playerid][PlayerGang] = i;
				break;
			}
		}
		Player[playerid][PlayerStatus] = cache_get_field_content_int(0, "status");
		Player[playerid][PlayerID] = cache_get_field_content_int(0, "id");
	}
	else
	{
		mysql_format(connection, query, sizeof(query), "INSERT INTO `member`(`name`) VALUES ('%e')", name);
		mysql_query(connection, query, true);
		Player[playerid][PlayerID] = cache_insert_id();
	}
	return 1;
}

SendGangMessage(i, msg[])
{
	foreach(new p : Player)
	{
		if(i == Player[p][PlayerGang])
			SendClientMessage(p, -1, msg);
	}
	return 1;
}

stock Name(playerid)
{
	new name[MAX_PLAYER_NAME];
	GetPlayerName(playerid, name, MAX_PLAYER_NAME);
	return name;
}

public OnFilterScriptInit()
{
	print("\n\n\n========================================================");
	print("||                 X-Gang System by X337               ||");
	connection = mysql_connect(HOSTNAME, USERNAME, DATABASENAME, PASSWORD);
	if(mysql_errno(connection) != 0)
	{
		print("\n++++++++++++++++++    WARNING    ++++++++++++++++++++++\n");
		print("X-Gang System Filterscript failed to connect to database !\n");
		print("++++++++++++++++++    WARNING    ++++++++++++++++++++++\n");
		SendRconCommand("unloadfs X-Gang");
	}
	else
	{
		mysql_log(LOG_ERROR | LOG_WARNING, LOG_TYPE_HTML);
		print("||           Succesfully connected to database !       ||");
		mysql_query(connection, "SELECT * FROM `zone`", true);
		new count = cache_num_rows(), TempString[56], time = GetTickCount(), i;
		for(new z = 0; z < count; z++)
		{
			i = Iter_Free(GangZones);
			GangZone[i][ZoneMinPos][0] = cache_get_field_content_float(z, "minx");
			GangZone[i][ZoneMinPos][1] = cache_get_field_content_float(z, "miny");
			GangZone[i][ZoneMaxPos][0] = cache_get_field_content_float(z, "maxx");
			GangZone[i][ZoneMaxPos][1] = cache_get_field_content_float(z, "maxy");
			GangZone[i][ZoneOwner]	= GetGangID(cache_get_field_content_int(z, "owner"));
			GangZone[i][ZoneID]	= cache_get_field_content_int(z, "id");
			cache_get_field_content(z, "name", TempString);
			format(GangZone[i][ZoneName], 50, "%s", TempString);
			GangZone[i][ZoneArea] = Area_AddBox(GangZone[i][ZoneMinPos][0], GangZone[i][ZoneMinPos][1], GangZone[i][ZoneMaxPos][0], GangZone[i][ZoneMaxPos][1]);
			GangZone[i][ZoneHolder] = GangZoneCreate(GangZone[i][ZoneMinPos][0], GangZone[i][ZoneMinPos][1], GangZone[i][ZoneMaxPos][0], GangZone[i][ZoneMaxPos][1]);
			GangZone[i][ZoneLocked] = 0;
			GangZone[i][ZoneStatus] = false;
			Iter_Add(GangZones, i);
		}
		printf("||         %d Zone(s) Succesfully Loaded!!! (%d ms)     ||", count, (GetTickCount() - time));
		mysql_query(connection, "SELECT * FROM `gang`", true);
		count = cache_num_rows(), time = GetTickCount();
		for(new z = 0; z < count; z++)
		{
			i = Iter_Free(Gangs);
			Gang[i][GangID] = cache_get_field_content_int(z, "id");
			Gang[i][GangScore] = cache_get_field_content_int(z, "score");
			Gang[i][CurrentZone] = -1;
			cache_get_field_content(z, "name", TempString);
			format(Gang[i][GangName], 30, "%s", TempString);
			cache_get_field_content(z, "color", TempString);
			format(Gang[i][GangColor], 7, "%s", TempString);
			cache_get_field_content(z, "tag", TempString);
			format(Gang[i][GangTag], 4, "%s", TempString);
			Iter_Add(Gangs, i);
		}
		printf("||         %d Gang(s) Succesfully Loaded!!! (%d ms)     ||", count, (GetTickCount() - time));
		print("========================================================");
		foreach(new p : Player)
		{
			CallLocalFunction("OnPlayerConnect", "d", p);
		}
		AutoSaveTimer = SetTimer("AutoSave", AUTOSAVE * 60000, true);
	}
	return 1;
}

public OnFilterScriptExit()
{
	AutoSave();
	foreach(new i : GangZones)
	{
		GangZoneDestroy(GangZone[i][ZoneHolder]);
		Area_Delete(GangZone[i][ZoneArea]);
	}
	Iter_Clear(GangZones);
	foreach(new i : Player)
	{
		PlayerTextDrawHide(i, Player[i][TDZone][0]);
		PlayerTextDrawHide(i, Player[i][TDZone][1]);
	}
	KillTimer(AutoSaveTimer);
	print("X-Gang System Filterscript unloaded!\n");
	return 1;
}
public OnGameModeInit()
{
    usfg1= GangZoneCreate(2229.5146,-1852.6798,2094.9995,-1724.7993);
    usfg2= GangZoneCreate(1671.5801,1124.0054,1528.9078,1256.9685);//
    usfg3= GangZoneCreate(1568.0446,1499.8220,1719.1251,1649.4502);
    usfg4= GangZoneCreate(2033.6691,1094.5887,2181.2407,925.3813);
    usfg5= GangZoneCreate(198.7097,2827.4675,301.6852,2969.7229);
    usfg6= GangZoneCreate(1632.7483,-2332.9270,1773.2834,-2201.1335);
    usfg7= GangZoneCreate(1302.7275,-2096.5513,1198.5382,-1971.3167);
    usfg8= GangZoneCreate(339.0952,-1985.1588,439.0745,-2154.1660);
	return 1;
}

public OnGameModeExit()
{
	return 1;
}

public OnPlayerSpawn(playerid)
{
    GangZoneShowForPlayer(playerid, usfg1,0xAA3333AA);
    GangZoneShowForPlayer(playerid, usfg2,0xAA3333AA);
    GangZoneShowForPlayer(playerid, usfg3,0xAA3333AA);
    GangZoneShowForPlayer(playerid, usfg4,0xAA3333AA);
    GangZoneShowForPlayer(playerid, usfg5,0xAA3333AA);
    GangZoneShowForPlayer(playerid, usfg6,0xAA3333AA);
    GangZoneShowForPlayer(playerid, usfg7,0xAA3333AA);
    GangZoneShowForPlayer(playerid, usfg8,0xAA3333AA);
	return 1;
}
COMMAND:creategang(playerid, params[])
{
	if(GetPlayerScore(playerid) >= REQUIRED_SCORE)
	{
		if(Player[playerid][PlayerGang] == -1)
			ShowPlayerDialog(playerid, DIALOG_CREATEGANG, DIALOG_STYLE_INPUT, "USF - Gang Name", "Insert the gang name below :", "Submit", "Cancel");
		else
			SendClientMessage(playerid, -1, "{FF0000}You already in gang!");
	}
	else
	{
		new string[128];
		format(string, sizeof(string), "{FF0000}You need %d score to create a gang!", REQUIRED_SCORE);
		SendClientMessage(playerid, -1, string);
	}
	return 1;
}

COMMAND:gangcolor(playerid, params[])
{
	new i = Player[playerid][PlayerGang];
	if(i != -1)
	{
		new color[7];
		if(sscanf(params, "h", color) || strlen(params) != 6)
			SendClientMessage(playerid, -1, "{FF0000}Invalid hex color!");
		else
		{
			new msg[56];
			format(msg, sizeof(msg), "{%s}Your gang color has been changed!", params);
			SendClientMessage(playerid, -1, msg);
			format(Gang[i][GangColor], 7, "%s", params);
		}
	}
	else
		SendClientMessage(playerid, -1, "{FF0000}You must be a gang leader to use this command!");
	return 1;
}

COMMAND:changeleader(playerid, params[])
{
	if(Player[playerid][PlayerGang] != -1)
	{
		if(Player[playerid][PlayerStatus] == GANG_LEADER)
		{
			new id;
			if(sscanf(params, "u", id))
			{
				SendClientMessage(playerid, -1, "{FF0000}Usage : /changeleader <playerid>");
			}
			else
			{
				if(IsPlayerConnected(id))
				{
					if(Player[playerid][PlayerGang] == Player[id][PlayerGang])
					{
						Player[playerid][PlayerStatus] = GANG_MEMBER;
						Player[id][PlayerStatus] = GANG_LEADER;
						new msg[56];
						format(msg, sizeof(msg), "{FF0000}Succesfully promoted %s as new gang leader!", Name(id));
						SendClientMessage(playerid, -1, msg);
						SendClientMessage(id, -1, "{FF0000}You have been promoted as new gang leader!");
						SaveStats(id);
						SaveStats(playerid);
					}
					else
						SendClientMessage(playerid, -1, "{FF0000}That player isn't your gang member!");
				}
				else
					SendClientMessage(playerid, -1, "{FF0000}That player isn't connected!");
			}
		}
		else
			SendClientMessage(playerid, -1, "{FF0000}You must be a gang leader to use this command!");
	}
	else
		SendClientMessage(playerid, -1, "{FF0000}You must be a gang member to use this command!");
	return 1;
}

COMMAND:territory(playerid, params[])
{
	new msg[512], p;
	foreach(new i : GangZones)
	{
		p = GangZone[i][ZoneOwner];
		if(p == -1)
			format(msg, sizeof(msg), "%s{B7B7B7}%s (-)\n", msg, GangZone[i][ZoneName]);
		else
			format(msg, sizeof(msg), "%s{%s}%s (%s)\n", msg, Gang[p][GangColor], GangZone[i][ZoneName], Gang[p][GangName]);
	}
	ShowPlayerDialog(playerid, DIALOG_UNUSED, DIALOG_STYLE_MSGBOX, "Territory", msg, "Close", "");
	return 1;
}

COMMAND:gangmembers(playerid, params[])
{
	new i = Player[playerid][PlayerGang];
	if(i != -1)
	{
		new query[256];
		mysql_format(connection, query, sizeof(query), "SELECT * FROM `member` WHERE `gang` = %d", Gang[i][GangID]);
		mysql_query(connection, query, true);
		format(query, sizeof(query), "{FFFFFF}");
		new count = cache_num_rows();
		if(count > 0)
		{
			new TempString[MAX_PLAYER_NAME], tempid;
			for(new r = 0; r < count; r++)
			{
				cache_get_field_content(r, "name", TempString);
				tempid = GetID(TempString);
				format(query, sizeof(query), "%s%d. %s ", query, (r+1), TempString);
				if(IsPlayerConnected(tempid))
					strcat(query, "{FE9A2E}(ONLINE) ");
				else
					strcat(query, "{FF0000}(OFFLINE) ");
				if(cache_get_field_content_int(r, "status") == GANG_LEADER)
					strcat(query, "{58D3F7} (LEADER) ");
				if(cache_get_field_content_int(r, "status") == GANG_STAFF)
					strcat(query, "{58D3F7} (STAFF) ");
				strcat(query, "\n{FFFFFF}");
			}
			ShowPlayerDialog(playerid, DIALOG_UNUSED, DIALOG_STYLE_MSGBOX, "Gang Members", query, "Close", "");
		}
	}
	else
		SendClientMessage(playerid, -1, "{FF0000}You must be a gang member to use this command!");
	return 1;
}

COMMAND:gcp(playerid, params[])
{
	new i = Player[playerid][PlayerGang];
	if(i != -1)
	{
		if(Iter_Contains(Gangs, i))
		{
			new msg[256];
			format(msg, sizeof(msg), "{FFFFFF}Gang Name : {%s}%s {FFFFFF}", Gang[i][GangColor], Gang[i][GangName]);
			format(msg, sizeof(msg), "%s\nGang Tag : [%s]", msg, Gang[i][GangTag]);
			format(msg, sizeof(msg), "%s\nGang Score : %d", msg, Gang[i][GangScore]);
			format(msg, sizeof(msg), "%s\n{B7B7B7}Gang Member", msg);
			format(msg, sizeof(msg), "%s\n{B7B7B7}Territory", msg);
			ShowPlayerDialog(playerid, DIALOG_GCP, DIALOG_STYLE_LIST, "Gang Control Panel", msg, "Chooose", "Cancel");
		}
	}
	else
		SendClientMessage(playerid, -1, "{FF0000}You must be a gang member to use this command!");
	return 1;
}

COMMAND:leavegang(playerid, params[])
{
	new i = Player[playerid][PlayerGang];
	if(i != -1)
	{
		if(Player[playerid][PlayerStatus] != GANG_LEADER)
		{
			new msg[56];
			format(msg, sizeof(msg), "{FF0000}%s left the gang!", Name(playerid));
			SendGangMessage(Player[playerid][PlayerGang], msg);
			Player[playerid][PlayerGang] = -1;
			SaveStats(playerid);
		}
		else
			SendClientMessage(playerid, -1, "{FF0000}Gang leader can't use this command!");
	}
	return 1;
}

COMMAND:disbandgang(playerid, params[])
{
	new i = Player[playerid][PlayerGang];
	if(i != -1)
	{
		if(Player[playerid][PlayerStatus] == GANG_LEADER)
		{
			if(Gang[i][CurrentZone] == -1)
			{
				new query[256];
				format(query, sizeof(query), "{FF0000}%s has disbanded the gang!", Name(playerid));
				SendGangMessage(i, query);
				mysql_format(connection, query, sizeof(query), "DELETE FROM `gang` WHERE `id` = %d", Gang[i][GangID]);
				mysql_query(connection, query, false);
				foreach(new p : Player)
				{
					if(Player[p][PlayerGang] == i)
					{
						Player[p][PlayerGang] = -1;
						Player[p][PlayerStatus] = GANG_MEMBER;
					}
				}
				mysql_format(connection, query, sizeof(query), "UPDATE `member` SET `gang` = -1, `status` = 1 WHERE `gang` = %d", Gang[i][GangID]);
				mysql_query(connection, query, false);
				Iter_Remove(Gangs, i);
				foreach(new p : GangZones)
				{
					if(GangZone[p][ZoneOwner] == i)
					{
						GangZone[p][ZoneOwner] = -1;
						GangZoneShowForAll(GangZone[p][ZoneHolder], HexToInt(DEFAULT_ZONE_COLOR));
					}
				}
			}
		}
		else
			SendClientMessage(playerid, -1, "{FF0000}You must be gang leader to use this command!!");
	}
	else
		SendClientMessage(playerid, -1, "{FF0000}You must be gang leader to use this command!!");
	return 1;
}

COMMAND:topgang(playerid, params[])
{
	new query[128];
	mysql_format(connection, query, sizeof(query), "SELECT * FROM `gang` ORDER BY `score` DESC LIMIT 20");
	mysql_query(connection, query, true);
	new ganglist[512], count = cache_num_rows(), TempColor[7], TempName[30];
	if(count != 0)
	{
		for(new i = 0; i < count; i++)
		{
			cache_get_field_content(i, "color", TempColor);
			cache_get_field_content(i, "name", TempName);
			format(ganglist, sizeof(ganglist), "%s%d. {%s}%s {FFFFFF}- Score : %d\n", ganglist, (i+1), TempColor, TempName, cache_get_field_content_int(i, "score"));
		}
		format(ganglist, sizeof(ganglist), "%s\n* This top list updated every %d minutes", ganglist, AUTOSAVE);
		ShowPlayerDialog(playerid, DIALOG_UNUSED, DIALOG_STYLE_MSGBOX, "Top Gangs", ganglist, "Close", "");
	}
	else
		SendClientMessage(playerid, -1, "{FF0000}There's no gangs present!");
	return 1;
}

COMMAND:gangrank(playerid, params[])
{
	new TempName[30];
	if(sscanf(params, "s[30]", TempName))
	{
		SendClientMessage(playerid, -1, "{FF0000}Usage : /gangrank <gang name>");
	}
	else
	{
		new query[512];
		mysql_format(connection, query, sizeof(query), "SELECT `rank` FROM (SELECT `name`,`score`, @current := @current + 1 as `rank` from `gang`, (select @current := 0) r order by `score` desc) z WHERE `name` = '%e'", TempName);
		mysql_query(connection, query, true);
		if(cache_num_rows() != 0)
		{
			new msg[56];
			format(msg, sizeof(msg), "{FF0000}%s - {FFFF00}Rank : %d", TempName, cache_get_field_content_int(0, "rank"));
			SendClientMessage(playerid, -1, msg);
		}
		else
			SendClientMessage(playerid, -1, "404! Gang name not found!");
	}
	return 1;
}

COMMAND:promotestaff(playerid, params[])
{
	if(Player[playerid][PlayerStatus] == GANG_LEADER)
	{
		new id;
		if(sscanf(params, "u", id))
		{
			SendClientMessage(playerid, -1, "{FF0000}Usage : /promotestaff <playerid>");
		}
		else
		{
			if(IsPlayerConnected(id))
			{
				if(Player[id][PlayerGang] == Player[playerid][PlayerGang])
				{
					if(id != playerid)
					{
						if(Player[id][PlayerStatus] != GANG_STAFF)
						{
							SendClientMessage(playerid, -1, "{FF0000}Succesfully promoted a gang staff!");
							SendClientMessage(id, -1, "{FF0000}You have been promoted as a gang staff!");
							Player[id][PlayerStatus] = GANG_STAFF;
							SaveStats(id);
						}
						else
							SendClientMessage(playerid, -1, "{FF0000}That player already a gang staff!");
					}
					else
						SendClientMessage(playerid, -1, "{FF0000}You can't promote yourself!");
				}
				else
					SendClientMessage(playerid, -1, "{FF0000}That player isn't your gang member!");
			}
			else
				SendClientMessage(playerid, -1, "{FF0000}That player isn't connected!");
		}
	}
	else
		SendClientMessage(playerid, -1, "{FF0000}You must be gang leader to use this command!!");
	return 1;
}

COMMAND:demotestaff(playerid, params[])
{
	if(Player[playerid][PlayerStatus] == GANG_LEADER)
	{
		new id;
		if(sscanf(params, "u", id))
		{
			SendClientMessage(playerid, -1, "{FF0000}Usage : /demotestaff <playerid>");
		}
		else
		{
			if(IsPlayerConnected(id))
			{
				if(Player[id][PlayerGang] == Player[playerid][PlayerGang])
				{
					if(id != playerid)
					{
						if(Player[id][PlayerStatus] == GANG_STAFF)
						{
							SendClientMessage(playerid, -1, "{FF0000}Succesfully promoted a gang staff!");
							SendClientMessage(id, -1, "{FF0000}You have been demoted from gang staff!");
							Player[id][PlayerStatus] = GANG_MEMBER;
							SaveStats(id);
						}
						else
							SendClientMessage(playerid, -1, "{FF0000}That player isn't a gang staff!");
					}
					else
						SendClientMessage(playerid, -1, "{FF0000}You can't demote yourself!");
				}
				else
					SendClientMessage(playerid, -1, "{FF0000}That player isn't your gang member!");
			}
			else
				SendClientMessage(playerid, -1, "{FF0000}That player isn't connected!");
		}
	}
	else
		SendClientMessage(playerid, -1, "{FF0000}You must be gang leader to use this command!!");
	return 1;
}

COMMAND:createzone(playerid, params[])
{
	if(IsPlayerAdmin(playerid))
	{
		if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
		{
			if(!Player[playerid][CreatingZone])
			{
				new Float:z;
				Player[playerid][CreatingZone] = true;
				new msg[128];
				format(msg, sizeof(msg), "Gangzone Mode! Use arrow keys to make the zone bigger or less");
				SendClientMessage(playerid, -1, msg);
				format(msg, sizeof(msg), "Using ~k~~PED_FIREWEAPON~ + Arrow keys you minus the height or width.");
				SendClientMessage(playerid, -1, msg);
				format(msg, sizeof(msg), "Press ~k~~VEHICLE_ENTER_EXIT~ when you are done!");
				SendClientMessage(playerid, -1, msg);
				GetPlayerPos(playerid, MinPos[playerid][0], MinPos[playerid][1], z);
				GetPlayerPos(playerid, MaxPos[playerid][0], MaxPos[playerid][1], z);
				TogglePlayerControllable(playerid, false);
			}
			else
				SendClientMessage(playerid, -1, "You already in create zone mode, /cancelzone to cancel");
		}
		else
			SendClientMessage(playerid, -1, "You must be onfoot to create gang zone");
	}
	else
		SendClientMessage(playerid, -1, "{FF0000}You must be RCON admin to use this command!");
	return 1;
}

COMMAND:ginvite(playerid, params[])
{
	new p;
	if(Player[playerid][PlayerStatus] == GANG_LEADER && Player[playerid][PlayerGang] != -1)
	{
		if(sscanf(params, "d", p))
		{
			SendClientMessage(playerid, -1, "{FF0000}Usage : /ganginvite <playerid>");
		}
		else
		{
			if(IsPlayerConnected(p))
			{
				if(Player[p][PlayerGang] == -1)
				{
					if(CheckGang(Player[playerid][PlayerGang]))
					{
						new msg[128];
						format(msg, sizeof(msg), "%s want you to join %s gang! (/acceptgang)", Name(playerid), Gang[Player[playerid][PlayerGang]][GangName]);
						SendClientMessage(p, -1, msg);
						format(msg, sizeof(msg), "You have invited %s to join your gang!", Name(p));
						SendClientMessage(playerid, -1, msg);
						Player[p][GangRequest] = Player[playerid][PlayerGang];
					}
					else
						SendClientMessage(playerid, -1, "{FF0000}Your gang member is full!");
				}
				else
					SendClientMessage(playerid, -1, "{FF0000}That player already a gang member!");
			}
			else
				SendClientMessage(playerid, -1, "{FF0000}That player isn't connected!");
		}
	}
	else
		SendClientMessage(playerid, -1, "{FF0000}You must be a gang leader to use this command!");
	return 1;
}

COMMAND:acceptg(playerid, params[])
{
	if(Player[playerid][PlayerGang] == -1)
	{
		if(Player[playerid][GangRequest] != -1)
		{
			if(Iter_Contains(Gangs, Player[playerid][GangRequest]))
			{
				if(CheckGang(Player[playerid][GangRequest]))
				{
					Player[playerid][PlayerGang] = Player[playerid][GangRequest];
					Player[playerid][GangRequest] = -1;
					Player[playerid][PlayerStatus] = GANG_MEMBER;
					new msg[56];
					format(msg, sizeof(msg), "%s has joined the gang!", Name(playerid));
					SendGangMessage(Player[playerid][PlayerGang], msg);
				}
			}
			else
				SendClientMessage(playerid, -1, "{FF0000}Invalid Session!");
		}
	}
	else
		SendClientMessage(playerid, -1, "{FF0000}You already inside a gang!");
	return 1;
}

COMMAND:g(playerid, params[])
{
	new i = Player[playerid][PlayerGang];
	if(i != -1)
	{
		new	msg[128];
		format(msg, sizeof(msg), "{%s}* %s(%d) {FFFFFF}: %s", Gang[i][GangColor], Name(playerid), playerid, params);
		SendGangMessage(Player[playerid][PlayerGang], msg);
	}
	else
		SendClientMessage(playerid, -1, "{FF0000}You must be a gang member to use this command!");
	return 1;
}
COMMAND:god(playerid, params[])
{
     if(Cantuse[playerid] == 1) return SendClientMessage(playerid, -1, "{FF0000}You Cant use this cmd in gwar!");
     return 1;
}

COMMAND:gwar(playerid, params[])
{
    if(Player[playerid][PlayerGang] != -1)
    {
        if(Gang[Player[playerid][PlayerGang]][CurrentZone] == -1)
        {
            new bool:found = false, i, total = 0, area = Area_GetPlayerAreas(playerid, 0);
            foreach(i : GangZones)
            {
                if(area == GangZone[i][ZoneArea])
                {
                    found = true;
                    break;
                }
            }
            if(found)
            {
                if(!GangZone[i][ZoneStatus])
                {
                    if(GangZone[i][ZoneOwner] != Player[playerid][PlayerGang])
                    {
                        new tick = GetTickCount() - GangZone[i][ZoneLocked], msg[128];
                        if(tick > (60000 * LOCKED_MINUTES))
                        {
                            format(msg, sizeof(msg), "Capturing ~g~%s", GangZone[i][ZoneName]);
                            foreach(new p : Player)
                            {
                            if(Player[p][PlayerGang] == Player[playerid][PlayerGang])
                                {
                                    if(Area_GetPlayerAreas(p, 0) == area)
                                    total++;
                                    PlayerTextDrawSetString(p, Player[p][CaptureTD][0], msg);
                                    PlayerTextDrawSetString(p, Player[p][CaptureTD][1], "-");
                                    PlayerTextDrawShow(p, Player[p][CaptureTD][0]);
                                    PlayerTextDrawShow(p, Player[p][CaptureTD][1]);
                                    Gang[Player[playerid][PlayerGang]][GangTimer] = CAPTURE_TIME;
                                }
                            }
                            format(msg, sizeof(msg), "{FE9A2E}** %s gang trying to capture %s zone with %d gang member!", Gang[Player[playerid][PlayerGang]][GangName], GangZone[i][ZoneName], total);
                            SendClientMessageToAll(-1, msg);
                            SendPlayerMessageToPlayer(0, playerid, "{FE9A2E}Before Gwar Make Sure you have disabled the GOTO Use /toggoto before gwar");
                            GangZone[i][ZoneStatus] = true;
                            GangZone[i][ZoneTimer] = SetTimerEx("AttackZone", 1000, true, "dd", Player[playerid][PlayerGang], i);
                            Gang[Player[playerid][PlayerGang]][CurrentZone] = i;
                            Cantuse[playerid] = 1;
                            GangZoneFlashForAll(GangZone[i][ZoneHolder], HexToInt("FF0000AA"));
                            if(GangZone[i][ZoneOwner] != -1)
                            {
                                format(msg, sizeof(msg), "{FF0000}* ALERT!!! %s gang trying to capture your territory in %s", Gang[Player[playerid][PlayerGang]][GangName], GangZone[i][ZoneName]);
                                SendGangMessage(GangZone[i][ZoneOwner], msg);
                            }
                        }
                        else
                        {
                            format(msg, sizeof(msg), "{FF0000}This Zone is locked, please wait %.2f minute(s) to capture!", floatdiv(60000 * LOCKED_MINUTES - tick, 60 * 1000));
                            SendClientMessage(playerid, -1, msg);
                        }
                    }
                    else
                        SendClientMessage(playerid, -1, "{FF0000}Your gang already owned this zone!");
                }
                else
                    SendClientMessage(playerid, -1, "{FF0000}Someone is trying to capture this zone!");
            }
            else
                SendClientMessage(playerid, -1, "{FF0000}You must be in gang zone to use this command!");
        }
        else
            SendClientMessage(playerid, -1, "{FF0000}Your gang already started a war, please wait!");
    }
    else
        SendClientMessage(playerid, -1, "{FF0000}You must be a gang member to use this command!");
    return 1;
}

COMMAND:okickmember(playerid, params[])
{
	new TempName[MAX_PLAYER_NAME];
	if(sscanf(params, "s[24]", TempName))
	{
		SendClientMessage(playerid, -1, "{FF0000}Usage : /okickmember <member name>");
	}
	else
	{
		new query[256], i = Player[playerid][PlayerGang];
		mysql_format(connection, query, sizeof(query), "SELECT * FROM `member` WHERE `name` = '%e'", TempName);
		mysql_query(connection, query, true);
		if(cache_num_rows() != 0)
		{
			if(cache_get_field_content_int(0, "gang") == Gang[i][GangID])
			{
				if(cache_get_field_content_int(0, "id") != Player[playerid][PlayerID])
				{
					if(cache_get_field_content_int(0, "status") != GANG_LEADER)
					{
						mysql_format(connection, query, sizeof(query), "UPDATE `member` SET `gang` = -1, `status` = 1 WHERE `name` = '%e'", TempName);
						mysql_query(connection, query, false);
						format(query, sizeof(query), "{FF0000}%s has been kicked from gang!", TempName);
						SendGangMessage(i, query);
						new p = GetID(TempName);
						if(IsPlayerConnected(p))
						{
							SendClientMessage(p, -1, "{FF0000}You have been kicked from gang!");
							Player[p][PlayerGang] = -1;
							Player[p][PlayerStatus] = GANG_MEMBER;
						}
					}
					else
						SendClientMessage(playerid, -1, "{FF0000}You can't kick gang leader!");
				}
				else
					SendClientMessage(playerid, -1, "{FF0000}You can't kick yourself!");
			}
			else
				SendClientMessage(playerid, -1, "{FF0000}That player isn't in your gang!");
		}
		else
			SendClientMessage(playerid, -1, "{FF0000}404! Name not found!");
	}
	return 1;
}

COMMAND:kickmember(playerid, params[])
{
	new p;
	if(Player[playerid][PlayerStatus] != GANG_MEMBER && Player[playerid][PlayerGang] != -1)
	{
		if(sscanf(params, "d", p))
		{
			SendClientMessage(playerid, -1, "{FF0000}Usage : /kickmember <playerid>");
		}
		else
		{
			if(IsPlayerConnected(p))
			{
				if(Player[playerid][PlayerGang] == Player[p][PlayerGang])
				{
					if(playerid != p)
					{
						if(Player[p][PlayerStatus] != GANG_LEADER)
						{
							new msg[56], query[256];
							format(msg, sizeof(msg), "{FF0000}%s has been kicked from gang!", Name(p));
							SendGangMessage(Player[playerid][PlayerGang], msg);
							Player[p][PlayerGang] = -1;
							Player[p][PlayerStatus] = GANG_MEMBER;
							mysql_format(connection, query, sizeof(query), "UPDATE `member` SET `gang` = -1, `status` = 1 WHERE `id` = '%d'", Player[p][PlayerID]);
							mysql_query(connection, query, false);
						}
						else
							SendClientMessage(playerid, -1, "{FF0000}You can't kick gang leader!");
					}
					else
						SendClientMessage(playerid, -1, "{FF0000}You can't kick yourself!");
				}
				else
					SendClientMessage(playerid, -1, "{FF0000}That player isn't in your gang!");
			}
			else
				SendClientMessage(playerid, -1, "{FF0000}That player isn't connected!");
		}
	}
	else
		SendClientMessage(playerid, -1, "{FF0000}You must be a gang leader to use this command!");
	return 1;
}

public OnPlayerConnect(playerid)
{

	Player[playerid][CreatingZone] = false;
	Player[playerid][TDZone][0] = CreatePlayerTextDraw(playerid, 320.000000, 376.666290, "ZONE NAME");
	PlayerTextDrawLetterSize(playerid, Player[playerid][TDZone][0], 0.400000, 1.600000);
	PlayerTextDrawAlignment(playerid, Player[playerid][TDZone][0], 2);
	PlayerTextDrawColor(playerid, Player[playerid][TDZone][0], -1);
	PlayerTextDrawSetShadow(playerid, Player[playerid][TDZone][0], 0);
	PlayerTextDrawSetOutline(playerid, Player[playerid][TDZone][0], 1);
	PlayerTextDrawBackgroundColor(playerid, Player[playerid][TDZone][0], 255);
	PlayerTextDrawFont(playerid, Player[playerid][TDZone][0], 3);
	PlayerTextDrawSetProportional(playerid, Player[playerid][TDZone][0], 1);
	PlayerTextDrawSetShadow(playerid, Player[playerid][TDZone][0], 0);

	Player[playerid][TDZone][1] = CreatePlayerTextDraw(playerid, 318.000000, 391.599609, "Owned By : ~r~Unowned");
	PlayerTextDrawLetterSize(playerid, Player[playerid][TDZone][1], 0.264999, 1.310666);
	PlayerTextDrawAlignment(playerid, Player[playerid][TDZone][1], 2);
	PlayerTextDrawColor(playerid, Player[playerid][TDZone][1], -1);
	PlayerTextDrawSetShadow(playerid, Player[playerid][TDZone][1], 1);
	PlayerTextDrawSetOutline(playerid, Player[playerid][TDZone][1], 0);
	PlayerTextDrawBackgroundColor(playerid, Player[playerid][TDZone][1], 255);
	PlayerTextDrawFont(playerid, Player[playerid][TDZone][1], 1);
	PlayerTextDrawSetProportional(playerid, Player[playerid][TDZone][1], 1);
	PlayerTextDrawSetShadow(playerid, Player[playerid][TDZone][1], 1);

	Player[playerid][CaptureTD][0] = CreatePlayerTextDraw(playerid, 633.000000, 358.000030, "");
	PlayerTextDrawLetterSize(playerid, Player[playerid][CaptureTD][0], 0.323000, 1.357333);
	PlayerTextDrawAlignment(playerid, Player[playerid][CaptureTD][0], 3);
	PlayerTextDrawColor(playerid, Player[playerid][CaptureTD][0], -1);
	PlayerTextDrawSetShadow(playerid, Player[playerid][CaptureTD][0], 1);
	PlayerTextDrawSetOutline(playerid, Player[playerid][CaptureTD][0], 0);
	PlayerTextDrawBackgroundColor(playerid, Player[playerid][CaptureTD][0], 255);
	PlayerTextDrawFont(playerid, Player[playerid][CaptureTD][0], 1);
	PlayerTextDrawSetProportional(playerid, Player[playerid][CaptureTD][0], 1);
	PlayerTextDrawSetShadow(playerid, Player[playerid][CaptureTD][0], 1);

	Player[playerid][CaptureTD][1] = CreatePlayerTextDraw(playerid, 633.000000, 343.999938, "00:00");
	PlayerTextDrawLetterSize(playerid, Player[playerid][CaptureTD][1], 0.400000, 1.600000);
	PlayerTextDrawAlignment(playerid, Player[playerid][CaptureTD][1], 3);
	PlayerTextDrawColor(playerid, Player[playerid][CaptureTD][1], -1);
	PlayerTextDrawSetShadow(playerid, Player[playerid][CaptureTD][1], 0);
	PlayerTextDrawSetOutline(playerid, Player[playerid][CaptureTD][1], 1);
	PlayerTextDrawBackgroundColor(playerid, Player[playerid][CaptureTD][1], 255);
	PlayerTextDrawFont(playerid, Player[playerid][CaptureTD][1], 3);
	PlayerTextDrawSetProportional(playerid, Player[playerid][CaptureTD][1], 1);
	PlayerTextDrawSetShadow(playerid, Player[playerid][CaptureTD][1], 0);

	LoadPlayerGang(playerid);
	foreach(new i : GangZones)
	{
		if(GangZone[i][ZoneOwner] == -1)
			GangZoneShowForPlayer(playerid, GangZone[i][ZoneHolder], HexToInt(DEFAULT_ZONE_COLOR));
		else
		{
			new colour[9];
			format(colour, 9, "%s50", Gang[GangZone[i][ZoneOwner]][GangColor]);
			GangZoneShowForPlayer(playerid, GangZone[i][ZoneHolder], HexToInt(colour));
		}
	}
	return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
	new i = Player[playerid][PlayerGang], msg[56];
	SaveStats(playerid);
	if(Iter_Contains(Gangs, i) && i != -1)
	{
		new zone = Gang[i][CurrentZone], total = -1;
		if(zone != -1)
		{
			total = 0;
			foreach(new p : Player)
			{
				if(Player[p][PlayerGang] == Player[playerid][PlayerGang])
				{
					if(Area_GetPlayerAreas(p, 0) == GangZone[zone][ZoneArea])
						total++;
				}
			}
		}
		if(total == 0)
		{
			format(msg, sizeof(msg), "{FF0000}** %s gang failed to capture %s zone!", Gang[Player[playerid][PlayerGang]][GangName], GangZone[zone][ZoneName]);
			SendClientMessageToAll(-1, msg);
			format(msg, sizeof(msg), "{FF0000}** %s zone will be locked for %d minutes!", GangZone[zone][ZoneName], LOCKED_MINUTES);
			SendClientMessageToAll(-1, msg);
			Gang[Player[playerid][PlayerGang]][CurrentZone] = -1;
			GangZone[zone][ZoneLocked] = GetTickCount();
			GangZone[zone][ZoneStatus] = false;
			GangZoneStopFlashForAll(GangZone[zone][ZoneHolder]);
		}
		format(msg, sizeof(msg), "%s has been logged out!", Name(playerid));
		SendGangMessage(i, msg);
	}
	return 1;
}

public OnPlayerUpdate(playerid) //RyDer
{
	if(Player[playerid][CreatingZone])
	{
		new Keys, UpDown, LeftRight;
		GetPlayerKeys(playerid, Keys, UpDown, LeftRight);
		TogglePlayerControllable(playerid, false);
		if(LeftRight == KEY_LEFT)
		{
			MinPos[playerid][0] -= 8.0;
			GangZoneDestroy(PlayerZone[playerid]);
			PlayerZone[playerid] = GangZoneCreate(MinPos[playerid][0], MinPos[playerid][1], MaxPos[playerid][0], MaxPos[playerid][1]);
			GangZoneShowForPlayer(playerid, PlayerZone[playerid], HexToInt("000000FF"));
		}
		else if(LeftRight & KEY_LEFT && Keys & KEY_FIRE)
		{
			MinPos[playerid][0] += 8.0;
			GangZoneDestroy(PlayerZone[playerid]);
			PlayerZone[playerid] = GangZoneCreate(MinPos[playerid][0], MinPos[playerid][1], MaxPos[playerid][0], MaxPos[playerid][1]);
			GangZoneShowForPlayer(playerid, PlayerZone[playerid], HexToInt("000000FF"));
		}
		else if(LeftRight == KEY_RIGHT)
		{
			MaxPos[playerid][0] += 8.0;
			GangZoneDestroy(PlayerZone[playerid]);
			PlayerZone[playerid] = GangZoneCreate(MinPos[playerid][0], MinPos[playerid][1], MaxPos[playerid][0], MaxPos[playerid][1]);
			GangZoneShowForPlayer(playerid, PlayerZone[playerid], HexToInt("000000FF"));
		}
		else if(LeftRight & KEY_RIGHT && Keys & KEY_FIRE)
		{
			MaxPos[playerid][0] -= 8.0;
			GangZoneDestroy(PlayerZone[playerid]);
			PlayerZone[playerid] = GangZoneCreate(MinPos[playerid][0], MinPos[playerid][1], MaxPos[playerid][0], MaxPos[playerid][1]);
			GangZoneShowForPlayer(playerid, PlayerZone[playerid], HexToInt("000000FF"));
		}
		else if(UpDown == KEY_UP)
		{
			MaxPos[playerid][1] += 8.0;
			GangZoneDestroy(PlayerZone[playerid]);
			PlayerZone[playerid] = GangZoneCreate(MinPos[playerid][0], MinPos[playerid][1], MaxPos[playerid][0], MaxPos[playerid][1]);
			GangZoneShowForPlayer(playerid, PlayerZone[playerid], HexToInt("000000FF"));
		}
		else if(UpDown & KEY_UP && Keys & KEY_FIRE)
		{
			MaxPos[playerid][1] -= 8.0;
			GangZoneDestroy(PlayerZone[playerid]);
			PlayerZone[playerid] = GangZoneCreate(MinPos[playerid][0], MinPos[playerid][1], MaxPos[playerid][0], MaxPos[playerid][1]);
			GangZoneShowForPlayer(playerid, PlayerZone[playerid], HexToInt("000000FF"));
		}
		else if(UpDown == KEY_DOWN)
		{
			MinPos[playerid][1] -= 8.0;
			GangZoneDestroy(PlayerZone[playerid]);
			PlayerZone[playerid] = GangZoneCreate(MinPos[playerid][0], MinPos[playerid][1], MaxPos[playerid][0], MaxPos[playerid][1]);
			GangZoneShowForPlayer(playerid, PlayerZone[playerid], HexToInt("000000FF"));
		}
		else if(UpDown & KEY_DOWN && Keys & KEY_FIRE)
		{
			MinPos[playerid][1] += 8.0;
			GangZoneDestroy(PlayerZone[playerid]);
			PlayerZone[playerid] = GangZoneCreate(MinPos[playerid][0], MinPos[playerid][1], MaxPos[playerid][0], MaxPos[playerid][1]);
			GangZoneShowForPlayer(playerid, PlayerZone[playerid], HexToInt("000000FF"));
		}
		else if(Keys & KEY_SECONDARY_ATTACK)
		{
			TogglePlayerControllable(playerid, true);
			Player[playerid][CreatingZone] = false;
			ShowPlayerDialog(playerid, DIALOG_SAVEZONE, DIALOG_STYLE_INPUT, "USF", "Input gang zone name below, press \"Delete\" to delete current zone", "Save", "Delete");
		}
	}
	return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
	if(Player[playerid][PlayerGang] != -1)
	{
		new zone = Gang[Player[playerid][PlayerGang]][CurrentZone], total = -1;
		if(zone != -1)
		{
			total = 0;
			foreach(new p : Player)
			{
				if(Player[p][PlayerGang] == Player[playerid][PlayerGang])
				{
					if(Area_GetPlayerAreas(p, 0) == GangZone[zone][ZoneArea])
						total++;
				}
			}
		}
		if(total == 0)
		{
			new msg[128];
			format(msg, sizeof(msg), "{FF0000}** %s gang failed to capture %s zone!", Gang[Player[playerid][PlayerGang]][GangName], GangZone[zone][ZoneName]);
			SendClientMessageToAll(-1, msg);
			format(msg, sizeof(msg), "{FF0000}** %s zone will be locked for %d minutes!", GangZone[zone][ZoneName], LOCKED_MINUTES);
			SendClientMessageToAll(-1, msg);
			Gang[Player[playerid][PlayerGang]][CurrentZone] = -1;
			GangZone[zone][ZoneLocked] = GetTickCount();
			GangZone[zone][ZoneStatus] = false;
			GangZoneStopFlashForAll(GangZone[zone][ZoneHolder]);
		}
	}
	return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	switch(dialogid)
	{
		case DIALOG_SAVEZONE:
		{
			if(response)
			{
				if(strlen(inputtext) < 3 || strlen(inputtext) > 50)
					ShowPlayerDialog(playerid, DIALOG_SAVEZONE, DIALOG_STYLE_INPUT, "USF", "{FF0000}Gang zone name must be between 3 - 50 characters! \nInput gang zone name below, press \"Delete\" to delete current zone", "Save", "Delete");
				else
				{
					new query[256];
					mysql_format(connection, query, sizeof(query), "INSERT INTO `zone` (`minx`, `miny`, `maxx`, `maxy`, `name`) VALUES('%f', '%f', '%f', '%f', '%e')", MinPos[playerid][0], MinPos[playerid][1], MaxPos[playerid][0], MaxPos[playerid][1], inputtext);
					mysql_query(connection, query, true);
					GangZoneDestroy(PlayerZone[playerid]);
					new i = Iter_Free(GangZones);
					GangZone[i][ZoneMinPos][0] = MinPos[playerid][0];
					GangZone[i][ZoneMinPos][1] = MinPos[playerid][1];
					GangZone[i][ZoneMaxPos][0] = MaxPos[playerid][0];
					GangZone[i][ZoneMaxPos][1] = MaxPos[playerid][1];
					GangZone[i][ZoneOwner] = -1;
					format(GangZone[i][ZoneName], 50, "%s", inputtext);
					GangZone[i][ZoneID] = cache_insert_id();
					GangZone[i][ZoneArea] = Area_AddBox(MinPos[playerid][0], MinPos[playerid][1], MaxPos[playerid][0], MaxPos[playerid][1]);
					GangZone[i][ZoneHolder] = GangZoneCreate(MinPos[playerid][0], MinPos[playerid][1], MaxPos[playerid][0], MaxPos[playerid][1]);
					GangZone[i][ZoneLocked] = 0;
					GangZone[i][ZoneStatus] = false;
					GangZoneShowForAll(GangZone[i][ZoneHolder], HexToInt(DEFAULT_ZONE_COLOR));
					Iter_Add(GangZones, i);
				}
			}
			else
				GangZoneDestroy(PlayerZone[playerid]);
		}
		case DIALOG_CREATEGANG:
		{
			if(response)
			{
				if(strlen(inputtext) < 5 || strlen(inputtext) > 30)
				{
					ShowPlayerDialog(playerid, DIALOG_CREATEGANG, DIALOG_STYLE_INPUT, "USF - Gang Name", "{FF0000}Gang name must be between 5 - 30 characters! \nInsert the gang name below :", "Submit", "Cancel");
				}
				else if(!IsAlpha(inputtext))
				{
					ShowPlayerDialog(playerid, DIALOG_CREATEGANG, DIALOG_STYLE_INPUT, "USF - Gang Name", "{FF0000}Please insert only a-z,A-Z,0-9 character! \nInsert the gang name below :", "Submit", "Cancel");
				}
				else
				{
					strcpy(TempGangName[playerid], inputtext);
					ShowPlayerDialog(playerid, DIALOG_GANGTAG, DIALOG_STYLE_INPUT, "USF - Gang Tag", "Insert the gang tag below :", "Submit", "Cancel");
				}
			}
		}
		case DIALOG_GANGTAG:
		{
			if(response)
			{
				if(strlen(inputtext) < 1 || strlen(inputtext) > 3)
				{
					ShowPlayerDialog(playerid, DIALOG_GANGTAG, DIALOG_STYLE_INPUT, "USF - Gang Tag", "{FF0000}Gang tag must be between 1 - 3 character! \nInsert the gang tag below :", "Submit", "Cancel");
				}
				else if(!IsAlpha(inputtext))
				{
					ShowPlayerDialog(playerid, DIALOG_GANGTAG, DIALOG_STYLE_INPUT, "USF - Gang Tag", "{FF0000}Please insert only a-z,A-Z,0-9 character! \nInsert the gang tag below :", "Submit", "Cancel");
				}
				else
				{
					strcpy(TempGangTag[playerid], inputtext);
					ShowPlayerDialog(playerid, DIALOG_GANGCOLOUR, DIALOG_STYLE_LIST, "USF - Gang Colour",
					"{00FFFF}Aqua \n{000000}Black \n{0000FF}Blue \n{A52A2A}Brown \n{FF0000}Red \n{FFFFFF}Use HEX Colour", "Choose", "Cancel");
				}
			}
		}
		case DIALOG_GANGCOLOUR:
		{
			if(response)
			{
				switch(listitem)
				{
					case 0:
						strcpy(TempGangColour[playerid], "00FFFF");
					case 1:
						strcpy(TempGangColour[playerid], "000000");
					case 2:
						strcpy(TempGangColour[playerid], "0000FF");
					case 3:
						strcpy(TempGangColour[playerid], "A52A2A");
					case 4:
						strcpy(TempGangColour[playerid], "FF0000");
					case 5:
					{
						ShowPlayerDialog(playerid, DIALOG_HEXCOLOUR, DIALOG_STYLE_INPUT, "USF - Hex Colour", "Enter hexadecimal colour below :", "Submit", "Back");
					}
				}
				if(listitem != 5)
				{
					new msg[128];
					format(msg, sizeof(msg), "Are you sure you want to make a gang? \
					\nGang Name : %s \
					\nGang Tag : [%s] \
					\nGang Colour : {%s}%s", TempGangName[playerid], TempGangTag[playerid], TempGangColour[playerid], TempGangColour[playerid]);
					ShowPlayerDialog(playerid, DIALOG_CREATEGANG_CONFIRM, DIALOG_STYLE_MSGBOX, "USF - Create Gang", msg, "Sure", "Cancel");
				}
			}
		}
		case DIALOG_HEXCOLOUR:
		{
			if(response)
			{
				if(strlen(inputtext) != 6)
					ShowPlayerDialog(playerid, DIALOG_HEXCOLOUR, DIALOG_STYLE_INPUT, "USF - Hex Colour", "{FF0000}Hex colour must be 6 character!\n{FFFFFF}Enter hexadecimal colour below :", "Submit", "Back");
				else
				{
					if(sscanf(inputtext, "h", TempGangColour[playerid]))
						ShowPlayerDialog(playerid, DIALOG_HEXCOLOUR, DIALOG_STYLE_INPUT, "USF - Hex Colour", "{FF0000}Invalid HEX colour!\n{FFFFFF}Enter hexadecimal colour below :", "Submit", "Back");
					else
					{
						new msg[128];
						format(msg, sizeof(msg), "Are you sure you want to make a gang? \
						\nGang Name : %s \
						\nGang Tag : [%s] \
						\nGang Colour : {%s}%s", TempGangName[playerid], TempGangTag[playerid], TempGangColour[playerid], TempGangColour[playerid]);
						ShowPlayerDialog(playerid, DIALOG_CREATEGANG_CONFIRM, DIALOG_STYLE_MSGBOX, "USF - Create Gang", msg, "Sure", "Cancel");
					}
				}
			}
			else
			{
				ShowPlayerDialog(playerid, DIALOG_GANGCOLOUR, DIALOG_STYLE_LIST, "USF - Gang Colour",
				"{00FFFF}Aqua \n{000000}Black \n{0000FF}Blue \n{A52A2A}Brown \n{FF0000}Red \n{FFFFFF}Use HEX Colour", "Choose", "Cancel");
			}
		}
		case DIALOG_CREATEGANG_CONFIRM:
		{
			if(response)
			{
				new bool:found = false;
				foreach(new i : Gangs)
				{
					if(!strcmp(Gang[i][GangName], TempGangName[playerid], true))
					{
						found = true;
						SendClientMessage(playerid, -1, "{FF0000}Gang name already used!");
						break;
					}
					if(!strcmp(Gang[i][GangTag], TempGangTag[playerid], true))
					{
						found = true;
						SendClientMessage(playerid, -1, "{FF0000}Gang tag already used!");
						break;
					}
				}
				if(!found)
				{
					new query[256];
					mysql_format(connection, query, sizeof(query), "INSERT INTO `gang` (`name`, `color`, `tag`) VALUES('%e', '%e', '%e')", TempGangName[playerid], TempGangColour[playerid], TempGangTag[playerid]);
					mysql_query(connection, query, true);
					new i = Iter_Free(Gangs);
					strcpy(Gang[i][GangColor], TempGangColour[playerid]);
					Gang[i][GangID] = cache_insert_id();
					Gang[i][GangName] = TempGangName[playerid];
					Gang[i][GangScore] = 0;
					Gang[i][GangTag] = TempGangTag[playerid];
					Gang[i][CurrentZone] = -1;
					Player[playerid][PlayerGang] = i;
					Player[playerid][PlayerStatus] = GANG_LEADER;
					Iter_Add(Gangs, i);
					format(query, sizeof(query), "{%s}[%s]%s {FFFFFF}gang has been created!", TempGangColour[playerid], TempGangTag[playerid], TempGangName[playerid]);
					SendClientMessageToAll(-1, query);
					SaveStats(playerid);
				}
			}
		}
		case DIALOG_GCP:
		{
			if(response)
			{
				switch(listitem)
				{
					case 3:
						cmd_gangmembers(playerid, "");
					case 4:
						cmd_territory(playerid, "");
				}
			}
		}
	}
	return 1;
}

public OnPlayerEnterArea(playerid, areaid)
{
	foreach(new i : GangZones)
	{
		if(areaid == GangZone[i][ZoneArea])
		{
			PlayerTextDrawSetString(playerid, Player[playerid][TDZone][0], GangZone[i][ZoneName]);
			new msg[128];
			if(GangZone[i][ZoneOwner] == -1)
				format(msg, sizeof(msg), "Owned by : ~r~Unowned");
			else
				format(msg, sizeof(msg), "Owned by : ~r~%s", Gang[GangZone[i][ZoneOwner]][GangName]);
			PlayerTextDrawSetString(playerid, Player[playerid][TDZone][1], msg);
			PlayerTextDrawShow(playerid, Player[playerid][TDZone][0]);
			PlayerTextDrawShow(playerid, Player[playerid][TDZone][1]);
			return 1;
		}
	}
	return 1;
}

public OnPlayerLeaveArea(playerid, areaid)
{
	PlayerTextDrawHide(playerid, Player[playerid][TDZone][0]);
	PlayerTextDrawHide(playerid, Player[playerid][TDZone][1]);
	if(Player[playerid][PlayerGang] != -1)
	{
		new zone = Gang[Player[playerid][PlayerGang]][CurrentZone], total = -1;
		if(zone != -1)
		{
			total = 0;
			foreach(new p : Player)
			{
				if(Player[p][PlayerGang] == Player[playerid][PlayerGang])
				{
					if(Area_GetPlayerAreas(p, 0) == GangZone[zone][ZoneArea])
						total++;
				}
			}
		}
		if(total == 0)
		{
			new msg[128];
			format(msg, sizeof(msg), "{FF0000}** %s gang failed to capture %s zone!", Gang[Player[playerid][PlayerGang]][GangName], GangZone[zone][ZoneName]);
			SendClientMessageToAll(-1, msg);
			format(msg, sizeof(msg), "{FF0000}** %s zone will be locked for %d minutes!", GangZone[zone][ZoneName], LOCKED_MINUTES);
			Cantuse[playerid] = 0;
			SendClientMessageToAll(-1, msg);
			Gang[Player[playerid][PlayerGang]][CurrentZone] = -1;
			GangZone[zone][ZoneLocked] = GetTickCount();
			GangZone[zone][ZoneStatus] = false;
			GangZoneStopFlashForAll(GangZone[zone][ZoneHolder]);
		}
	}
	return 1;
}

forward AttackZone(gangid, zoneid);
public AttackZone(gangid, zoneid)
{
	if(Gang[gangid][CurrentZone] == zoneid && Iter_Contains(Gangs, gangid))
	{
		Gang[gangid][GangTimer]--;
		if(Gang[gangid][GangTimer] > 0)
		{
			new minutes = Gang[gangid][GangTimer] / 60, seconds = Gang[gangid][GangTimer] % 60, msg[10];
			format(msg, sizeof(msg), "%02d:%02d", minutes, seconds);
			foreach(new p : Player)
			{
				if(Player[p][PlayerGang] == gangid)
					PlayerTextDrawSetString(p, Player[p][CaptureTD][1], msg);
			}
		}
		else
		{
			KillTimer(GangZone[zoneid][ZoneTimer]);
			new msg[128];
			format(msg, sizeof(msg), "Owned by : ~r~%s", Gang[gangid][GangName]);
			foreach(new p : Player)
			{
				if(Player[p][PlayerGang] == gangid)
				{
					PlayerTextDrawHide(p, Player[p][CaptureTD][0]);
					PlayerTextDrawHide(p, Player[p][CaptureTD][1]);
				}
				if(Area_GetPlayerAreas(p, 0) == GangZone[zoneid][ZoneArea])
					PlayerTextDrawSetString(p, Player[p][TDZone][1], msg);

			}
			GangZoneStopFlashForAll(GangZone[zoneid][ZoneHolder]);
			new colour[9];
			format(colour, 9, "%s50", Gang[gangid][GangColor]);
			GangZoneShowForAll(GangZone[zoneid][ZoneHolder], HexToInt(colour));
			GangZone[zoneid][ZoneOwner] = gangid;
			format(msg, sizeof(msg), "{FF0000}** %s gang succesfully captured %s zone!", Gang[gangid][GangName], GangZone[zoneid][ZoneName]);
			SendClientMessageToAll(-1, msg);
			format(msg, sizeof(msg), "{FF0000}** %s zone will be locked for %d minutes!", GangZone[zoneid][ZoneName], LOCKED_MINUTES);
			SendClientMessageToAll(-1, msg);
			Gang[gangid][CurrentZone] = -1;
			GangZone[zoneid][ZoneLocked] = GetTickCount();
			GangZone[zoneid][ZoneStatus] = false;
			Gang[gangid][GangScore]+=5;
		}
	}
	else
	{
		foreach(new p : Player)
		{
			if(Player[p][PlayerGang] == gangid)
			{
				PlayerTextDrawHide(p, Player[p][CaptureTD][0]);
				PlayerTextDrawHide(p, Player[p][CaptureTD][1]);
			}
		}
		KillTimer(GangZone[zoneid][ZoneTimer]);
		GangZoneStopFlashForAll(GangZone[zoneid][ZoneHolder]);
	}
	return 1;
}


forward AutoSave();
public AutoSave()
{
	foreach(new i : Player)
		SaveStats(i);
	foreach(new i : Gangs)
		SaveGang(i);
	foreach(new i : GangZones)
		SaveZone(i);
	return 1;
}
thnx in advance
Reply


Messages In This Thread
Easy help .. thnx in advance - by Stop - 12.11.2016, 05:55
Re: Easy help .. thnx in advance - by SyS - 12.11.2016, 06:38
Re: Easy help .. thnx in advance - by Stop - 12.11.2016, 07:00
Re: Easy help .. thnx in advance - by SyS - 12.11.2016, 10:50
Re: Easy help .. thnx in advance - by Sew_Sumi - 12.11.2016, 12:53
Re: Easy help .. thnx in advance - by Marshall32 - 12.11.2016, 12:58

Forum Jump:


Users browsing this thread: 1 Guest(s)