[Tutorial] Easiest Way To Create Capture Zones
#1

I was seeing around whole SA-MP many people have questions how to create Capture Zone so today i am showing

a tutorial by which you can create 1 capture zone in your script


So before you script you need to know two things that is first of all you need to know how to create gang zones if

you don't know see my gang zone tutorial here

http://forum.sa-mp.com/showthread.ph...Easiest+Create


Now after you know how to create gang zone secondly you have to know how to create teams if you don't know see

my this tutorial http://forum.sa-mp.com/showthread.ph...Easiest+Create

now if you know how to script gang zone and teams now you want to know how to create capture zones right

now here we start


INCLUDES NEEDED FOR SCRIPTING

#include <a_samp>
#include <zcmd>
#include <Dudb>
#pragma unused ret_memcpy

First of all i am starting with the defines first make this color and gang zone defines in your script


HTML Code:
//Max Allowed Zones
#define MAX_GANGZONES   15

//Colors
#define COLOR_USA 0x0000FF96
#define COLOR_RUSSIA 0xFF000096
#define COLOR_UK 0x00808096
#define COLOR_CHINA 0x80800096
we are here defining the
HTML Code:
#define MAX_GANGZONES 15
You guys saw that right i put this define

to create the maximum amount of zone for capture some-one can create


you guys also saw i gave teh COLOR_USA etc this is because those are my team colors so it will be easy for me to

track the colors so i gave it there next part of our tutorial is you need to know how to make a Checkpoint if you

don't know see how to create here

http://forum.sa-mp.com/showthread.ph...ple+Checkpoint

then after you know how to create a checkpoint come to know now for example i choose my 4 teams USA,RUSSIA,

UK and China so we have teams and everything set up checkpoint now only thing is we need to know how to make

the capture system so to make it first go to your script line

Code:
public OnPlayerEnterCheckpoint(playerid)
so after you went to this line you need something more to make something in this line those things are


Code:
new Checkpoint[MAX_PLAYERS];
new timer;
top of
Code:
public OnGameModeInit()
so when you put them there these are used because to set

timer and max checkpoints the new timer; is to set the timer for zone to 30,40 secs whatever you like and the

new Checkpoint[MAX_PLAYERS]; is for the maximum amount of checkpoint we are using for our script


so then again come to public OnPlayerEnterCheckpoint (playerid)

then after you go there just script the following lines



Code:
 SendClientMessage(playerid, 0x00FF007A, "Wait 30 Seconds - To Caputre this Zone."); // Telling the player to        wait 30 seconds.
    GangZoneFlashForAll(China,  0xFF80FF76); // Makes the turf Flash Pink ( telling everyone its being taken over )
    SendClientMessageToAll(0xFF80FFFF, "The gangzone is being taken over"); // Sending Message to all players.
    timer = SetTimerEx("SetZone", 30000, false, "i", playerid); // Setting the Timer... ( 30 seconds )
    Checkpoint[playerid] = 1; // Telling the variable that the player is in the checkpoint.
SendClientMessage thing is to send the message to player that he has to wait for 30 seconds to capture the zone

gangzoneflashforall China is to flash the zone when some-one enters the checkpoint SendClientMessageToAll

that symbol is used for sending the message to all that the zone is being taken over by some-one and

timer = SetTimerEx("SetZone",30000,false,"i",playerid); remember we have the new timer; this new timer is used

here as timer = SetTimerEx to set the zone timer to 30 seconds for players to capture it to thats why we are

using that new timer; thing in our gm or else it would be of no use but this timer thing is very important thing in

the capture things and we are using the Checkpoint[playerid] = 1; to check if the player is in the checkpoint and

is in.

so when we complete the OnPlayerEnterCheckpoint it will be something like this


