[Tutorial] Turf War System ! [Zones]
#1

hi guys !
i will show you how to create a Turf War system simple !
well let's go !

firstly we need define the teams !
in my case i will define 3 teams
pawn Код:
//Here we will define the teams !
#define TEAM_GROOVE 0
#define TEAM_BALLAS 1
#define TEAM_VAGOS 2
now that the teams are already defined !
we need define Teams colors
how to define it?
simple we need do something like this !
pawn Код:
//We will define the colors of the team
#define GROOVE_COLOR 0x0FEA1F96 //here we define that Groove team will be green
#define BALLAS_COLOR 0xBC0EC096 // here we define that Ballas team is rose
#define VAGOS_COLOR 0xDFEF1F96 // here we define that vagos team is yellow
now that the colors are defined
we need define max teams and the max gang zones
pawn Код:
#define MAX_ZONES 3
 //this will change if you have other zone, example if you have 5 zones or 5 gang zones you must change this for 5 and if is 6 change it to 6 etc..!
#define MAX_TEAMS 3
also we need define gTeam[MAX_PLAYERS];
if you don't know how i will show you how
pawn Код:
new gTeam[MAX_PLAYERS]; //you need define this i will explain later !
now we need define the zones ! Bases and zones gang capturables
pawn Код:
//defining zones...!
//well we need define some zones here ! something like this !
//here also we will define the bases for the players !
new GROOVEZ;
new BALLASZ;
new VAGOSZ;
//for the bases will be something like this
new GROOVEB;
new BALLASB;
new VAGOSB; //you can change the name ^ of this ^ whatever do you want !
//now that Bases and Zones are defined we gotta go to OnGameModeInIt
now that the zones are defined we need the coords ! how to get coords?
i use GangZoneMarker made by iPleomax
download it here
https://sampforum.blast.hk/showthread.php?tid=279647
remember that when you get the coords you must change "," to "." change the comma ! dont forget that ! is important !
well we need define ZoneInfo and these thing...!
but we need add before this
now we need create an enum !
somehitng like this..
pawn Код:
enum Z_Info
{
    Float:z_minx,
    Float:z_miny,
    Float:z_maxx,
    Float:z_maxy,
    z_team, //team
    z_id //the id
}
pawn Код:
new ZoneTakeOverTeam[MAX_ZONES];// and this
new ZoneTakeOverTime[MAX_ZONES]; //fixed, define this too !

new ZoneInfo[MAX_ZONES][Z_Info] = {
//here we need post the coord of zones that are capturable
{2437.5,-1722.65625,2525.390625,-1634.765625, TEAM_GROVE},//an example, but this gang zone are defined as GROVEB in OnGameModeInIt
{x,y,z, TEAM_BALLAS},
{x,y,z, TEAM_VAGOS}  //here without a comma ,
}; //close
//remember that if you have 4 5 6..etc or more zones capturables you must change #define MAX_ZONES 3 this to the numbers of zones that are you getting.. in this case is 3
well now that we have defined the zones we need create a timer !
just add this !
pawn Код:
//new savetimer;
new zonetimer; // here we define the timer !!! in the zone
and also add this in OnGameModeInIt
pawn Код:
KillTimer(zonetimer);//We need define this to define the kill time(You don't say)
now we have a !killtimer well done guy !

well now if you want define the spawn zones really is not important for you know bcz i guess that you have already defined your teams and the spawns no?
but however i will show you how to do it :'3 !
pawn Код:
//Here we define the spawn of the players ! and here we can define a base if you want, but that base aren't capturable
    AddPlayerClass(107,2478.6343,-1662.2228,13.3438,249.9869,0,0,0,0,0,0); // GROOVE SPAWN
    AddPlayerClass(104,1961.4006,-1152.5022,26.0251,249.9869,0,0,0,0,0,0); // BALLAS SAWN
    AddPlayerClass(108,2804.2061,-1092.7837,30.7285,251.2403,0,0,0,0,0,0); // vagos spawn
    //AddPlayerClass(skinid, coord:x, Coord:y, COord:z, angle, here we can add weapons too, weapon ammo, weap2,ammo2,weap3,ammo3);
    //we need close it with a ; to avoid many errors !
    //This is a example
