[Tutorial] Gang Zone Wars
#1

This tutorial shows how you can create gang zones and zone wars.

Teams

I'm assuming that you have your teams set up.
If you don't, you can easily set them by following this tutorial: https://sampwiki.blast.hk/wiki/PAWN_tutorial

I will be using 3 example teams in this tutorial

pawn Code:
#define TEAM_GROVE 1
#define TEAM_BALLAS 2
#define TEAM_VAGOS 3
Creating The Zones

pawn Code:
enum eZone
{
    Float:zMinX,
    Float:zMinY,
    Float:zMaxX,
    Float:zMaxY,
    zTeam
}
new ZoneInfo[][eZone] = {
    {2337.9004,-1808.8383,2590.2043,-1610.3673,TEAM_GROVE},
    {2084.7,-1808.8383,2337.9004,-1610.3673,TEAM_BALLAS},
    {2590.2043,-1808.8383,2842.3,-1610.3673,TEAM_VAGOS}
};
new ZoneID[sizeof(ZoneInfo)];
I created 3 zones, 1 for each team.

Let's look at the first one

pawn Code:
{2337.9004,-1808.8383,2590.2043,-1610.3673,TEAM_GROVE},
If you look at the enum, you see what each number means.

2337.9004 - zMinX
-1808.8383 - zMinY
2590.2043 - zMaxX
-1610.3673 - zMaxY
TEAM_GROVE - zTeam

The coordinates zMinX, zMinY, zMaxX, zMaxY are used in GangZoneCreate function to create the zones.

You should create the gang zones in OnGameModeInit or in OnFilterScriptInit if you are making a filterscript.

pawn Code:
for(new i=0; i < sizeof(ZoneInfo); i++)
{
    ZoneID[i] = GangZoneCreate(ZoneInfo[i][zMinX], ZoneInfo[i][zMinY], ZoneInfo[i][zMaxX], ZoneInfo[i][zMaxY]);
}
You also have to show the gang zones to the player. You can do this in OnPlayerSpawn.

pawn Code:
for(new i=0; i < sizeof(ZoneInfo); i++)
{
    GangZoneShowForPlayer(playerid, ZoneID[i], GetTeamZoneColor(ZoneInfo[i][zTeam]));
}
You also need the GetTeamZoneColor function

pawn Code:
stock GetTeamZoneColor(teamid)
{
    switch(teamid)
    {
        case TEAM_GROVE: return 0x00FF0088;
        case TEAM_BALLAS: return 0xFF00FF88;
        case TEAM_VAGOS: return 0xFFFF0088;
    }
    return -1;
}
Note that I added 88 to the end of the colors. This shows transparency. If you want to make the zones more transparent, use smaller values like 55. If you want to make the zones less transparent, use bigger values like AA.

Now the zones should be working.

Adding New Zones

If you want to add more zones, you need to get the coordinates.
You can do this with /save [comment] command in any SA-MP server or in Debug Mode.
Just go in game and find the location for the gang zone.



You have to use /save in 2 places: in point 1 and point 2 (see the picture):
1. Go to point 1 and do "/save example min"
2. Go to point 2 and do "/save example max"

Then you should have the lines in My Documents\GTA San Andreas User Files\SAMP\savedpositions.txt

Code:
AddPlayerClass(107,1429.3770,-1732.4554,13.3828,355.2560,0,0,0,0,0,0); // example min
AddPlayerClass(107,1529.1932,-1592.1989,13.3828,90.5102,0,0,0,0,0,0); // example max
You only need these coordinates

Code:
1429.3770,-1732.4554
1529.1932,-1592.1989
So if you want to add a zone for Grove, you have all the things you need to create a new gang zone

1429.3770 - zMinX
-1732.4554 - zMinY
1529.1932 - zMaxX
-1592.1989 - zMaxY
TEAM_GROVE - zTeam

Then add this line to ZoneInfo

pawn Code:
{1429.3770,-1732.4554,1529.1932,-1592.1989,TEAM_GROVE}
So the ZoneInfo should look like this

