Help with Gang zones
#1

hey guys i have done gag zones so when the there is enough players in the zone then the war will start, all zones show but the problem is when i go to the zone it does not start the attack, no flashing turf and does not take over, all it does is stay white, i also added sendclientmessage to see if it shows when in the zone but that does not show aswell.
the person who finds a fix for this i will rep.

here is all my code:

pawn Код:
#include <a_samp>
#include <zcmd>
#include <sscanf2>
#include <foreach>
#include <streamer>

#define NUN_TEAM 0
#define TEAM_GROVE 1
#define TEAM_BALLAS 2
#define TEAM_NULL 3

#define TAKEOVER_TIME 130
#define MIN_MEMBERS_TO_START_WAR 3

#define     NUN_TEAM_COLOR      0xFFFFFFFF
#define     GROVE_COLOR         0x008000FF
#define     BALLAS_COLOR        0x800080FF
#define     C_GROVE             "{008000}"
#define     C_BALLAS            "{800080}"

new PrevColor[MAX_PLAYERS];

new gTeam[MAX_PLAYERS];

enum eZone
{
    Float:Zone_Min_X,
    Float:Zone_Min_Y,
    Float:Zone_Max_X,
    Float:Zone_Max_Y,
    zTeam,
}
new ZoneInfo[][eZone] =
{
    {2337.9004,-1808.8383,2590.2043,-1610.3673, TEAM_NULL},
    {2084.7,-1808.8383,2337.9004,-1610.3673, TEAM_NULL},
    {2590.2043,-1808.8383,2842.3,-1610.3673, TEAM_NULL}
};
new ZoneID[sizeof(ZoneInfo)];

new ZoneAttacker[sizeof(ZoneInfo)] = {-1, ...};
new ZoneAttackTime[sizeof(ZoneInfo)];

new Teams[] = {
    TEAM_GROVE,
    TEAM_BALLAS,
    TEAM_NULL
};

public OnFilterScriptInit()
{
    for(new i=0; i < sizeof(ZoneInfo); i++)
    {
        ZoneID[i] = GangZoneCreate(ZoneInfo[i][Zone_Min_X], ZoneInfo[i][Zone_Min_Y], ZoneInfo[i][Zone_Max_X], ZoneInfo[i][Zone_Max_Y]);
    }  
    SetTimer("ZoneTimer", 1000, true);
    return 1;
}

public OnPlayerConnect(playerid)
{
    SetPlayerTeam(playerid, 0);
    return 1;
}

public OnPlayerSpawn(playerid)
{
    if(gTeam[playerid] == TEAM_GROVE)
    {
        for(new i=0; i < sizeof(ZoneInfo); i++)
        {
            GangZoneShowForPlayer(playerid, ZoneID[i], GetTeamZoneColor(ZoneInfo[i][zTeam]));
            if(ZoneAttacker[i] != -1) GangZoneFlashForPlayer(playerid, ZoneID[i], GetTeamZoneColor(ZoneAttacker[i]));
        }
    }
    if(gTeam[playerid] == TEAM_BALLAS)
    {
        for(new i=0; i < sizeof(ZoneInfo); i++)
        {
            GangZoneShowForPlayer(playerid, ZoneID[i], GetTeamZoneColor(ZoneInfo[i][zTeam]));
            if(ZoneAttacker[i] != -1) GangZoneFlashForPlayer(playerid, ZoneID[i], GetTeamZoneColor(ZoneAttacker[i]));
        }
    }
    return 1;
}

forward ZoneTimer();
public ZoneTimer()
{
    for(new i=0; i < sizeof(ZoneInfo); i++) // loop all zones
    {
        if(ZoneAttacker[i] != -1) // zone is being attacked
        {
            if(GetPlayersInZone(i, ZoneAttacker[i]) >= MIN_MEMBERS_TO_START_WAR) // team has enough members in the zone
            {
                ZoneAttackTime[i]++;
                if(ZoneAttackTime[i] == TAKEOVER_TIME) // zone has been under attack for enough time and attackers take over the zone
                {
                    GangZoneStopFlashForAll(ZoneID[i]);
                    ZoneInfo[i][zTeam] = ZoneAttacker[i];
                    GangZoneShowForAll(ZoneID[i], GetTeamZoneColor(ZoneInfo[i][zTeam])); // update the zone color for new team
                    ZoneAttacker[i] = -1;
                    SendClientMessageToAll(-1, "Turf Taken");
                }
            }
            else // attackers failed to take over the zone
            {
                GangZoneStopFlashForAll(ZoneID[i]);
                ZoneAttacker[i] = -1;
                SendClientMessageToAll(-1, "Turf Fail");
            }
        }
        else // check if somebody is attacking
        {
            for(new t=0; t < sizeof(Teams); t++) // loop all teams
            {
                if(Teams[t] != ZoneInfo[i][zTeam] && GetPlayersInZone(i, Teams[t]) >= MIN_MEMBERS_TO_START_WAR) // if there are enough enemies in the zone
                {
                    ZoneAttacker[i] = Teams[t];
                    ZoneAttackTime[i] = 0;
                    GangZoneFlashForAll(ZoneID[i], GetTeamZoneColor(ZoneAttacker[i]));
                    SendClientMessageToAll(-1, "Turf Attacking");
                }
            }
        }
    }
}