well now that we defined thats spawns xD or teams skins etc !
we need define the Zones that we defined before, do you remember?
remember that all this are in OnGameModeInIt
pawn Код:
//well now we need define the BASES ZONES AND ZONES CAPTURABLES !
    //Here we need do something like this !
    GROOVEZ = GangZoneCreate(2229.4921875,-1731.4453125,2326.171875,-1666.9921875); //here we define that GROOVE zone is now a gang zone  but still isn't capturable
    BALLASZ = GangZoneCreate(1851.5625,-1453.125,1974.609375,-1353.515625); //same as GROOVE
    VAGOSZ = GangZoneCreate(2452.1484375,-1262.6953125,2563.4765625,-1201.171875); //Like groove and ballas
    //now we gonna define the bases
    GROOVEB = GangZoneCreate(2437.5,-1722.65625,2525.390625,-1634.765625); //here we defined the bases are not capturables but are defined now
    BALLASB = GangZoneCreate(1869.140625,-1265.625,2059.5703125,-1148.4375); //now we need show the players that the zone is created go to OnPlayerSpawn
    VAGOSB = GangZoneCreate(2742.1875,-1262.6953125,2841.796875,-1163.0859375); // :D !
    //now after do these things ! we must define this (is important)
    //this for the zones this define that we gonna take a zone and will be capturable but still don't define what zone is capturable
    for(new i=0; i<MAX_ZONES; i++)
    {
        ZoneInfo[i][z_id] = GangZoneCreate(ZoneInfo[i][z_minx], ZoneInfo[i][z_miny], ZoneInfo[i][z_maxx], ZoneInfo[i][z_maxy]);
        ZoneTakeOverTeam[i] = -1;
    }