pawn Code:
new ZoneInfo[][eZone] = {
    {2337.9004,-1808.8383,2590.2043,-1610.3673,TEAM_GROVE},
    {2084.7,-1808.8383,2337.9004,-1610.3673,TEAM_BALLAS},
    {2590.2043,-1808.8383,2842.3,-1610.3673,TEAM_VAGOS},
    {1429.3770,-1732.4554,1529.1932,-1592.1989,TEAM_GROVE}
};
Zone Attack

Now that you have your zones placed, let's make them attackable.

First we should make some additions to our code.

Add these new global variables

pawn Code:
new ZoneAttacker[sizeof(ZoneInfo)] = {-1, ...};
new ZoneAttackTime[sizeof(ZoneInfo)];
If a war is going on, the zone should be flashing. Make these changes to OnPlayerSpawn

pawn Code:
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]));
}
There are many ways to start a gang zone war, but I will show you 2 of them.

Zone Attack #1

To start a war, you need to have some team members on enemy zone.

We will need some defines and stock functions

pawn Code:
#define TAKEOVER_TIME 120 // how many seconds needed to take over the zone
#define MIN_MEMBERS_TO_START_WAR 3 // how many team members needed in a zone to start a war
We define them so they can be easily changed later.

pawn Code:
new Teams[] = {
    TEAM_GROVE,
    TEAM_BALLAS,
    TEAM_VAGOS
};
We need to make an array of all our teams to later use it in a loop. Add all your teams here.

pawn Code:
stock IsPlayerInZone(playerid, zoneid)
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    return (x > ZoneInfo[zoneid][zMinX] && x < ZoneInfo[zoneid][zMaxX] && y > ZoneInfo[zoneid][zMinY] && y < ZoneInfo[zoneid][zMaxY]);
}

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;
}
Set up a timer in OnGameModeInit or in OnFilterScriptInit if you are making a filterscript.

pawn Code:
SetTimer("ZoneTimer", 1000, true);
Add a public function for the timer (don't forget to forward it)

pawn Code:
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;
                }
            }
            else // attackers failed to take over the zone
            {
                GangZoneStopFlashForAll(ZoneID[i]);
                ZoneAttacker[i] = -1;
            }
        }
        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]));
                }
            }
        }
    }
}
And you are done. Now, if there are enough enemies in the zone, a war will start and last until enemies have left the zone or have been there enough time to capture it.

Zone Attack #2

To start a war, you need to kill some enemies on enemy zone.

We will need some defines

pawn Code:
#define TAKEOVER_TIME 120 // how many seconds needed to take over the zone
#define MIN_DEATHS_TO_START_WAR 3 // how many team members must be killed in a zone to start a war
We define them so they can be easily changed later.

Set up a timer in OnGameModeInit or in OnFilterScriptInit if you are making a filterscript.

pawn Code:
SetTimer("ZoneTimer", 1000, true);
Add a public function for the timer (don't forget to forward it)

pawn Code:
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]) >= 1) // there must be at least 1 attacker left
            {
                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;
                }
            }
            else // attackers failed to take over the zone
            {
                GangZoneStopFlashForAll(ZoneID[i]);
                ZoneAttacker[i] = -1;
            }
        }
    }
}
Now we need to trigger the attack in OnPlayerDeath

pawn Code:
if(IsPlayerConnected(killerid) && GetPlayerTeam(playerid) != GetPlayerTeam(killerid)) // not a suicide or team kill
{
    new zoneid = GetPlayerZone(playerid);
    if(zoneid != -1 && ZoneInfo[zoneid][zTeam] == GetPlayerTeam(playerid)) // zone member has been killed in the zone
    {
        ZoneDeaths[zoneid]++;
        if(ZoneDeaths[zoneid] == MIN_DEATHS_TO_START_WAR)
        {
            ZoneDeaths[zoneid] = 0;
            ZoneAttacker[zoneid] = GetPlayerTeam(killerid);
            ZoneAttackTime[zoneid] = 0;
            GangZoneFlashForAll(ZoneID[zoneid], GetTeamZoneColor(ZoneAttacker[zoneid]));
        }
    }
}
We also need a global variable ZoneDeaths and GetPlayerZone function.

