SA-MP Forums Archive
[Tutorial] [New] How to make capture zone system (no more code repeating) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] [New] How to make capture zone system (no more code repeating) (/showthread.php?tid=586587)

Pages: 1 2


[New] How to make capture zone system (no more code repeating) - Gammix - 23.08.2015


Capture Zone Tutorial
Make capturable zone in one line - checkpoint based captures
Last Updated: 12 Sept, 2017
Features:
What makes this different and better from other tutorials/methods used in gamemodes, mostly COD named: Step1: Required Libraries
progress2.inc - https://sampforum.blast.hk/showthread.php?tid=629401
streamer.inc (.dll/.so too) - https://sampforum.blast.hk/showthread.php?tid=102865

After you install them correctly, if you haven't. Now you have to include them in your script:
PHP код:
#include <progress2>
#include <streamer> 
Step2: Constants
Now we will declare our constants on the very top so its easier to modify in-game related changes easily.
We are using enumerator, you can use define statement if you want, Doesn't matter.
PHP код:
#define CAPTURE_TIME 30 // how many seconds to capture a zone 
And now we will add two colors we will be using for client messages:
PHP код:
#define COLOR_TOMATO \
    
0xFF6347FF
#define COLOR_GREEN \
    
0x00FF00FF 
COLOR_TOMATO - For warning messages
COLOR_GREEN - For success messages

Step3: Function(s)
This is a small one, we just need this function/macro to adjust alpha values of our colors so we don't rely on the colors user specify in our "TEAM" array. We basically require this for making opacity of gangzone color not full (255/FF).

So add this after the colors constants:
PHP код:
#define ALPHA(%1,%2) \
    
((%& ~0xFF) | clamp(%20x000xFF)) 
Step4: Variables/Arrays
This one needs a little attention.

Team Array:
So first of all, we will make an enumerator-array for our Teams data, we just need the team names and colors so we can use them for information while flashing a gangzone and capture messages.

Since we don't need to change anything in the array, we simply make it constant:
PHP код:
enum E_TEAM
{
    
bool:E_TEAM_VALID,
    
E_TEAM_NAME[32],
    
E_TEAM_COLOR
};
new const 
TEAM[][E_TEAM] =
{
    {
true"team 1"0xFF0000FF}, // the color's opacity doesn't matter, we will use the function "ALPHA" to change it later
    
{true"team 2"0x00FF00FF}
}; 
Now, as you can see 3 elements are made. Now how this array indexing system i made works is based on the first element:
E_TEAM_VALID: This is basically for those scripts whose teamid are not reliable to array indexes. So lets say you are Team:0 but when your team is set by "SetPlayerTeam", the id there used is 10, so my script will use 10 as an index for the array declared below "TEAM", but the array size is 2, so for that case we use this element, you have to do a bit hardwork here, you have to make 8 more entries in array, all empty but the 10th team with its data included. So it will look like this:

