SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 23/07/2013, 02:41 PM   #1
JimmyCh
Gangsta
 
JimmyCh's Avatar
 
Join Date: Mar 2013
Location: LB
Posts: 656
Reputation: 62
Default How to make Capture Zones!

Hey guys, I'm back with a new tutorial.
I'm pretty sure you're gonna like this one, because the ones I've seen aren't the best, so this tutorial will help you make fully working capture zones!
Let's get started!
Before we start, make sure you do the following include under #include <a_samp>:
pawn Code:
#include <streamer>

First thing we're gonna do is defining the gang zone's name.
Let's call it CAPZONE.
pawn Code:
#define CAPZONE 0
I will make two teams so you can understand more.
pawn Code:
#define TEAM1 0
#define TEAM2 1
#define NONE  2
NONE will be used OnGameModeInIt to show it's not captured by anyone.

Some color defines for the teams and others we will use.
pawn Code:
#define     TEAM1_COLOR     0x0011FF93
#define     TEAM2_COLOR     0xFF0000C8
#define     COLOR_WHITE     0xFFFFFFFF
#define     COLOR_RED       0xFF0000FF
#define     COLOR_GREEN     0x33AA33AA
#define     COLOR_ORANGE    0xFF560AFF
#define     STEALTH_BLUE    0x0077BB00

Now we need some stuff to make our script work, add this on top of the script:
pawn Code:
new tCP[30];
new UnderAttack[30] = 0;
new CP[30];
new Zone[30];
new Captured[MAX_PLAYERS][30];
new timer[MAX_PLAYERS][30];
new CountVar[MAX_PLAYERS][30];
new Text:CountText[MAX_PLAYERS];
new IsPlayerCapturing[MAX_PLAYERS][30];
We will use those later.

Alright we're done with that now!
Let's move on!
Now OnGameModeInIt, we're gonna put that the zone is not captured by anyone, and isn't under attack, and we're gonna create the gang zone and dynamic CP!
We will add the following:
pawn Code:
tCP[CAPZONE] = NONE;
    UnderAttack[CAPZONE] = 0;
    Zone[CAPZONE] = GangZoneCreate(MinX, MinY, MaxX, MaxY);
    CP[CAPZONE] = CreateDynamicCP(X,Y,Z, radius, -1, -1, -1, 100.0);
Let me explain what I did.
First the tCP[CAPZONE] = NONE; it's to show that the zone is not captured by anyone OnGameModeInIt.
It's not UnderAttack too( = 0), we also created the GangZone and The Dynamic CP.
Do not forget to change the coordinates to your zone location.

Now OnPlayerConnect, we need to add some stuff too:
Put the following:
pawn Code:
SetPlayerMapIcon(playerid, 2, X,Y,Z, 19, MAPICON_GLOBAL);
    GangZoneShowForAll(Zone[CAPZONE], 0x00000043);
    IsPlayerCapturing[playerid][CAPZONE] = 0;
    CountVar[playerid][CAPZONE] = 25;
    if(tCP[CAPZONE] == NONE) GangZoneShowForAll(Zone[CAPZONE], -66);
    else if(tCP[CAPZONE] == TEAM1) GangZoneShowForAll(Zone[CAPZONE], TEAM1_COLOR);
    else if(tCP[CAPZONE] == TEAM2) GangZoneShowForAll(Zone[CAPZONE], TEAM2_COLOR);
So first of all, we're creating a map icon on the capture zone, change the coordinates of it(It's a flag by the way).
We made the Zone[CAPZONE] show as white color because it's not captured.
Since this is OnPlayerConnect, so we're checking if the zone if captured so we show the player who captured the zone.
We put that if the zone is captured by TEAM1, it shows as TEAM1 color.
And for the TEAM2 the same thing, else if it's not captured it shows as white.

Let's move to OnPlayerDisconnect now, we will put the following:
pawn Code:
if(Captured[playerid][CAPZONE] == 0 && IsPlayerCapturing[playerid][CAPZONE] == 1)
    {
    LeavingCAPZONE(playerid);
    }
So what I did now that if the player is capturing the capture zone and disconnects, it will check the stock that we will make later, the LeavingCAPZONE stock.

Now OnPlayerSpawn, we will also put this:
pawn Code:
if(Captured[playerid][CAPZONE] == 0 && IsPlayerCapturing[playerid][CAPZONE] == 1)
    {
    LeavingCAPZONE(playerid);
    }