CMD:attack(playerid, params[])
{
    for(new i=0; i < sizeof(ZoneInfo); i++) // loop all zones
    {
        if(ZoneAttacker[i] != -1) // zone is being attacked
        {
            if(GetPlayersInZone(i, ZoneAttacker[i]) >= MIN_MEMBERS_TO_START_WAR) // team has enough members in the zone
            {
                ZoneAttackTime[i]++;
                if(ZoneAttackTime[i] == TAKEOVER_TIME) // zone has been under attack for enough time and attackers take over the zone
                {
                    GangZoneStopFlashForAll(ZoneID[i]);
                    ZoneInfo[i][zTeam] = ZoneAttacker[i];
                    GangZoneShowForAll(ZoneID[i], GetTeamZoneColor(ZoneInfo[i][zTeam])); // update the zone color for new team
                    ZoneAttacker[i] = -1;
                    SendClientMessageToAll(-1, "Turf Taken");
                }
            }
            else // attackers failed to take over the zone
            {
                GangZoneStopFlashForAll(ZoneID[i]);
                ZoneAttacker[i] = -1;
                SendClientMessageToAll(-1, "Turf Fail");
            }
        }
        else // check if somebody is attacking
        {
            for(new t=0; t < sizeof(Teams); t++) // loop all teams
            {
                if(Teams[t] != ZoneInfo[i][zTeam] && GetPlayersInZone(i, Teams[t]) >= MIN_MEMBERS_TO_START_WAR) // if there are enough enemies in the zone
                {
                    ZoneAttacker[i] = Teams[t];
                    ZoneAttackTime[i] = 0;
                    GangZoneFlashForAll(ZoneID[i], GetTeamZoneColor(ZoneAttacker[i]));
                    SendClientMessageToAll(-1, "Turf Attacking");
                }
            }
        }
    }
    return 1;
}

/*CMD:joingrove(playerid, params[])
{
    if(gTeam[playerid] == TEAM_BALLAS) return SendClientMessage(playerid, -1, "You are already in a gang");
    SendClientMessage(playerid, -1, "You have joined Grove Street Gang");
    GetPlayerColor(PrevColor[playerid]);
    SetPlayerColor(playerid, GROVE_COLOR);
    gTeam[playerid] = TEAM_GROVE;
    SetPlayerTeam(playerid, 1);
    for(new i=0; i < sizeof(ZoneInfo); i++)
    {
        GangZoneShowForPlayer(playerid, ZoneID[i], GetTeamZoneColor(ZoneInfo[i][zTeam]));
        if(ZoneAttacker[i] != -1) GangZoneFlashForPlayer(playerid, ZoneID[i], GetTeamZoneColor(ZoneAttacker[i]));
    }
    return 1;
}

CMD:joinballas(playerid, params[])
{
    if(gTeam[playerid] == TEAM_GROVE) return SendClientMessage(playerid, -1, "You are already in a gang");
    SendClientMessage(playerid, -1, "You have joined Ballas Gang");
    GetPlayerColor(PrevColor[playerid]);
    SetPlayerColor(playerid, BALLAS_COLOR);
    gTeam[playerid] = TEAM_BALLAS;
    SetPlayerTeam(playerid, 2);
    for(new i=0; i < sizeof(ZoneInfo); i++)
    {
        GangZoneShowForPlayer(playerid, ZoneID[i], GetTeamZoneColor(ZoneInfo[i][zTeam]));
        if(ZoneAttacker[i] != -1) GangZoneFlashForPlayer(playerid, ZoneID[i], GetTeamZoneColor(ZoneAttacker[i]));
    }
    return 1;
}*/