Code:
public OnPlayerEnterCheckpoint(playerid) // If the player enters a particluar checkpoint
{
    SendClientMessage(playerid, 0x00FF007A, "Wait 30 Seconds - To Caputre this Zone."); // Telling the player to wait 30 seconds.
    GangZoneFlashForAll(USA,  0xFF80FF76); // Makes the turf Flash Pink ( telling everyone its being taken over )
    GangZoneFlashForAll(China,  0xFF80FF76); // Makes the turf Flash Pink ( telling everyone its being taken over )
    SendClientMessageToAll(0xFF80FFFF, "The gangzone is being taken over"); // Sending Message to all players.
    timer = SetTimerEx("SetZone", 30000, false, "i", playerid); // Setting the Timer... ( 30 seconds )
    Checkpoint[playerid] = 1; // Telling the variable that the player is in the checkpoint.
    return 1;
}
so the next part of the tutorial is we have to know how to make a GangZoneStopFlashForAll when player leaves

checkpoint and show messages for it we need to script like this

Code:
if(Checkpoint[playerid] == 1)
    {
        SendClientMessage(playerid, 0x00FF007A, " You have left the checkpoint , You have failed to capture");
        GangZoneStopFlashForAll(USA);
        GangZoneStopFlashForAll(China);
        SendClientMessageToAll(0x00FF007A, "Zone was not taken over");
        KillTimer(timer);
        Checkpoint[playerid] = 0;
    }
we are giving the if checkpoint thing to check if the player is in checkpoint so to know when the player will leave.

SendClientMessage we are using this thing again to say player that he has left the checkpoint.

GangZoneStopFlashForAll(China); this line is used so when the player is leaving the checkpoint it will stop flash

or the whole server will be a bug. SendClientMessageToAll is used again to say everyone that the zone was not

taken over or what message you like to give. KillTimer(timer); is to stop a dangerous bug which i faced first to not

give bonus to who did not capture the zone as much as i know it is this, Checkpoint[playerid] = 0; then we will use

it to say that player is no more in checkpoint which means now the player is not in and its 0.

So when we complete our OnPlayerLeaveCheckpoint(playerid) thing then the code should be something like this



Code:
public OnPlayerLeaveCheckpoint(playerid)
{
    if(Checkpoint[playerid] == 1)
    {
        SendClientMessage(playerid, 0x00FF007A, " You have left the checkpoint , You have failed to capture");
        GangZoneStopFlashForAll(USA);
        GangZoneStopFlashForAll(China);
        SendClientMessageToAll(0x00FF007A, "Zone was not taken over");
        KillTimer(timer);
        Checkpoint[playerid] = 0;
    }
    return 1;
}
Now We Come To The Last Step Of Our Capture Zone To Set The Zone To Which Team Captures It.


