SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 13/08/2011, 02:38 PM   #1
MadeMan
High-roller
 
MadeMan's Avatar
 
Join Date: Jun 2007
Posts: 3,489
Reputation: 256
Default Gang Zone Wars

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: http://wiki.sa-mp.com/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
MadeMan is offline   Reply With Quote
Old 13/08/2011, 02:48 PM   #2
Darnell
Gangsta
 
Darnell's Avatar
 
Join Date: Jul 2010
Posts: 852
Reputation: 34
Default Re: Gang Zone Wars

ZIS IS GOODEN.
Darnell is offline   Reply With Quote
Old 13/08/2011, 04:36 PM   #3
emokidx
Gangsta
 
emokidx's Avatar
 
Join Date: Jul 2011
Posts: 553
Reputation: 63
Default Re: Gang Zone Wars

wow,, i got bored by reading half of it.. 0.0
well,, it seemed a great tut..
emokidx is offline   Reply With Quote
Old 13/08/2011, 05:18 PM   #4
samtey
Gangsta
 
samtey's Avatar
 
Join Date: Jul 2011
Posts: 529
Reputation: 12
Default AW: Gang Zone Wars

Credits: Scripting by MadeMan, idea by samtey ^^

NICE! EXACTLY WHAT I NEEDED!
__________________
Dear USER! If I helped you in one of your posts, then please give me reputation! I also will give you if you help me!

samtey is offline   Reply With Quote
Old 13/08/2011, 11:22 PM   #5
CoLLYY
Big Clucker
 
Join Date: Aug 2010
Posts: 119
Reputation: 9
Default Re: Gang Zone Wars

FIXED!!

Great tutorial ! Good JOB !
CoLLYY is offline   Reply With Quote
Old 14/08/2011, 06:37 PM   #6
samtey
Gangsta
 
samtey's Avatar
 
Join Date: Jul 2011
Posts: 529
Reputation: 12
Default AW: Gang Zone Wars

Code:
D:\Program Files\Rockstar Games\GTA San Andreas\eigener SAMP\gamemodes\deathmatch.pwn(554) : error 012: invalid function call, not a valid address
D:\Program Files\Rockstar Games\GTA San Andreas\eigener SAMP\gamemodes\deathmatch.pwn(554) : warning 215: expression has no effect
D:\Program Files\Rockstar Games\GTA San Andreas\eigener SAMP\gamemodes\deathmatch.pwn(554) : error 001: expected token: ";", but found ")"
D:\Program Files\Rockstar Games\GTA San Andreas\eigener SAMP\gamemodes\deathmatch.pwn(554) : error 029: invalid expression, assumed zero
D:\Program Files\Rockstar Games\GTA San Andreas\eigener SAMP\gamemodes\deathmatch.pwn(554) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright (c) 1997-2006, ITB CompuPhase


4 Errors.
Line:
PHP Code:
if(IsPlayerConnected(killerid) && gTeam[playerid] != gTeam(killerid)) // not a suicide or team kill 
__________________
Dear USER! If I helped you in one of your posts, then please give me reputation! I also will give you if you help me!

samtey is offline   Reply With Quote
Old 14/08/2011, 07:04 PM   #7
Darnell
Gangsta
 
Darnell's Avatar
 
Join Date: Jul 2010
Posts: 852
Reputation: 34
Default Re: Gang Zone Wars

pawn Code:
if(IsPlayerConnected(killerid) && gTeam[playerid] != gTeam(killerid));
Helps ?
Darnell is offline   Reply With Quote
Old 14/08/2011, 09:45 PM   #8
MadeMan
High-roller
 
MadeMan's Avatar
 
Join Date: Jun 2007
Posts: 3,489
Reputation: 256
Default Re: AW: Gang Zone Wars

Quote:
Originally Posted by samtey View Post
PHP Code:
if(IsPlayerConnected(killerid) && gTeam[playerid] != gTeam(killerid)) // not a suicide or team kill 
pawn Code:
if(IsPlayerConnected(killerid) && gTeam[playerid] != gTeam[killerid]) // not a suicide or team kill
MadeMan is offline   Reply With Quote
Old 16/08/2011, 11:21 AM   #9
CoLLYY
Big Clucker
 
Join Date: Aug 2010
Posts: 119
Reputation: 9
Default Re: Gang Zone Wars

How i can to make a command like : /takezone for leaders ?

And when a team will be attack another team,a message like : Team X has attached team y.

If succeds,a message like : Team X has won the gangzone against TEAM Y
If fails, Team X failed to take the gangzone against TEAM Y
CoLLYY is offline   Reply With Quote
Old 16/08/2011, 11:23 AM   #10
SpiderWalk
High-roller
 
SpiderWalk's Avatar
 
Join Date: Apr 2010
Location: Serbia
Posts: 1,104
Reputation: 26
Default Re: Gang Zone Wars

Its somethink about capturing turfs?If yes I WAS SEARCHING FOR THIS!!!!!!!!!!!!!
SpiderWalk is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[AJUDA]Gang Zone DOminaveis ( o meu possui /gang criar) rene20 Português/Portuguese 2 22/09/2010 06:55 PM
[AJUDA]Gang Zone e Cor Gang angels182 Português/Portuguese 4 16/05/2010 01:56 PM


All times are GMT. The time now is 06:05 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.