[Tutorial] Creating captureable GangZones. [Best for TDM]
#1

Introduction

Hello guys, today i am going to show you how to make captureable Gang zones. Mainly for the TDM server's its very good feature. So, why wasting time.. lets start.


STEP BY STEP | PROPER EXPLANATION | WORKS.

__________________________________

1. Defining variables.
__________________________________



First we need to define some important variables we will use in creating the capture zones.

-Checkpoints:

pawn Код:
new CP[30];
Extra Info: [30] means you can define 30 Capture zones with only one variable.. example: CP[Zone1]; You can increase it or decrease it as per your Zone numbers.

-Gang Zones

pawn Код:
new Zone[30];
Extra Info: same as above

-Main variables use to define the Gang zone for particular team

pawn Код:
new tCheck[30];
new zDefine[MAX_PLAYERS];
new UnderAttack[30];
Extra Info (tCheck) : It will be used to check that the zone is captured by particular team.
Extra Info (zDefine) : will be used to define the zone and the color of GangZone.
Extra Info (UnderAttack) : will be used to check that if the zone is already being taken over and to stop other player to capture it while its already being captured.

-Timer

pawn Код:
new timer[MAX_PLAYERS][30];
Extra Info: self understandable.

TIP: We will use streamer for multiple checkpoints.

_______________________________________
2. Creating Gang Zone and Checkpoints
_______________________________________


As we have defined our variables.. we can now create the Checkpoints and GangZones.

-Checkpoints

First we need to define the name of checkpoint.
pawn Код:
#define Zone 0
Extra Info: We will use the above define for the GangZone too

Now creating the checkpoint for this we will use CreateDynamicCP
Under OnGameModeInit we will put the following code
pawn Код:
CP[Zone] = CreateDynamicCP(.....);
Same for GangZone

pawn Код:
Zone[Zone] = GangZoneCreate(......);
End: We are now done with our Checkpoint and GangZone too.. lets make it captureable!

___________________________________________
3. Making the Zone Captureable
___________________________________________


Extra: As we have used the Streamer checkpoint, so we will use OnPlayerEnterDynamicCP callback for the Checkpoint.

Under OnPlayerEnterDynamicCP

pawn Код:
if(checkpointid == CP[Zone]) {
First: Checking if the zone is already capture by the player's team

pawn Код:
if(tCheck[Zone] == gTeam[playerid]) return SendClientMessage(playerid, 0xFF0000FF,"ERROR: This zone is already captured by your team");
Second: Checking if the zone is already being taken over

pawn Код:
if(UnderAttack == 1) return SendClientMessage(playerid, 0xFF0000FF,"ERROR: This zone is already being taken over!");
Third: Checking if the player who is trying to enter zone is in vehicle

pawn Код:
if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0xFF0000FF,"ERROR: You cannot capture while in vehicle!");
If the above situations are not there.. then setting it UnderAttack.

pawn Код:
UnderAttack[Zone] = 1;
Setting up the timer to capture the zone.

pawn Код:
timer[playerid][Zone] = SetTimerEx("SetZone",25000,false,"i", playerid);
Flashing the zone when player enter Checkpoint.

pawn Код:
GangZoneFlashForAll(Zone[Zone],COLOR_RED);
Sending message to all the this zone is being taken over.

pawn Код:
SendClientMessageToAll(0x00FF00FF,"*Zone is being taken over!");
defining the zone for next setting up for player's team