thats all i;ve explained all in tthat code
now if you have problems with that i will show you how is OnGameModeInIt
pawn Код:
public OnGameModeInit()
{
    // Don't use these lines if it's a filterscript
    SetGameModeText("Blank Script");
    KillTimer(zonetimer);//We need define this to define the kill time(You don't say)
    //Here we define the spawn of the players ! and here we can define a base if you want, but that base aren't capturable
    AddPlayerClass(107,2478.6343,-1662.2228,13.3438,249.9869,0,0,0,0,0,0); // GROOVE SPAWN
    AddPlayerClass(104,1961.4006,-1152.5022,26.0251,249.9869,0,0,0,0,0,0); // BALLAS SAWN
    AddPlayerClass(108,2804.2061,-1092.7837,30.7285,251.2403,0,0,0,0,0,0); // vagos spawn
    //AddPlayerClass(skinid, coord:x, Coord:y, COord:z, angle, here we can add weapons too, weapon ammo, weap2,ammo2,weap3,ammo3);
    //we need close it with a ; to avoid many errors !
    //This is a example
    //i will add a base but later ! i will explain it too ! don't worry
    //well now we need define the BASES ZONES AND ZONES CAPTURABLES !
    //Here we need do something like this !
    GROOVEZ = GangZoneCreate(2229.4921875,-1731.4453125,2326.171875,-1666.9921875); //here we define that GROOVE zone is now a gang zone  but still isn't capturable
    BALLASZ = GangZoneCreate(1851.5625,-1453.125,1974.609375,-1353.515625); //same as GROOVE
    VAGOSZ = GangZoneCreate(2452.1484375,-1262.6953125,2563.4765625,-1201.171875); //Like groove and ballas
    //now we gonna define the bases
    GROOVEB = GangZoneCreate(2437.5,-1722.65625,2525.390625,-1634.765625); //here we defined the bases are not capturables but are defined now
    BALLASB = GangZoneCreate(1869.140625,-1265.625,2059.5703125,-1148.4375); //now we need show the players that the zone is created go to OnPlayerSpawn
    VAGOSB = GangZoneCreate(2742.1875,-1262.6953125,2841.796875,-1163.0859375); // :D !
    //now after do these things ! we must define this (is important)
    //this for the zones this define that we gonna take a zone and will be capturable but still don't define what zone is capturable
    for(new i=0; i<MAX_ZONES; i++)
    {
        ZoneInfo[i][z_id] = GangZoneCreate(ZoneInfo[i][z_minx], ZoneInfo[i][z_miny], ZoneInfo[i][z_maxx], ZoneInfo[i][z_maxy]);
        ZoneTakeOverTeam[i] = -1;
    }
    return 1;
}
now that you know and have defined all this !
we need go to OnPlayerSpawn and add some codes !
codes simples you know :3 e_E !
something like this(we'll use this code https://sampwiki.blast.hk/wiki/GangZoneShowForAll )
pawn Код:
public OnPlayerSpawn(playerid)
{
    for(new i=0; i<MAX_ZONES; i++)
    {
        GangZoneShowForPlayer(playerid, ZoneInfo[i][z_id], GetTeamColor(ZoneInfo[i][z_team]));
        if(ZoneTakeOverTeam[i] != -1) GangZoneFlashForPlayer(playerid, ZoneInfo[i][z_id], GetTeamColor(ZoneTakeOverTeam[i]));
    }
    GangZoneShowForAll(GROOVEZ, 0x0FEA1F96); //this define the colors of the zones !
    GangZoneShowForAll(BALLASZ, 0xBC0EC096);
    GangZoneShowForAll(VAGOSZ, 0x0FEA1F96);
    //Now the bases
    GangZoneShowForAll(GROOVEB, 0x0FEA1F96);
    GangZoneShowForAll(VAGOSB, 0xDFEF1F96);//now we must define something
    GangZoneShowForAll(BALLASB, 0xBC0EC096);//what we gonna explain and create now? we need a forward a new funtion ! c'mon !
    return 1;
}
now that we have defined this on OnPlayerSpawn
we will create a forward !
i will explain it in the code so check this
do something like this !
pawn Код:
//Here we will post the code of the new Funtion !
//what do this funtion? this send a message and send the score and check if a player is in the zone check if
//3 users are in the zone to start to capture the zone !
//check the time that you must stay to capture the zone !
//i;m gonna explain the funtion !
forward ZoneUpdate();
public ZoneUpdate()
{
    for(new z=0; z < MAX_ZONES; z++)
    {
        if(ZoneTakeOverTeam[z] == -1)
        {
            for(new t=0; t < MAX_TEAMS; t++)
            {
                if(t == ZoneInfo[z][z_team]) continue;
                if(GetMembersInZone(z, t) >= 3) //this you can change ! if you change this to 1, you can capture a zone with 1 player and don't need more help !
                {
                    ZoneTakeOverTeam[z] = t;
                    GangZoneFlashForAll(ZoneInfo[z][z_id], GetTeamColor(t));// this is when you are in the zone start to attack it, and will change of color !
                    ZoneTakeOverTime[z] = 0;
                }
            }
        }
        else
        {
            if(GetMembersInZone(z, ZoneTakeOverTeam[z]) > 0)
            {
                ZoneTakeOverTime[z]++;
                if(ZoneTakeOverTime[z] >= 30)//this is the time that you need wait to capture the zone, now is 30 seconds but you can change it ! :D !
                {
                    GangZoneStopFlashForAll(ZoneInfo[z][z_id]);
                    GangZoneShowForAll(ZoneInfo[z][z_id], GetTeamColor(ZoneTakeOverTeam[z]));///here if you capture the zones, the zone will change to the color of your team !
                    ZoneInfo[z][z_team] = ZoneTakeOverTeam[z];
                    for(new i=0; i<MAX_PLAYERS; i++)
                    {
                        if(IsPlayerConnected(i))//above, checks if you are online
                        {
                            if(GetPlayerZone(i) == z && gTeam[i] == ZoneTakeOverTeam[z])//this checks if you capture the gang zone !
                            {
                                SetPlayerScore(i, GetPlayerScore(i) + 2);//here if u capture the zone will give you 2 of score you can change it to 5 20 523 :D
                                pInfo[i][Kills] += 2;//will add you 2 kills
                                GameTextForPlayer(i, "~g~Turf ~r~taken over~n~~b~~h~+2 score", 6000, 3);// this is the message when you capture the zone
                            }
                        }
                    }
                    ZoneTakeOverTeam[z] = -1;
                    ZoneTakeOverTime[z] = 0;
                }
            }
            else
            {
                ZoneTakeOverTeam[z] = -1;
                GangZoneStopFlashForAll(ZoneInfo[z][z_id]);//this shows to all players when the zone is attacked and when is captured (with the ned color)
                ZoneTakeOverTime[z] = 0;
            }
        }
    }
}
now we need define when a player is in the gang zone to able to capture
something like this
remember that i'm explaining all in the codes so pay atenttion !
pawn Код:
//now we need define more things ! with this you can check if a player is the gang zone ! if no, isn't able to capture the zone (logic)
//im gonna to explain !
GetMembersInZone(zoneid, team)
{
    new count = 0; // you do here a new count ! above
    new Float:px, Float:py, Float:pz; //this to check if the players is in the x gang zone !
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))///checks if you are online
        {
            if(GetPlayerState(i) != PLAYER_STATE_WASTED && gTeam[i] == team)//this checks if you are in Wasted state !
            {
                GetPlayerPos(i, px, py, pz);//gets your position and start to capture the zone !
                if(px > ZoneInfo[zoneid][z_minx] && py > ZoneInfo[zoneid][z_miny] && px < ZoneInfo[zoneid][z_maxx] && py < ZoneInfo[zoneid][z_maxy])//this gets the zone info where are you possioned !
                {
                    count++;
                }
            }
        }
    }
    return count;
}
well now we need define the colors when a player capture a area or zone !
something like this !
pawn Код:
//now we need define the colors of the teams
//ups not of the teams of the gang zones when you capture for example
// case:TEAM_GROOVE: return 0x0FEA1F96 thats says that if a user that is using
//Groove team will capture with the color GReen this is the code of the color green 0x0FEA1F96