We checked the same, if he's capturing and spawns, it will stop capturing, else it will bug and keep capturing EVEN if he left the area.

OnPlayerDeath, we will do the same:
pawn Code:
if(Captured[playerid][CAPZONE] == 0 && IsPlayerCapturing[playerid][CAPZONE] == 1)
        {
        LeavingCAPZONE(playerid);
        }
We also checked that if he died while capturing, it will return to the stock LeavingCAPZONE which we'll check later.

Now let's move on to the OnPlayerEnterDynamicCP.
Let's start with this:
pawn Code:
forward OnPlayerEnterDynamicCP(playerid, checkpointid);
public OnPlayerEnterDynamicCP(playerid, checkpointid)
Now that we have this, we will check that if the checkpoint is called CAPZONE, it will start capturing(Also a stock).
So OnPlayerEnterDynamicCP we got the following:
pawn Code:
forward OnPlayerEnterDynamicCP(playerid, checkpointid);
public OnPlayerEnterDynamicCP(playerid, checkpointid)
{
    if(checkpointid == CP[CAPZONE])
    {
        if(UnderAttack[CAPZONE] == 0)
        {
            if(tCP[CAPZONE] != gTeam[playerid])
            {
                CountVar[playerid][CAPZONE] = 25;
                ActiveCAPZONE(playerid);

            } else return SendClientMessage(playerid, COLOR_RED,"*This zone is already captured by your team!");
        } else return CaptureZoneMessage(playerid, 2);
    }
}
We checked that if he entered the zone and it's not under attack already, it will start capturing, else it will show a message that it's under attack.
And we checked that if his team already captured it, he can't capture it.

Now, the same for OnPlayerLeaveDynamicCP, we will put this:
pawn Code:
forward OnPlayerLeaveDynamicCP(playerid, checkpointid);
public OnPlayerLeaveDynamicCP(playerid, checkpointid)
{
    if(checkpointid == CP[CAPZONE] && Captured[playerid][CAPZONE] == 0 && IsPlayerCapturing[playerid][CAPZONE] == 1 && !IsPlayerInDynamicCP(playerid, CP[CAPZONE]))
    {
        LeavingCAPZONE(playerid);
    }
}
We just checked that if the CP is the CAPZONE checkpoint, and if he's capturing and if he left the checkpoint, it will also stop capturing( From the stock which we're gonna put).

Now let's make the stock for the CaptureZoneMessage before we continue:
pawn Code:
stock CaptureZoneMessage(playerid, messageid)
{
    switch(messageid)
    {
       case 1:
       {
           SendClientMessage(playerid, COLOR_RED,"You cannot capture while in a vehicle!");
       }
       case 2:
       {
           SendClientMessage(playerid, COLOR_RED,"This zone is already being taken over!");
       }
    }
    return 1;
}
Alright, we're good to start the real work!
Let's start with the stock, ActiveCAPZONE.
pawn Code:
stock ActiveCAPZONE(playerid)
{
        if(UnderAttack[CAPZONE] == 0)
        {
            if(!IsPlayerInAnyVehicle(playerid))
            {
                UnderAttack[CAPZONE] = 1;
                timer[playerid][CAPZONE] = SetTimerEx("CAPZONETimer", 25000, false,"i",playerid);
                Captured[playerid][CAPZONE] = 0;
                SendClientMessage(playerid, 0xFFFFFFFF,"| Stay in this checkpoint for 25 seconds to capture it! |");
                if(gTeam[playerid] == TEAM1)
                {
                  GangZoneFlashForAll(Zone[CAPZONE], TEAM1_COLOR);
                }
                else if(gTeam[playerid] == TEAM2)
                {
                  GangZoneFlashForAll(Zone[CAPZONE], TEAM2_COLOR);
                }

                //------Message-----
                if(tCP[CAPZONE] == TEAM1)
                {
                  SendClientMessage(playerid, COLOR_WHITE,"This flag is controlled by team 1!");
                  SendClientMessageToAll(STEALTH_BLUE,"*Capture Zone is under attack!");
                }
                else if(tCP[CAPZONE] == TEAM2)
                {
                  SendClientMessage(playerid, COLOR_WHITE,"This flag is controlled by team 2!");
                  SendClientMessageToAll(STEALTH_BLUE,"*Capture Zone is under attack!");
                }

                else if(tCP[CAPZONE] == NONE)
                {
                  SendClientMessage(playerid, COLOR_WHITE,"This flag is not controlled by any team!");
                }
                //---------loop-------//
                for(new i = 0; i < MAX_PLAYERS; i ++)
                {
                   IsPlayerCapturing[i][CAPZONE] = 1;
                }
            }
            else return CaptureZoneMessage(playerid, 1);
        }
        else return CaptureZoneMessage(playerid, 2);
        return 1;
}
Don't worry, gonna explain it.
First of all, to start capturing we checked if it's not already getting captured.
Secondly, we checked if he's in a vehicle, if so, it will return CaptureZoneMessage 1, which says that he can't capture in a vehicle.
If he follows the requirements, it starts the timer which is 25 seconds to capture(You can change it) and it will start flashing the zone with the team's color.
It will also send a message that the zone is under attack.
It will also tell the player who already controls the flag, Team1, Team2, or NONE.