pawn Code:
new ZoneDeaths[sizeof(ZoneInfo)];
pawn Code:
stock GetPlayerZone(playerid)
{
    for(new i=0; i < sizeof(ZoneInfo); i++)
    {
        if(IsPlayerInZone(playerid, i))
        {
            return i;
        }
    }
    return -1;
}
And you are done. Now, if there has been enough kills in a zone, a war will start and last until enemies have left the zone or have been there enough time to capture it.

Notes

I'm using GetPlayerTeam to check player team. If you define your teams in some other way (gTeam[playerid] for example), just replace it with your define.

The End

This is the end of the tutorial. If you have any questions or recommendations, feel free to post them here
Reply


Messages In This Thread
Gang Zone Wars - by MadeMan - 13.08.2011, 13:38
Re: Gang Zone Wars - by Darnell - 13.08.2011, 13:48
Re: Gang Zone Wars - by emokidx - 13.08.2011, 15:36
AW: Gang Zone Wars - by samtey - 13.08.2011, 16:18
Re: Gang Zone Wars - by CoLLYY - 13.08.2011, 22:22
AW: Gang Zone Wars - by samtey - 14.08.2011, 17:37
Re: Gang Zone Wars - by Darnell - 14.08.2011, 18:04
Re: AW: Gang Zone Wars - by MadeMan - 14.08.2011, 20:45
Re: Gang Zone Wars - by CoLLYY - 16.08.2011, 10:21
Re: Gang Zone Wars - by SpiderWalk - 16.08.2011, 10:23
Re: Gang Zone Wars - by DeadAhead - 16.08.2011, 10:24
Re: Gang Zone Wars - by MaTrIx4057 - 16.08.2011, 11:04
Re: Gang Zone Wars - by RaZvY - 28.08.2011, 11:15
Re: Gang Zone Wars - by qUick1337 - 03.09.2011, 17:01
Re: Gang Zone Wars - by davve95 - 03.09.2011, 17:23
Re: Gang Zone Wars - by Davz*|*Criss - 03.09.2011, 22:02
Re: Gang Zone Wars - by MadeMan - 04.09.2011, 08:29
Re: Gang Zone Wars - by RaZvY - 08.09.2011, 22:22
Re: Gang Zone Wars - by Anzhelov - 09.09.2011, 08:55
Re: Gang Zone Wars - by eemalekorraks - 11.09.2011, 17:10
Respuesta: Gang Zone Wars - by ||ponpon|| - 11.09.2011, 18:18
Re: Gang Zone Wars - by R3dX - 12.11.2011, 08:42
Re: Gang Zone Wars - by MadeMan - 12.11.2011, 12:48
Re: Gang Zone Wars - by Naruto_Emilio - 18.11.2011, 15:14
Re: Gang Zone Wars - by Astralis - 18.11.2011, 16:15
Re: Gang Zone Wars - by DawioX - 24.01.2012, 12:33
Re: Gang Zone Wars - by dickyodie - 01.02.2012, 09:26
Re: Respuesta: Gang Zone Wars - by Dustly - 01.03.2012, 00:30
Re: Gang Zone Wars - by GNGification - 03.03.2012, 09:43
Re: Gang Zone Wars - by susuke97 - 16.08.2012, 11:38
Re: Gang Zone Wars - by Arxalan - 04.01.2015, 04:07
Re: Gang Zone Wars - by Cr3dO - 07.02.2015, 17:10
Re: Gang Zone Wars - by Tookapack - 26.02.2015, 01:19
Re: Gang Zone Wars - by Ugaustin - 24.06.2015, 10:12
Re: Gang Zone Wars - by Ugaustin - 24.06.2015, 20:11
Re: Gang Zone Wars - by Ugaustin - 25.06.2015, 17:27
Re: Gang Zone Wars - by TonyCan - 06.06.2016, 08:34
Re: Gang Zone Wars - by iamjems - 14.10.2016, 23:02
Re: Gang Zone Wars - by Oxygenated - 30.04.2017, 13:06

Forum Jump:


Users browsing this thread: 1 Guest(s)