GetTeamColor(team)
{
    switch(team)
    {
        case TEAM_GROOVE: return 0x0FEA1F96;//we define the colors i explained before
        case TEAM_BALLAS: return 0xBC0EC096;
        case TEAM_VAGOS: return 0xDFEF1F96;// :D continue !
    }
    return 0;
}
now gonna check if the player is in the zone
pawn Код:
stock GetPlayerZone(playerid)
{
    if(GetPlayerState(playerid) != PLAYER_STATE_WASTED)//waa this?, this get the zone that we are attacking in the momment !, this checks if the zone is capturable or not !
    {
        new Float:px, Float:py, Float:pz;//here gets the coords !
        GetPlayerPos(playerid, px, py, pz);//gets your position !
        for(new i=0; i<MAX_ZONES; i++)//to all players
        {
            if(px > ZoneInfo[i][z_minx] && py > ZoneInfo[i][z_miny] && px < ZoneInfo[i][z_maxx] && py < ZoneInfo[i][z_maxy]) return i;
        }//and finito ! already we defined all zones capturables and zones not capturables
    }
    return -1;
}
well thats all !
hope you like this tutorial
i used this in my gm a works fine !
+rep me if you like and ...if you have internet see you later !
-RafaelZam !
bai
Reply
#2

It's good and all that, but there's tutorials extremely similar to this that already exist.
Reply
#3

Quote:
Originally Posted by DanishHaq
Посмотреть сообщение
It's good and all that, but there's tutorials extremely similar to this that already exist.
what tutorial?
i've searched many tutorials to do this and nothin'
i've made this bcz many ppl are requestin' this and well, just tryin' to get it right :3
just trying to share somethingXD but nvm
ty
C: !
Reply
#4

pretty nice,, btw look visitor message
Reply
#5

Thank you !
i did :3
Reply
#6

Quote:
Originally Posted by Rafael_Zambrano
Посмотреть сообщение
what tutorial?
i've searched many tutorials to do this and nothin'
i've made this bcz many ppl are requestin' this and well, just tryin' to get it right :3
just trying to share somethingXD but nvm
ty
C: !
https://sampforum.blast.hk/showthread.php?tid=353267
https://sampforum.blast.hk/showthread.php?tid=276352

I'm not saying yours is bad, it's good, I was just saying that there's already a couple :P.
Reply
#7

Quote:
Originally Posted by DanishHaq
Посмотреть сообщение
https://sampforum.blast.hk/showthread.php?tid=353267
https://sampforum.blast.hk/showthread.php?tid=276352