Let's move on, shall we?
Now let's see CAPZONECaptured, where we have done capturing the zone.
We will make a system to send his team 1 score and the player himself some score and cash.
pawn Code:
stock CAPZONECaptured(playerid)
{

    Captured[playerid][CAPZONE] = 1;
    UnderAttack[CAPZONE] = 0;
    KillTimer(timer[playerid][CAPZONE]);
    CountVar[playerid][CAPZONE] = 25;
    GivePlayerScore(playerid, 5);
    GivePlayerMoney(playerid, 5000);
    SendClientMessage(playerid, COLOR_GREEN,"Congratulations! You have captured the area! You received +5 scores and +$5000 cash!");
    //==========================================================================
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
       IsPlayerCapturing[i][CAPZONE] = 0;
       if(gTeam[i] == gTeam[playerid])
       {
           SendClientMessage(i, 0xFFFFFFFF,"*Your team has captured the area! You received +1 score for it!");
           GivePlayerScore(i, 1);
       }
    }
    //==========================================================================
    tCP[CAPZONE] = gTeam[playerid];
    GangZoneStopFlashForAll(Zone[CAPZONE]);
    //==========================================================================
    if(gTeam[playerid] == USA)
    {
       GangZoneShowForAll(Zone[CAPZONE], TEAM1_COLOR);
    }
    else if(gTeam[playerid] == CHINA)
    {
    GangZoneShowForAll(Zone[CAPZONE], TEAM2_COLOR);
    }
    //==========================================================================
    new str[128];
    format(str, sizeof(str),"%s has captured the capture zone!", GetName(playerid));
    SendClientMessageToAll(COLOR_ORANGE, str);
    return 1;
}
Well it's pretty simple, if he captures it, he gets some score, and we did a loop to see if a player is in his team, it will give him 1 score.
We also sent a message to everyone saying the player captured the zone.

Now let's make the stock, LeavingCAPZONE.
pawn Code:
stock LeavingCAPZONE(playerid)
{
    Captured[playerid][CAPZONE] = 0;
    UnderAttack[CAPZONE] = 0;
    KillTimer(timer[playerid][CAPZONE]);
    CountVar[playerid][CAPZONE] = 25;
    GangZoneStopFlashForAll(Zone[CAPZONE]);
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
       IsPlayerCapturing[i][CAPZONE] = 0;
    }
    SendClientMessage(playerid, COLOR_RED,"*You have failed to capture this zone!");
    return 1;
}

It's as simple as before, if he leaves the CAPZONE, it stops capturing, and isn't under attack anymore.
The timer stops, and the zone stops flashing.
We made a loop to see who is capturing, and tell him he failed to capture the zone.

Now all left is the timer.
pawn Code:
forward CAPZONETimer(playerid);
public CAPZONETimer(playerid)
{
    CAPZONECaptured(playerid);
    return 1;
}

If you scroll up, you can see a GetName which we will create a stock for.
And here it is:
pawn Code:
stock GetName(playerid)
{
 new pnameid[24];
 GetPlayerName(playerid,pnameid,24);
 return pnameid;
}

One last thing, in case you got an error on "Undefined symbol ""GivePlayerScore"" ", we will create a stock on that to define what it is supposed to do:
Simply add the following:
pawn Code:
stock GivePlayerScore(playerid, score) // creating our stock
{
SetPlayerScore(playerid, GetPlayerScore(playerid) + score); // we're defining it as it will SetPlayerScore, since it's not known like GivePlayerMoney, there is just SetPlayerScore for the scores.
return 1;
}
I guess we're done! Hope I helped you guys, it took me ALOT of time to do this tutorial.
I hope I get some positive feedback, if you encounter any bug or see any mistake in the script, or got any questions, do not hesitate to post!
Thank you for reading!