CMD:join(playerid, params[])
{
    new
    command[20];
   
    if(sscanf(params,"s[20]", command)) return SendClientMessage(playerid, -1, "Usage: /joingang <grove/ballas>");
    if(!strcmp(command, "grove"))
    {
        if(gTeam[playerid] == TEAM_BALLAS) return SendClientMessage(playerid, -1, "You are already in a gang");
        SendClientMessage(playerid, -1, "You have joined Grove Street Gang");
        GetPlayerColor(PrevColor[playerid]);
        SetPlayerColor(playerid, GROVE_COLOR);
        gTeam[playerid] = TEAM_GROVE;
        SetPlayerTeam(playerid, 1);
        for(new i=0; i < sizeof(ZoneInfo); i++)
        {
            GangZoneShowForPlayer(playerid, ZoneID[i], GetTeamZoneColor(ZoneInfo[i][zTeam]));
            if(ZoneAttacker[i] != -1) GangZoneFlashForPlayer(playerid, ZoneID[i], GetTeamZoneColor(ZoneAttacker[i]));
        }
        return 1;
    }
    if(!strcmp(command, "ballas"))
    {
        if(gTeam[playerid] == TEAM_GROVE) return SendClientMessage(playerid, -1, "You are already in a gang");
        SendClientMessage(playerid, -1, "You have joined Ballas Gang");
        GetPlayerColor(PrevColor[playerid]);
        SetPlayerColor(playerid, BALLAS_COLOR);
        gTeam[playerid] = TEAM_BALLAS;
        SetPlayerTeam(playerid, 2);
        for(new i=0; i < sizeof(ZoneInfo); i++)
        {
            GangZoneShowForPlayer(playerid, ZoneID[i], GetTeamZoneColor(ZoneInfo[i][zTeam]));
            if(ZoneAttacker[i] != -1) GangZoneFlashForPlayer(playerid, ZoneID[i], GetTeamZoneColor(ZoneAttacker[i]));
        }
        return 1;
    }
    return 1;
}

CMD:quitgang(playerid, params[])
{
    if(gTeam[playerid] == TEAM_GROVE)
    {
        SetPlayerColor(playerid, PrevColor[playerid]);
        SendClientMessage(playerid, -1, "You have quit the gang!");
        gTeam[playerid] = NUN_TEAM;
        SetPlayerTeam(playerid, 0);
        for(new i=0; i < sizeof(ZoneInfo); i++)
        {
            GangZoneHideForPlayer(playerid, ZoneID[i]);
        }
    }
    if(gTeam[playerid] == TEAM_BALLAS)
    {
        SetPlayerColor(playerid, PrevColor[playerid]);
        SendClientMessage(playerid, -1, "You have quit the gang!");
        gTeam[playerid] = NUN_TEAM;
        SetPlayerTeam(playerid, 0);
        for(new i=0; i < sizeof(ZoneInfo); i++)
        {
            GangZoneHideForPlayer(playerid, ZoneID[i]);
        }
    }
    return 1;
}

CMD:acar(playerid, params[])
{
    if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, -1,"You already have a vehicle!");
    new Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, X, Y, Z);
    PutPlayerInVehicle(playerid, CreateVehicle(415, X, Y, Z, 0.0,0, 1, 60), 0);
    return 1;
}

GetTeamZoneColor(teamid)
{
    switch(teamid)
    {
        case TEAM_GROVE: return 0x00FF0088;
        case TEAM_BALLAS: return 0xFF00FF88;
        case TEAM_NULL: return 0xFFFFFF88;
    }
    return -1;
}

stock IsPlayerInZone(playerid, zoneid)
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    return (x > ZoneInfo[zoneid][Zone_Min_X] && x < ZoneInfo[zoneid][Zone_Min_Y] && y > ZoneInfo[zoneid][Zone_Max_X] && y < ZoneInfo[zoneid][Zone_Max_Y]);
}

stock GetPlayersInZone(zoneid, teamid)
{
    new count;
    for(new i=0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) && GetPlayerTeam(i) == teamid && IsPlayerInZone(i, zoneid))
        {
            count++;
        }
    }
    return count;
}

public OnPlayerText(playerid, text[])
{
    if(gTeam[playerid] == TEAM_GROVE && text[0] == '#')
    {
         new msg[128];
         format(msg, sizeof(msg), ""C_GROVE"[GANG CHAT] %s: %s", GetName(playerid), text[1]);
         SendMessageToGang(msg);
    }
    if(gTeam[playerid] == TEAM_BALLAS && text[0] == '#')
    {
         new msg[128];
         format(msg, sizeof(msg), ""C_BALLAS"[GANG CHAT] %s: %s", GetName(playerid), text[1]);
         SendMessageToGang(msg);
    }
    return 1;
}

SendMessageToGang(text[])
{
    foreach(Player, i)
    {
        if(gTeam[i] == TEAM_GROVE)
        {
            SendClientMessage(i, -1, text);
        }
        else if(gTeam[i] == TEAM_BALLAS)
        {
            SendClientMessage(i, -1, text);
        }      
    }
}

GetName(playerid)
{
      new name[MAX_PLAYER_NAME];
      GetPlayerName(playerid, name, MAX_PLAYER_NAME);
      return name;
}
Reply
#2

I got same problem..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)