pawn Код:
zDefine[playerid] = Zone;
Proper code for above situation
pawn Код:
if(checkpointid == CP[Zone])
{
if(tCheck[Zone] == gTeam[playerid]) return SendClientMessage(playerid, COLOR_RED,"This zone is already captured by your team");
if(UnderAttack[Zone] == 1) return SendClientMessage(playerid, COLOR_RED,"This zone is already being taken over!");
if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, RED,"ERROR: You cannot capture while in vehicle!");
UnderAttack[Zone] = 1;
timer[playerid][Zone] = SetTimerEx("SetZone",25000,false,"i", playerid);
GangZoneFlashForAll(Zone[Zone],COLOR_RED);
SendClientMessageToAll(GREEN, "Zone is being taken over");
zDefine[playerid] = Zone;
}
Now OnPlayerLeaveDynamicCP
pawn Код:
if(checkpointid == CP[Zone]) {
First doing UnderAttack = 0;
pawn Код:
UnderAttack[Zone] = 0;
Stopping the zone's flash

pawn Код:
GangZoneStopFlashForAll(Zone[Zone]);
Killing the timer

pawn Код:
KillTimer(timer[playerid][Zone]);
_________________________
Reaching towards final steps.
_________________________


Following codes are self understandable.

pawn Код:
forward SetZone(playerid);
public SetZone(playerid)
{
SetPlayerScore(playerid, GetPlayerScore(playerid) + 3); //Giving score and money
GivePlayerMoney(playerid, 3000);
SendClientMessage(playerid,GREEN,"Congratulation! You have Gained 3 Scores & 3000$ Money ");
UnderAttack[Zone] = 0; //Stopping the UnderAttack
KillTimer(timer[playerid][Zone]); //Killing the timer
SetGangZone(playerid); //We will define it..
return 1;
}
SetGangZone is also self Understandable

pawn Код:
forward SetGangZone(playerid);
public SetGangZone(playerid)
{
if(zDefine[playerid] == Zone)
{
GangZoneShowForAll(Zone[Zone],GetPlayerColor(playerid));
/*Following code looks a bit big but its very simple.. its just send msg. */
new string[126], pName5[MAX_PLAYER_NAME];
GetPlayerName(playerid,pName5,sizeof(pName5));
format(string,sizeof string,"*%s has captured Zone",pName5);
GangZoneStopFlashForAll(Zone[Zone]);
SendClientMessageToAll(GREEN, string);
tCheck[Zone] = gTeam[playerid];
}
return 1;
}

TIP: You need to kill the timer in various situations like OnPlayerDeath...

Thank you for reading the tutorial.. it might helped you a bit ..


+REP me if you liked it please.. ^-^
Reply
#2

Comment guys.. anyway.. UPDATED. and fixed a missing brace
Reply
#3

Nice Job Jarnu! it's good dude
Reply
#4

jarnu

i can't understand

i can't added capture zone please help me and tell me with easily
Reply
#5

Jarnu, Nice [Tutorial]
Good Job.
Reply
#6

In my opinion it would be more better if you explain more.
Explain each lines..so that it'll look more better than current.
Reply
#7

Jarnu a mistake you did not add the OnPlayerLeaveDynamicCP(playerid, checkpointid) lol! add it!

and Nice Tutorial jarnu great job from my great buddy! and you should explain the CreateDynamicCP more cause

in its last there is after float,y,z there is CP size and other things which newbies don't understand if they don't

know that they can't make the CP give the last codes for CP or it will be total mess! i can also make capture zones

now! but i don't cheat your tutorial! :P
Reply
#8

Quote:

Now OnPlayerLeaveDynamicCP

Quote:

Jarnu a mistake you did not add the OnPlayerLeaveDynamicCP(playerid, checkpointid) lol! add it!

Go and read the tutorial properly..

@all thanks ^_^
Reply
#9

Updated! ..Comment guys
Reply
#10

Explain each lines would be better.
btw Awesome Tutorial it will help a new scripter to script a capturezone minigames or TDM gm
Reply
#11

Quote:
Originally Posted by talkro
Посмотреть сообщение
Jarnu, Nice [Tutorial]
Good Job.
Regards, Cassy_
( [COD5]Cassy or call me [SWAT]Matrix[DELTA] )
Reply
#12

@Devil..
i will in my next tut.. ^^ and thanks
Thank You all
Reply
#13

Well explained dude!
Reply
#14

Thanks! Gonna use this later .
Reply
#15

Thank you davve and Justin ^^
Reply
#16

Fixed a small mistake.. thanks newbienoob
Reply
#17

I love it, its understandable and simple
Reply
#18

That is understandable thanks soo much ^^
We need tutorials Like this one
Reply
#19

Quote:
Originally Posted by Coder_
View Post
That is understandable thanks soo much ^^
We need tutorials Like this one
agreed
Reply
#20

it wont work; you are defining
#define Zone 0

and later saying
Zone[Zone] = GangZoneCreate(......);

this will end up in
0[0] = GangZoneCreate(......);
Reply


Forum Jump:


Users browsing this thread: 7 Guest(s)