PHP код:
new const TEAM[][E_TEAM] =
{
    {
true"team 1"0xFF0000FF}, // the color's opacity doesn't matter, we will use the function "ALPHA" to change it later
    
{true"team 2"0x00FF00FF},
    {},
    {},
    {},
    {},
    {},
    {},
    {},
    {
true"team 10"0x0000FFFF// this is the "SetPlayerTeam(playerid, 10)" entry
}; 
Capture Array:
Similar to TEAM array but this time its name is not in Caps, which means its not a constant, yes we need to make changes to this array later on in script.

PHP код:
enum E_CAPTURE_ZONE
{
    
E_CAPTURE_ZONE_NAME[64],
    
Float:E_CAPTURE_ZONE_GANGZONE_OFFSET[4], // the capture zone's gangzone minx/y and maxx/y
    
Float:E_CAPTURE_ZONE_CP_OFFSET[3], // the x,y,z offset for the checkpoint the players will stay in and capture
    
E_CAPTURE_ZONE_OWNER,
    
E_CAPTURE_ZONE_ATTACKER,
    
E_CAPTURE_ZONE_COUNTDOWN,
    
E_CAPTURE_ZONE_GANGZONE,
    
E_CAPTURE_ZONE_CP,
    
E_CAPTURE_ZONE_AREA,
    
E_CAPTURE_ZONE_TIMER,
    
E_CAPTURE_ZONE_PLAYERS_IN_ZONE
};
new 
captureZone[][E_CAPTURE_ZONE] =
{
    {
"Big Ear", {-437.51513.671875, -244.1406251636.71875}, {-311.01361542.973375.5625}, 0},
    {
"Area 51", {-46.8751697.265625423.8281252115.234375}, {254.45921802.89977.4285}, 1// "1" means the zone owner will be "team 2", notice the number relates to array "TEAM"'s indexes
}; 
As you know by know you can add as many Teams you want, same is here. And you don't need to worry about indexes as well, since we are not using them anywhere importantly, i mean the symmetry doesn't matter.

For example: if i need to add a new zone, i simply do...
PHP код:
new captureZone[][E_CAPTURE_ZONE] =
{
    {
"Big Ear", {-437.51513.671875, -244.1406251636.71875}, {-311.01361542.973375.5625}, 0},
    {
"Area 51", {-46.8751697.265625423.8281252115.234375}, {254.45921802.89977.4285}, 1}, // "1" means the zone owner will be "team 2", notice the number relates to array "TEAM"'s indexes
    
{"New zone", {0.00.00.00.0}, {0.00.00.0}, 10}, // the new zone
}; 
About the syntax:
PHP код:
{"zone name", {minxminymaxxmaxy}, {cpxcpycpz}, owner_team_index
Others:
Lastly we need two player variables to store PlayerProgressBar and PlayerTextDraw ids:
PHP код:
new PlayerText:capturePlayerTextDraw[MAX_PLAYERS];
new 
PlayerBar:capturePlayerBar[MAX_PLAYERS]; 
Step5: Initializing
If you are using filterscript use: OnFilterScriptInit
PHP код:
public OnGameModeInit()
{
    for (new 
isizeof captureZonei++)
    {
        
captureZone[i][E_CAPTURE_ZONE_ATTACKER] = INVALID_PLAYER_ID// set the zone attacker to none
        
captureZone[i][E_CAPTURE_ZONE_COUNTDOWN] = 0;
        
captureZone[i][E_CAPTURE_ZONE_GANGZONE] = GangZoneCreate(captureZone[i][E_CAPTURE_ZONE_GANGZONE_OFFSET][0], captureZone[i][E_CAPTURE_ZONE_GANGZONE_OFFSET][1], captureZone[i][E_CAPTURE_ZONE_GANGZONE_OFFSET][2], captureZone[i][E_CAPTURE_ZONE_GANGZONE_OFFSET][3]);
        
captureZone[i][E_CAPTURE_ZONE_CP] = CreateDynamicCP(captureZone[i][E_CAPTURE_ZONE_CP_OFFSET][0], captureZone[i][E_CAPTURE_ZONE_CP_OFFSET][1], captureZone[i][E_CAPTURE_ZONE_CP_OFFSET][2], 1.0);
        
captureZone[i][E_CAPTURE_ZONE_AREA] = CreateDynamicRectangle(captureZone[i][E_CAPTURE_ZONE_GANGZONE_OFFSET][0], captureZone[i][E_CAPTURE_ZONE_GANGZONE_OFFSET][1], captureZone[i][E_CAPTURE_ZONE_GANGZONE_OFFSET][2], captureZone[i][E_CAPTURE_ZONE_GANGZONE_OFFSET][3]);
    }
    return 
1;

Its pretty self explanatory!

Now initializing when a player connect, i.e. creating textdraw and progress bar:
PHP код:
public OnPlayerConnect(playerid)
{
    
capturePlayerBar[playerid] = CreatePlayerProgressBar(playerid44.000000318.00000089.5000003.700000, -1429936641CAPTURE_TIME0);
    
capturePlayerTextDraw[playerid] = CreatePlayerTextDraw(playerid87.000000308.000000"Capturing !...");
    
PlayerTextDrawBackgroundColor(playeridcapturePlayerTextDraw[playerid], 255);
    
PlayerTextDrawFont(playeridcapturePlayerTextDraw[playerid], 1);
    
PlayerTextDrawLetterSize(playeridcapturePlayerTextDraw[playerid], 0.2900001.099999);
    
PlayerTextDrawColor(playeridcapturePlayerTextDraw[playerid], -1);
    
PlayerTextDrawAlignment(playeridcapturePlayerTextDraw[playerid], 2);
    
PlayerTextDrawSetOutline(playeridcapturePlayerTextDraw[playerid], 1);
    return 
1;

Step6: Showing ganzones
So here we loop through the array "captureZone" and show gangzone to player.

In the second part we see if the gangzone is under attack, if it is then flash it for player with the attacker's team color.
PHP код:
public OnPlayerSpawn(playerid)
{
    for (new 
isizeof captureZonei++)
    {
        
// show gangzones
        
GangZoneShowForPlayer(playeridcaptureZone[i][E_CAPTURE_ZONE_GANGZONE], ALPHA(TEAM[captureZone[i][E_CAPTURE_ZONE_OWNER]][E_TEAM_COLOR], 100));
        
// flash gangzone if under attack
        
if (captureZone[i][E_CAPTURE_ZONE_ATTACKER] != INVALID_PLAYER_ID)
        {
            
GangZoneFlashForPlayer(playeridcaptureZone[i][E_CAPTURE_ZONE_GANGZONE], ALPHA(TEAM[GetPlayerTeam(captureZone[i][E_CAPTURE_ZONE_ATTACKER])][E_TEAM_COLOR], 100));
        }
    }
    return 
1;

Step7: Showing gangzone name (Optional)
This callback is called when you enter a dynamic area created through streamer plugin. So if you noticed in Initializing step, we made a DynamicRectangle exactly to the coordinates of our capture zones. So each gangzone have its own dynamic area too. So now we can use it to detect if a player enters that zone and we simply show him the zone name as a GameText!

PHP код:
public OnPlayerEnterDynamicArea(playeridareaid)
{
    for (new 
isizeof captureZonei++)
    {
        if (
areaid == captureZone[i][E_CAPTURE_ZONE_AREA]) // matches the player area to the gangzone area
        
{
            new 
string[64 3];
            
format(stringsizeof string"~w~%s"captureZone[i][E_CAPTURE_ZONE_NAME]);
            
GameTextForPlayer(playeridstring50006);
            return 
1;
        }
    }
    return 
1;

Step8: Capturing A Zone
Similar to dynamic areas, when a player enteres a dynamic checkpoint, this callback is called. And so it goes:
PHP код:
public OnPlayerEnterDynamicCP(playeridcheckpointid)
{
    for (new 
isizeof captureZonei++)
    {
        if (
checkpointid == captureZone[i][E_CAPTURE_ZONE_CP]) // player entered checkpoint of the gangzone
        
{
            if (
IsPlayerInAnyVehicle(playerid)) // this little check disallows the player to capture in a vehicle
            
{
                
SendClientMessage(playeridCOLOR_TOMATO"You cannot capture a zone in a vehicle.");
                return 
1;
            }
            
            if (
captureZone[i][E_CAPTURE_ZONE_ATTACKER] == INVALID_PLAYER_ID// this check tells us that gangzone is not under attack so we can proceed with start attacking here!
            
{
                if ((
GetPlayerTeam(playerid) >= && GetPlayerTeam(playerid) < sizeof TEAM) && TEAM[GetPlayerTeam(playerid)][E_TEAM_VALID] && GetPlayerTeam(playerid) != captureZone[i][E_CAPTURE_ZONE_OWNER]) // here the team ids play its role, we check the index is valid - The second part is if whether the player isn't of team that zone owner is 
                
{
                    
captureZone[i][E_CAPTURE_ZONE_ATTACKER] = playerid;
                    
captureZone[i][E_CAPTURE_ZONE_PLAYERS_IN_ZONE] = 1;
                    
captureZone[i][E_CAPTURE_ZONE_COUNTDOWN] = 0;
                    
KillTimer(captureZone[i][E_CAPTURE_ZONE_TIMER]);
                    
captureZone[i][E_CAPTURE_ZONE_TIMER] = SetTimerEx("OnCaptureZoneUpdate"1000true"i"i);
                    
// falsh gangzone for all
                    
GangZoneFlashForAll(captureZone[i][E_CAPTURE_ZONE_GANGZONE], ALPHA(TEAM[GetPlayerTeam(playerid)][E_TEAM_COLOR], 100));
                    
                    
// display capture message to player
                    
SendClientMessage(playeridCOLOR_GREEN"Stay in the checkpoint to for "#CAPTURE_TIME" seconds to capture the zone.");
                    
                    // display provocation message to all
                    
new string[150];
                    
format(stringsizeof string"%s is trying to capture %s away from team %s."TEAM[GetPlayerTeam(playerid)][E_TEAM_NAME], captureZone[i][E_CAPTURE_ZONE_NAME], TEAM[captureZone[i][E_CAPTURE_ZONE_OWNER]][E_TEAM_NAME]);
                    
SendClientMessageToAll(COLOR_TOMATOstring);
                }
                else return 
1;
            }
            else if (
GetPlayerTeam(playerid) == GetPlayerTeam(captureZone[i][E_CAPTURE_ZONE_ATTACKER])) // already being captured and player is of the same team that of attacker is
            
{
                
// increase number of players capturing
                
captureZone[i][E_CAPTURE_ZONE_PLAYERS_IN_ZONE]++;
                
SendClientMessage(playeridCOLOR_GREEN"Stay in the checkpoint to assist your teammate in capturing the zone.");
            }
            
// show progress bar and capture textdraw!
            
PlayerTextDrawShow(playeridcapturePlayerTextDraw[playerid]);
            
ShowPlayerProgressBar(playeridcapturePlayerBar[playerid]);
            return 
1;
        }
    }
    return 
1;

Timer:
This is the main part!
PHP код:
forward OnCaptureZoneUpdate(zoneid);
public 
OnCaptureZoneUpdate(zoneid)
{
    
// the zone capture rate depends on the number of players capturing it
    // so if its "1", the capture time taken will be 30s
    // if its "2", the capture time decreases to half i.e. 15s
    // given you set the CAPTURE_TIME to 30
    
captureZone[zoneid][E_CAPTURE_ZONE_COUNTDOWN] += captureZone[zoneid][E_CAPTURE_ZONE_PLAYERS_IN_ZONE];
    new 
string[150];
    
format(stringsizeof string"Capturing Zone In %i..."CAPTURE_TIME captureZone[zoneid][E_CAPTURE_ZONE_COUNTDOWN]);
    
    
// update progress bar and textdraw for all players capturing
    
for (new iGetPlayerPoolSize(); <= ji++)
    {
         if (
IsPlayerInDynamicCP(icaptureZone[zoneid][E_CAPTURE_ZONE_CP]) &&
             !
IsPlayerInAnyVehicle(i) &&
             
GetPlayerTeam(i) == GetPlayerTeam(captureZone[zoneid][E_CAPTURE_ZONE_ATTACKER]))
        {
            
PlayerTextDrawSetString(icapturePlayerTextDraw[i], string);
            
SetPlayerProgressBarValue(icapturePlayerBar[i], captureZone[zoneid][E_CAPTURE_ZONE_COUNTDOWN]);
          }
    }
    
    
// zone has been captured
    
if (captureZone[zoneid][E_CAPTURE_ZONE_COUNTDOWN] > CAPTURE_TIME)
    {
        
GetPlayerName(captureZone[zoneid][E_CAPTURE_ZONE_ATTACKER], stringMAX_PLAYER_NAME);
        
format(stringsizeof string"Good job. You assisted %s to capture %s. +$250"stringcaptureZone[zoneid][E_CAPTURE_ZONE_NAME]);
        for (new 
iGetPlayerPoolSize(); <= ji++)
        {
             if (
IsPlayerInDynamicCP(icaptureZone[zoneid][E_CAPTURE_ZONE_CP]) &&
                 !
IsPlayerInAnyVehicle(i) &&
                 
GetPlayerTeam(i) == GetPlayerTeam(captureZone[zoneid][E_CAPTURE_ZONE_ATTACKER]))
            {
                
PlayerTextDrawHide(icapturePlayerTextDraw[i]);
                
HidePlayerProgressBar(icapturePlayerBar[i]);
                
                
// giving reward to teammates who assisted
                
if (!= captureZone[zoneid][E_CAPTURE_ZONE_ATTACKER])
                {
                    
SendClientMessage(iCOLOR_GREENstring);
                    
GivePlayerMoney(i250);
                }
              }
        }
        
        
// giving reward to the attacker who startd capturing initially
        
SetPlayerScore(captureZone[zoneid][E_CAPTURE_ZONE_ATTACKER], GetPlayerScore(captureZone[zoneid][E_CAPTURE_ZONE_ATTACKER]) + 1);
        
GivePlayerMoney(captureZone[zoneid][E_CAPTURE_ZONE_ATTACKER], 1000);
        
format(stringsizeof string"Good job. You successfully captured %s from %s. +1 Score, +$1000"captureZone[zoneid][E_CAPTURE_ZONE_NAME], TEAM[captureZone[zoneid][E_CAPTURE_ZONE_OWNER]][E_TEAM_NAME]);
        
SendClientMessage(captureZone[zoneid][E_CAPTURE_ZONE_ATTACKER], COLOR_GREENstring);
        
        
// announcing capture to all players
        
format(stringsizeof string"<Capture Zone>: Team %s have captured %s from %s."TEAM[GetPlayerTeam(captureZone[zoneid][E_CAPTURE_ZONE_ATTACKER])][E_TEAM_NAME], captureZone[zoneid][E_CAPTURE_ZONE_NAME], TEAM[captureZone[zoneid][E_CAPTURE_ZONE_OWNER]][E_TEAM_NAME]);
        
SendClientMessageToAll(-1string);
        
// reset capture zone variables and modify Owner to attacker's team id
        
captureZone[zoneid][E_CAPTURE_ZONE_OWNER] = GetPlayerTeam(captureZone[zoneid][E_CAPTURE_ZONE_ATTACKER]);
        
captureZone[zoneid][E_CAPTURE_ZONE_ATTACKER] = INVALID_PLAYER_ID;
          
KillTimer(captureZone[zoneid][E_CAPTURE_ZONE_TIMER]);
        
GangZoneStopFlashForAll(captureZone[zoneid][E_CAPTURE_ZONE_GANGZONE]);
        
GangZoneShowForAll(captureZone[zoneid][E_CAPTURE_ZONE_GANGZONE], ALPHA(TEAM[captureZone[zoneid][E_CAPTURE_ZONE_OWNER]][E_TEAM_COLOR], 100));
    }
     return 
1;

Step9: Canceling Capture
This part is for what happens when a player leaves the capture checkpoint while capturing...
PHP код:
public OnPlayerLeaveDynamicCP(playeridcheckpointid)
{
    for (new 
isizeof captureZonei++)
    {
        if (
checkpointid == captureZone[i][E_CAPTURE_ZONE_CP])
        {
            if (
captureZone[i][E_CAPTURE_ZONE_ATTACKER] != INVALID_PLAYER_ID)
            {
                if (
GetPlayerTeam(playerid) == GetPlayerTeam(captureZone[i][E_CAPTURE_ZONE_ATTACKER]))
                {
                    
// hide progress bar and textdraw
                    
PlayerTextDrawHide(playeridcapturePlayerTextDraw[playerid]);
                    
HidePlayerProgressBar(playeridcapturePlayerBar[playerid]);
            
                    
captureZone[i][E_CAPTURE_ZONE_PLAYERS_IN_ZONE]--;
                    
                    if (
captureZone[i][E_CAPTURE_ZONE_PLAYERS_IN_ZONE] == 0// if there is no one left in capture checkpoint but the zone was still being captured
                    
{
                        
// stop capture and reset it to the team it was before
                        
captureZone[i][E_CAPTURE_ZONE_ATTACKER] = INVALID_PLAYER_ID;
                          
KillTimer(captureZone[i][E_CAPTURE_ZONE_TIMER]);
                        
GangZoneStopFlashForAll(captureZone[i][E_CAPTURE_ZONE_GANGZONE]);
                        
                        
SendClientMessage(playeridCOLOR_TOMATO"You failed to capture the zone. You left the checkpoint before time!");
                    }
                    else 
                    {
                        if (
playerid == captureZone[i][E_CAPTURE_ZONE_ATTACKER]) // if the main player who started capturing initially left
                        
{
                            
// we will select another player who is in capture checkpoint and set him as the main attacker
                            // since attackers recieve bigger reward
                            
for (new xGetPlayerPoolSize(); <= yx++)
                            {
                                 if (
IsPlayerInDynamicCP(xcaptureZone[i][E_CAPTURE_ZONE_CP]) &&
                                     !
IsPlayerInAnyVehicle(x) &&
                                     
GetPlayerTeam(x) == GetPlayerTeam(captureZone[i][E_CAPTURE_ZONE_ATTACKER]))
                                {
                                    
captureZone[i][E_CAPTURE_ZONE_ATTACKER] = x;
                                    
                                    new 
string[150];
                                    
GetPlayerName(playeridstringMAX_PLAYER_NAME);
                                    
format(stringsizeof string"%s is no longer the initial zone attacker. You are now holding that position."string);
                                    
SendClientMessage(xCOLOR_TOMATOstring);
                                    
SendClientMessage(xCOLOR_TOMATO"Stay in checkpoint to finish capture and recieve maximum reward.");
                                    
                                    
GetPlayerName(xstringMAX_PLAYER_NAME);
                                    
format(stringsizeof string"You left the checkpoint before time! You are no longer the initial capturer, %s is!"string);
                                    
SendClientMessage(playeridCOLOR_TOMATOstring);
                                    break;
                                  }
                            }
                        }
                        else
                        {
                            
SendClientMessage(playeridCOLOR_TOMATO"You left the checkpoint before time! You are no longer assisting your teammates in capturing!");
                        }
                    }
                }
            }
        }
    }
    return 
1;

Step10: Exiting
We simply destroy what we made in Initializing step.
Also, if you are using filterscript, use OnFilterScriptExit.
PHP код:
public OnGameModeExit()
{
    for (new 
isizeof captureZonei++)
    {
        
GangZoneDestroy(captureZone[i][E_CAPTURE_ZONE_GANGZONE]);
        
DestroyDynamicCP(captureZone[i][E_CAPTURE_ZONE_CP]);
        
DestroyDynamicArea(captureZone[i][E_CAPTURE_ZONE_AREA]);
    }
    return 
1;

That's it, you are done!
If you have any questions, feel free to ask them here in this thread!



Re: [New] How to make capture zone system (no more code repeating) - Hemeei - 23.08.2015

WOW WOW WOW !! THANK YOU BRO ;_; GUYS!!! THIS IS THE BEST CAPTURE ZONE TUTORIAL EVER !!!

NO MORE CODE REPEATING ONLY ONE LINE TO ADD !


Re: [New] How to make capture zone system (no more code repeating) - Karan007 - 23.08.2015

Thanks, great tutorial.


Re: [New] How to make capture zone system (no more code repeating) - jamesmith12 - 23.08.2015

Nice tutorial bro! Keep it up , gonna use this to my gamemode


Re: [New] How to make capture zone system (no more code repeating) - Hemeei - 23.08.2015

Hi guys this is the error that recently fix by gammix =D for people having this problem too

Quote:

C:\Program Files\GTA San Andreas\gamemodes\codnew.pwn(656) : error 017: undefined symbol "GetPlayerPoolSize"

Get latest SAMP version 0.3.7 (optional R2-1).


Quote:

C:\Program Files\GTA San Andreas\gamemodes\codnew.pwn(253) : warning 213: tag mismatch

Download This : http://pastebin.com/LnT3FXdG


Quote:

C:\Program Files\GTA San Andreas\gamemodes\codnew.pwn(684) : warning 209: function "OnPlayerEnterDynamicCP" should return a value

return 1 in this callback.

and Check some unline codes like this
PHP код:
                  new
        
sBuffer[156]
    ; 
Thanks to gammix!


Re: [New] How to make capture zone system (no more code repeating) - Viki - 23.08.2015

hey man i downloaded ur gamemode it was the best!and i was thinking how you made that bar!now u made a TUT!thanks ALOT


Re: [New] How to make capture zone system (no more code repeating) - Cassy_ - 25.08.2015

Took me so much time to read, nice tutorial.
I would surely use this in my COD server.


Re: [New] How to make capture zone system (no more code repeating) - SEIFOUNE123 - 25.08.2015

nice, but I always prefer to use this one https://sampforum.blast.hk/showthread.php?tid=534999 as it is more easy and explained


Re: [New] How to make capture zone system (no more code repeating) - jamesmith12 - 25.08.2015

nah this one is better than that ^^


Re: [New] How to make capture zone system (no more code repeating) - HydraHumza - 25.08.2015

Really Nice (Y) KEEP IT UP MAN


Re: [New] How to make capture zone system (no more code repeating) - N0FeaR - 13.12.2015

Thanks, i love it!


Re: [New] How to make capture zone system (no more code repeating) - Counterafk - 03.01.2016

Could someone please explain
Code:
new const gCaptureZone[][e_CAPTURE_ZONE] =
{
	{"Big Ear", {-437.5,1513.671875, -244.140625,1636.71875}, {-311.0136,1542.9733,75.5625}, 0},
	{"Area 51", {-46.875,1697.265625, 423.828125,2115.234375}, {254.4592,1802.8997,7.4285}, 1}
};
To me it looks like {X,Y, X,Y} {X,Y, X,Y,?}

Am I supposed to go like this? I'm really lost



Re: [New] How to make capture zone system (no more code repeating) - Gammix - 04.01.2016

Quote:

There are 4 things we need to fill into the array for a new capture zone. These 4 are:
  • Zone name
  • Gangzone coordinate (minx, miny, maxx, maxy)
  • Checkpoint coordinate (x, y, z)
  • The teamid which will be the initial owner of the zone
Here is the syntax:
pawn Code:
{"zone_name", {minx, miny, maxx, maxy}, {cpx, cpy, cpz}, teamid}
{minx, miny, maxx, maxy} for gangzone coordinates.
{cpx, cpy, cpz} for checkpoint coordinates.


Re: [New] How to make capture zone system (no more code repeating) - CrunchxNoy - 04.01.2016

WOW Thanks You Gammix !


Re: [New] How to make capture zone system (no more code repeating) - Counterafk - 04.01.2016

Quote:
Originally Posted by Gammix
View Post
Here is the syntax:
pawn Code:
{"zone_name", {minx, miny, maxx, maxy}, {cpx, cpy, cpz}, teamid}
{minx, miny, maxx, maxy} for gangzone coordinates.
{cpx, cpy, cpz} for checkpoint coordinates.
Wow. Cant believe I missed that in the original post, thanks alot though man!


Re: [New] How to make capture zone system (no more code repeating) - aloveliday - 04.01.2016

Gammix your script looks like awesome but i am very newbie about pawno so i did not understand what you explained about.

Could you complete the blanks with true numbers and names to be more specific?
I mean i need more detail i did not make it.

I just need an example script with fake number and coordinate zone names and other names.Please


Re: [New] How to make capture zone system (no more code repeating) - Gammix - 05.01.2016

Quote:
Originally Posted by aloveliday
View Post
Gammix your script looks like awesome but i am very newbie about pawno so i did not understand what you explained about.

Could you complete the blanks with true numbers and names to be more specific?
I mean i need more detail i did not make it.

I just need an example script with fake number and coordinate zone names and other names.Please
Explanation is given in FAQ. But here i'll try a bit harder.


This array hods team's information. The first param is the team's name and the second is its color.
Syntax:
pawn Code:
{"team_name", team_color}
Example:
pawn Code:
new const gTeamData[][e_TEAM_DATA] =
{
    {"Germany", 0xFFFF90FF}
};
The thing to keep in mind is you use the same index (here "Germany" is at 0) as teamid, so germany should be:
pawn Code:
SetPlayerTeam(playerid, 0);

Secondly, the capture zone array:
You can add as many you want, just take care of the syntax only.
Syntax:
pawn Code:
{"zone_name", {minx, miny, maxx, maxy}, {cpx, cpy, cpz}, zone_owner_team}
Keep in mind that zone_owner_team must be an existing index from gTeamData. Like germany is 0 so if you put 0 as zone_owner_team, then basically you are setting germany as the default owner of the zone.

Example:
pawn Code:
new const gCaptureZone[][e_CAPTURE_ZONE] =
{
    {"Big Ear", {-437.5,1513.671875, -244.140625,1636.71875}, {-311.0136,1542.9733,75.5625}, 0}
};
So we can create our sample (2 teams and 1 capture zone):
pawn Code:
new const gTeamData[][e_TEAM_DATA] =
{
    {"Germany", 0xFFFF90FF},
    {"India", 0xFF90FFFF},
};

new const gCaptureZone[][e_CAPTURE_ZONE] =
{
    {"Big Ear", {-437.5,1513.671875, -244.140625,1636.71875}, {-311.0136,1542.9733,75.5625}, 0}
};
You can also check the Sample(pastebin link) from main page.


Re: [New] How to make capture zone system (no more code repeating) - stormchaser206 - 16.03.2016

How do I make the zone unowned at start?

Thanks!


Re: [New] How to make capture zone system (no more code repeating) - Gammix - 16.03.2016

Quote:
Originally Posted by stormchaser206
View Post
How do I make the zone unowned at start?

Thanks!
Its easy by creating a new team at the last index of your teams array.

Example:
pawn Code:
new const gTeamData[][e_TEAM_DATA] =
{
    {"Germany", 0xFFFF90FF},
    {"India", 0xFF90FFFF},
    {"Unknown Team", 0x505050FF} // This is the last index i.e. 2
};

new const gCaptureZone[][e_CAPTURE_ZONE] =
{
    {"Big Ear", {-437.5,1513.671875, -244.140625,1636.71875}, {-311.0136,1542.9733,75.5625}, 2} // Set the team id to 2
};
But if you don't want the system to print messages for unknown team, just edit the SendClientMessageToAll parts where team names are used.


Re: [New] How to make capture zone system (no more code repeating) - stormchaser206 - 16.03.2016

Quote:
Originally Posted by Gammix
View Post
Its easy by creating a new team at the last index of your teams array.

Example:
pawn Code:
new const gTeamData[][e_TEAM_DATA] =
{
    {"Germany", 0xFFFF90FF},
    {"India", 0xFF90FFFF},
    {"Unknown Team", 0x505050FF} // This is the last index i.e. 2
};

new const gCaptureZone[][e_CAPTURE_ZONE] =
{
    {"Big Ear", {-437.5,1513.671875, -244.140625,1636.71875}, {-311.0136,1542.9733,75.5625}, 2} // Set the team id to 2
};
But if you don't want the system to print messages for unknown team, just edit the SendClientMessageToAll parts where team names are used.
Thanks!

Also, the zone area does not show up for me on the map. Only the flag (when I get near) and the checkpoint. Also, the checkpoint is useless, it doesn't do anything, except send a message saying that it will be captured in 30 seconds. I can wait five minutes and nothing happens.

Code for enum:


OnGamemodeInit


OnPlayerConnect


There is also no progress bar.