Code:
forward SetZone(playerid);
public SetZone(playerid)
{
SetPlayerScore(playerid,GetPlayerScore(playerid)+5 );
GivePlayerMoney(playerid,6000);
SendClientMessage(playerid, COLOR_BLUE,"You've capture the zone and receive 6000 $ and 5 score");
we are using the forward to forward our public setzone so when we forwarded it so when the zone is captured it will

give the player bonus and other money things SetPlayerScore(playerid,GetPlayerScore(playerid)+5 ); so we are

using this thing to give the player 5 score bonus GivePlayerMoney(playerid,6000); we are using this one to give

player money of about 6000. and again we are using the sendclientmessage to say player that he has got this

amount of things as gift.

Code:
if(gTeam[playerid] == TEAM_USA)
{
	GangZoneShowForAll(USA,COLOR_USA);
}
if(gTeam[playerid] == TEAM_UK)
{
	GangZoneShowForAll(USA,COLOR_UK);
}
if(gTeam[playerid] == TEAM_RUSSIA)
{
	GangZoneShowForAll(USA,COLOR_RUSSIA);
}
if(gTeam[playerid] == TEAM_CHINA)
{
	GangZoneShowForAll(USA,COLOR_CHINA);
}
if(gTeam[playerid] == TEAM_USA)
{
	GangZoneShowForAll(China,COLOR_USA);
}
if(gTeam[playerid] == TEAM_UK)
{
	GangZoneShowForAll(China,COLOR_UK);
}
if(gTeam[playerid] == TEAM_RUSSIA)
{
	GangZoneShowForAll(China,COLOR_RUSSIA);
}
if(gTeam[playerid] == TEAM_CHINA)
{
	GangZoneShowForAll(China,COLOR_CHINA);
}
so as the zone is captured we need to know which team captured to for it we gave to show the gangzone color

TEAM_RUSSIA then RUSSIA color as in the define i already said easy to find our color if we define in team name

so when zone captured we are giving the color of the team.

so when scripting of setzone is finished it will look something like this

Code:
forward SetZone(playerid);
public SetZone(playerid)
{
SetPlayerScore(playerid,GetPlayerScore(playerid)+5 );
GivePlayerMoney(playerid,6000);
SendClientMessage(playerid, COLOR_BLUE,"You've capture the zone and receive 500 $ and 5 score");
if(gTeam[playerid] == TEAM_USA)
{
	GangZoneShowForAll(USA,COLOR_USA);
}
if(gTeam[playerid] == TEAM_UK)
{
	GangZoneShowForAll(USA,COLOR_UK);
}
if(gTeam[playerid] == TEAM_RUSSIA)
{
	GangZoneShowForAll(USA,COLOR_RUSSIA);
}
if(gTeam[playerid] == TEAM_CHINA)
{
	GangZoneShowForAll(USA,COLOR_CHINA);
}
if(gTeam[playerid] == TEAM_USA)
{
	GangZoneShowForAll(China,COLOR_USA);
}
if(gTeam[playerid] == TEAM_UK)
{
	GangZoneShowForAll(China,COLOR_UK);
}
if(gTeam[playerid] == TEAM_RUSSIA)
{
	GangZoneShowForAll(China,COLOR_RUSSIA);
}
if(gTeam[playerid] == TEAM_CHINA)
{
	GangZoneShowForAll(China,COLOR_CHINA);
}
return 1;
}
I KNOW THERE IS ONE BUG WHICH I CAN'T FIX THAT IS PLAYER OF ONE TEAM CAN CAPTURE IT THOUSAND TIMES.

and in this tutorial i have used this 4 teams as example and i created a zone name China for this tutorial and

i used OnPlayerSpawn under it SetPlayerCheckpoint(playerid,cords) to make my checkpoint and capture zone

this is a easy way to create capture zone as i know SO THANK YOU! For Watching my tutorial

If I Helped You Please +REP
Reply
#2

Didn't check it yet but i will test it and edit my post i may use it for my gang wars server
Reply
#3

LoL!
Good Work! xD

Have Bugs?
Reply
#4

Thank You! Guys Please Rate My Thread And BTW It Has Only One Bug Which I Mentioned I Am Unbale To Fix But

When I Know It I Will Tell You Guys The Bug Is A Team Can Capture It Millions Of Time
Reply
#5

Use variables to detect if zone has been captured or not.
Reply
#6

Ok thank you! i'll try to make it as soon as possible
Reply
#7

You can use following to detect that if its already captured
pawn Code:
new tCP[30];
new iCP[30];
Example Code:
pawn Code:
public OnPlayerEnterDynamicCP(playerid, checkpointid)
{
  if(checkpointid == CP[UnityStation])
   {
     if(tCP[UnityStation] == gTeam[playerid]) return SendClientMessage(playerid, COLOR_RED,"This zone is already captured by your team");
     if(UnderAttack[UnityStation] == 1) return SendClientMessage(playerid, COLOR_RED,"This zone is already being taken over!");
     UnderAttack[UnityStation] = 1;
     timer[playerid][UnityStation] = SetTimerEx("CaptureZone",30000,false,"i", playerid);
     SendClientMessage(playerid, COLOR_YELLOW,"You're Capturing this zone! Wait here for 30 Seconds!");
     new string[128];
     format(string, sizeof(string),"[ATTENTION]: Unity Station is Being taken Over!");
     SendClientMessageToAll(COLOR_RED,string);
     iCP[playerid] = UnityStation;
   }
Reply
#8

Thank You Bro for your comment its great
Reply
#9

Doesn't work and you can capture it as much as you want.
I can't find any good tutorial!
Reply
#10

Quote:
Originally Posted by JimmyCh
View Post
Doesn't work and you can capture it as much as you want.
I can't find any good tutorial!
Read the replies again..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)