Last edited by JimmyCh; 04/08/2013 at 08:50 PM.
JimmyCh is offline   Reply With Quote
Old 23/07/2013, 02:48 PM   #2
Nofear192
Guest
 
Posts: n/a
Default Re: How to make Capture Zones!

Nice Job bro ;]
  Reply With Quote
Old 23/07/2013, 02:49 PM   #3
Blademaster680
Gangsta
 
Blademaster680's Avatar
 
Join Date: Jul 2013
Location: On my Yamaha R6
Posts: 606
Reputation: 26
Thumbs up Re: How to make Capture Zones!

Welldone Jimmy
Blademaster680 is offline   Reply With Quote
Old 23/07/2013, 02:51 PM   #4
JimmyCh
Gangsta
 
JimmyCh's Avatar
 
Join Date: Mar 2013
Location: LB
Posts: 656
Reputation: 62
Default Re: How to make Capture Zones!

Thank you guys
__________________

Left SA-MP, you can always find me on Steam playing CS:GO though
http://steamcommunity.com/profiles/76561198173703259/ OR
http://steamcommunity.com/id/grizzlyjim/
Skype: jimmycherfan
JimmyCh is offline   Reply With Quote
Old 23/07/2013, 02:53 PM   #5
Mckarlis
Gangsta
 
Mckarlis's Avatar
 
Join Date: Jun 2013
Location: England
Posts: 726
Reputation: 86
Default Re: How to make Capture Zones!

Thanks this is really good +REP
__________________
Check out my youtube channel!!!! TGMotionz




Mckarlis is offline   Reply With Quote
Old 23/07/2013, 03:27 PM   #6
JimmyCh
Gangsta
 
JimmyCh's Avatar
 
Join Date: Mar 2013
Location: LB
Posts: 656
Reputation: 62
Default Re: How to make Capture Zones!

Thank you Karlis
__________________

Left SA-MP, you can always find me on Steam playing CS:GO though
http://steamcommunity.com/profiles/76561198173703259/ OR
http://steamcommunity.com/id/grizzlyjim/
Skype: jimmycherfan
JimmyCh is offline   Reply With Quote
Old 23/07/2013, 03:44 PM   #7
Necip
Huge Clucker
 
Necip's Avatar
 
Join Date: May 2011
Posts: 334
Reputation: 25
Default Re: How to make Capture Zones!

Such a nice tutorial.Explained and helpful.Gave you a +REP.
__________________


Necip is offline   Reply With Quote
Old 23/07/2013, 03:48 PM   #8
JimmyCh
Gangsta
 
JimmyCh's Avatar
 
Join Date: Mar 2013
Location: LB
Posts: 656
Reputation: 62
Default Re: How to make Capture Zones!

Thank you Necip for your comment
__________________

Left SA-MP, you can always find me on Steam playing CS:GO though
http://steamcommunity.com/profiles/76561198173703259/ OR
http://steamcommunity.com/id/grizzlyjim/
Skype: jimmycherfan
JimmyCh is offline   Reply With Quote
Old 23/07/2013, 07:31 PM   #9
Areax
Huge Clucker
 
Areax's Avatar
 
Join Date: Mar 2013
Location: Slovenia
Posts: 464
Reputation: 14
Default Re: How to make Capture Zones!

Thank you for this NICE tutorial! REP+
Areax is offline   Reply With Quote
Old 23/07/2013, 07:59 PM   #10
JimmyCh
Gangsta
 
JimmyCh's Avatar
 
Join Date: Mar 2013
Location: LB
Posts: 656
Reputation: 62
Default Re: How to make Capture Zones!

Thank you for your feedback! If you guys need more tutorials, I have nothing to do and looking for ideas!
__________________

Left SA-MP, you can always find me on Steam playing CS:GO though
http://steamcommunity.com/profiles/76561198173703259/ OR
http://steamcommunity.com/id/grizzlyjim/
Skype: jimmycherfan
JimmyCh 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
[HELP]: How to make capture zones! Areax Scripting Help 4 16/06/2013 12:30 PM
Capture zones the_zohan Scripting Help 6 01/02/2013 06:08 PM
How do I make capture zones Eminem 2ka9 Scripting Help 0 25/10/2012 09:03 PM
How do I make capture zones Eminem 2ka9 Scripting Help 2 10/08/2012 04:17 PM
How can i make capture zones with timer? Admigo Help Archive 1 20/08/2011 01:12 PM


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


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