I'm not saying yours is bad, it's good, I was just saying that there's already a couple :P.
XD
then i will say that i'm updating it xD :P
hope be helpful the tuto :3
anyway ty :3
Reply
#8

C:\Users\Gebruiker\Desktop\SA-MP 0.3x\gamemodes\Test.pwn(501) : error 017: undefined symbol "ZoneInfo"
C:\Users\Gebruiker\Desktop\SA-MP 0.3x\gamemodes\Test.pwn(501) : warning 215: expression has no effect
C:\Users\Gebruiker\Desktop\SA-MP 0.3x\gamemodes\Test.pwn(501) : error 001: expected token: ";", but found "]"
C:\Users\Gebruiker\Desktop\SA-MP 0.3x\gamemodes\Test.pwn(501) : error 029: invalid expression, assumed zero
C:\Users\Gebruiker\Desktop\SA-MP 0.3x\gamemodes\Test.pwn(501) : fatal error 107: too many error messages on one line


I get these error messages on the line
ZoneInfo[i][z_id] = GangZoneCreate(ZoneInfo[i][z_minx], ZoneInfo[i][z_miny], ZoneInfo[i][z_maxx], ZoneInfo[i][z_maxy]);
Reply
#9

Quote:
Originally Posted by Joeyer5
Посмотреть сообщение
C:\Users\Gebruiker\Desktop\SA-MP 0.3x\gamemodes\Test.pwn(501) : error 017: undefined symbol "ZoneInfo"
C:\Users\Gebruiker\Desktop\SA-MP 0.3x\gamemodes\Test.pwn(501) : warning 215: expression has no effect
C:\Users\Gebruiker\Desktop\SA-MP 0.3x\gamemodes\Test.pwn(501) : error 001: expected token: ";", but found "]"
C:\Users\Gebruiker\Desktop\SA-MP 0.3x\gamemodes\Test.pwn(501) : error 029: invalid expression, assumed zero
C:\Users\Gebruiker\Desktop\SA-MP 0.3x\gamemodes\Test.pwn(501) : fatal error 107: too many error messages on one line


I get these error messages on the line
ZoneInfo[i][z_id] = GangZoneCreate(ZoneInfo[i][z_minx], ZoneInfo[i][z_miny], ZoneInfo[i][z_maxx], ZoneInfo[i][z_maxy]);
my bad !
i fixed the post, thank you
well we need define ZoneInfo and these thing...!
pawn Код:
new ZoneInfo[MAX_ZONES][Z_Info] = {
//here we need post the coord of zones that are capturable
{2437.5,-1722.65625,2525.390625,-1634.765625, TEAM_GROVE},//an example, but this gang zone are defined as GROVEB in OnGameModeInIt
{x,y,z, TEAM_BALLAS},
{x,y,z, TEAM_VAGOS}  //here without a comma ,
}; //close
//remember that if you have 4 5 6..etc or more zones capturables you must change #define MAX_ZONES 3 this to the numbers of zones that are you getting.. in this case is 3
thank you i forget add that C:
Reply
#10

There's more errors than that apparently.

C:\Users\Gebruiker\Desktop\SA-MP 0.3x\gamemodes\test.pwn(58 ) : error 017: undefined symbol "Z_Info"
C:\Users\Gebruiker\Desktop\SA-MP 0.3x\gamemodes\test.pwn(613) : error 017: undefined symbol "z_id"
C:\Users\Gebruiker\Desktop\SA-MP 0.3x\gamemodes\test.pwn(614) : error 017: undefined symbol "ZoneTakeOverTeam"
C:\Users\Gebruiker\Desktop\SA-MP 0.3x\gamemodes\test.pwn(614) : warning 215: expression has no effect
C:\Users\Gebruiker\Desktop\SA-MP 0.3x\gamemodes\test.pwn(614) : error 001: expected token: ";", but found "]"
C:\Users\Gebruiker\Desktop\SA-MP 0.3x\gamemodes\test.pwn(614) : error 029: invalid expression, assumed zero
C:\Users\Gebruiker\Desktop\SA-MP 0.3x\gamemodes\test.pwn(614) : fatal error 107: too many error messages on one line

I did re-do everything with the things you added in the tutorial, do you miss more stuff or did I do something wrong ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)