[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


Messages In This Thread
Creating captureable GangZones. [Best for TDM] - by Jarnu - 20.08.2012, 15:16
Re: Creating captureable GangZones. [Best for TDM] - by Jarnu - 28.08.2012, 09:03
Re: Creating captureable GangZones. [Best for TDM] - by Jeth - 28.08.2012, 11:01
Re: Creating captureable GangZones. [Best for TDM] - by Inverse9 - 28.08.2012, 14:33
Re: Creating captureable GangZones. [Best for TDM] - by DeadLy™ - 28.08.2012, 15:21
Re: Creating captureable GangZones. [Best for TDM] - by Lordzy - 28.08.2012, 15:43
Re: Creating captureable GangZones. [Best for TDM] - by Nirzor - 28.08.2012, 15:46
Re: Creating captureable GangZones. [Best for TDM] - by Jarnu - 29.08.2012, 09:18
Re: Creating captureable GangZones. [Best for TDM] - by Jarnu - 04.09.2012, 11:38
Re: Creating captureable GangZones. [Best for TDM] - by Devilxz97 - 04.09.2012, 13:01
Re: Creating captureable GangZones. [Best for TDM] - by Cassy_ - 04.09.2012, 13:10
Re: Creating captureable GangZones. [Best for TDM] - by Jarnu - 04.09.2012, 14:49
Re: Creating captureable GangZones. [Best for TDM] - by JustinAn - 05.09.2012, 01:32
Re: Creating captureable GangZones. [Best for TDM] - by davve95 - 05.09.2012, 05:36
Re: Creating captureable GangZones. [Best for TDM] - by Jarnu - 05.09.2012, 06:01
Re: Creating captureable GangZones. [Best for TDM] - by Jarnu - 16.09.2012, 10:56
Re: Creating captureable GangZones. [Best for TDM] - by DaRk_RaiN - 15.11.2012, 08:38
Re: Creating captureable GangZones. [Best for TDM] - by Coder_ - 20.11.2012, 17:24
Re: Creating captureable GangZones. [Best for TDM] - by Joshman543 - 20.11.2012, 19:37
Re: Creating captureable GangZones. [Best for TDM] - by ikkentim - 21.11.2012, 19:59
Re: Creating captureable GangZones. [Best for TDM] - by DiReCt hIt - 21.11.2012, 19:59
Re: Creating captureable GangZones. [Best for TDM] - by DaRk_RaiN - 24.11.2012, 09:01
Re: Creating captureable GangZones. [Best for TDM] - by [DOG]irinel1996 - 24.11.2012, 21:03
Re: Creating captureable GangZones. [Best for TDM] - by x96664 - 26.11.2012, 18:32
Respuesta: Creating captureable GangZones. [Best for TDM] - by Strier - 26.12.2012, 07:06
Re: Creating captureable GangZones. [Best for TDM] - by Dark Killer - 12.01.2013, 05:29
Re: Creating captureable GangZones. [Best for TDM] - by Jarnu - 12.01.2013, 05:42
Re: Creating captureable GangZones. [Best for TDM] - by Inverse - 21.06.2013, 07:27
Re: Creating captureable GangZones. [Best for TDM] - by DaRk_RaiN - 21.06.2013, 10:39
Re: Creating captureable GangZones. [Best for TDM] - by Inverse - 21.06.2013, 11:18

Forum Jump:


Users browsing this thread: 3 Guest(s)