
#define FILTERSCRIPT
#include <a_samp>

#define MAX_ZONES  5 // Максимальное число безопасных зон.
#define MAX_WARNS  2 // Максимальное число предупреждений.
#define WARN_COLOR 0xf6102bFF // Цвет предупреждения.
#define ZONE_COLOR 0xFFFF0096 // Цвет безопасных зон.

forward ShowText();
enum kords
{
    Float:minX,
    Float:minY,
    Float:maxX,
    Float:maxY
};

new Float:ZoneCords[MAX_ZONES][kords] =
{
    // minX, minY, maxX, maxY
	{-2696.9824, -60.6852, -2613.1055, 29.8879}, // Сан Фиерро.
	{-2001.5415, 77.9670, -1950.7507, 218.3597}, // Сан Фиерро.
	{2077.4653, 1197.4258, 2182.3826, 1369.1112}, // Лас Вентурас.
	{1810.8127, 1456.8585, 2037.8066, 1709.1813}, // Лас Вентурас.
	{2192.7255, 2032.4004, 2312.0420, 2067.6936} // Лас Вентурас.
};

new Zone[MAX_ZONES], Warns[MAX_PLAYERS], bool:IsPlayerInZone[MAX_PLAYERS];
new Text:Text, Timer;

public OnFilterScriptInit()
{
	print("\n--------------------------------------------");
	print("[FS]jSZS - Save Zones System by Stanly loaded.");
	print("--------------------------------------------\n");
	Text = TextDrawCreate(456.0, 381.0, "Save_Zone");
	TextDrawFont(Text, 3);
	TextDrawLetterSize(Text, 0.569999, 2.399999);
	TextDrawSetOutline(Text, 0);
	TextDrawBackgroundColor(Text, 1717986918);
	TextDrawColor(Text, -65386);
	TextDrawSetOutline(Text, 0);
	TextDrawSetProportional(Text, 1);
	TextDrawSetShadow(Text, 1);
	for(new z = 0; z < MAX_ZONES; z++)
	{
		Zone[z] = GangZoneCreate(ZoneCords[z][minX], ZoneCords[z][minY], ZoneCords[z][maxX], ZoneCords[z][maxY]);
		GangZoneShowForAll(Zone[z], ZONE_COLOR);
	}
	for(new p = 0; p < MAX_PLAYERS; p++) IsPlayerInZone[p] = false;
	Timer = SetTimer("ShowText", 1000, true);
	return 1;
}

public OnFilterScriptExit()
{
	print("\n----------------------------------------------");
	print("DarkCity.");
	print("----------------------------------------------\n");
	for(new z = 0; z < MAX_ZONES; z++) GangZoneDestroy(Zone[z]);
	for(new p = 0; p < MAX_PLAYERS; p++) IsPlayerInZone[p] = false;
	KillTimer(Timer); TextDrawDestroy(Text);
	return 1;
}

public OnPlayerConnect(playerid)
{
    Warns[playerid] = 0; IsPlayerInZone[playerid] = false;
    for(new z = 0; z < MAX_ZONES; z++) GangZoneShowForPlayer(playerid, Zone[z], ZONE_COLOR);
    TextDrawHideForPlayer(playerid, Text);
	return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    for(new z = 0; z < MAX_ZONES; z++) GangZoneHideForPlayer(playerid, Zone[z]);
    TextDrawHideForPlayer(playerid, Text);
	return 1;
}

public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid)
{
    if(issuerid != INVALID_PLAYER_ID)
    {
        if(IsPlayerInZone[playerid] == true)
        {
			new Float:phealt; GetPlayerHealth(playerid, phealt);
			new Float:ihhealt; GetPlayerHealth(issuerid, ihhealt);
      		SetPlayerHealth(playerid, phealt + amount); SetPlayerHealth(issuerid, ihhealt - amount);
       		Warns[issuerid] += 1;
			new msg[105];
			format(msg, sizeof(msg), "Предупреждение. Если ты не уймешся полетиш с DarkCity. Получили %d предупреждение(Max %d).", Warns[issuerid], MAX_WARNS);
	  		SendClientMessage(issuerid, WARN_COLOR, msg);
   			if(Warns[issuerid] >= MAX_WARNS)
	   		{
         		SendClientMessage(issuerid, WARN_COLOR, "DarkCity ебланы не нужны гуляй Вася.");
				Kick(issuerid);
			}
		}
	}
	return 1;
}

public ShowText()
{
    for(new p = 0; p < MAX_PLAYERS; p++)
    {
        if(!IsPlayerConnected(p)) continue;
        for(new z = 0; z < MAX_ZONES; z++)
        {
            if(!PlayerInZone(p, ZoneCords[z][minX], ZoneCords[z][minY], ZoneCords[z][maxX], ZoneCords[z][maxY]))
			{
			    if(IsPlayerInZone[p] == true)
				{
				    IsPlayerInZone[p] = false;
					TextDrawHideForPlayer(p, Text);
				}
				continue;
			}
			else if(IsPlayerInZone[p] == false)
			{
			    IsPlayerInZone[p] = true;
		 		TextDrawShowForPlayer(p, Text);
			}
			return 1;
		}
	}
	return 1;
}

stock PlayerInZone(playerid, Float:min_X, Float:min_Y, Float:max_X, Float:max_Y)
{
    new Float:pos[3]; GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
    if((pos[0] <= max_X && pos[0] >= min_X) && (pos[1] <= max_Y && pos[1] >= min_Y)) return 1;
    return 0;
}
