SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 09/12/2017, 10:01 AM   #41
Psycho96
Little Clucker
 
Join Date: Nov 2017
Posts: 28
Reputation: 2
Default Re: [New] How to make capture zone system (no more code repeating)

Quote:
Originally Posted by Gammix View Post
You did some changes to the original code, looks like. Might be something you are doing wrong, can't tell from the code you provided.

But before changing anything, you should put and trst the origibal code first. See if there's any bugs and if so report them. Let me know.
I just fixed it, I forgot to check if the base is already captured by a guild..

PHP Code:
if(!strcmp(GetClanName(_Info[playerid][pClan]), _bInfo[i][ConquistedBy], false)) return SendClientMessage(playeridCOLOR_TOMATO"This zone is already yours."); 
I'll test all the system to catch bugs.
Regards, and thanks for the tutorial.
Psycho96 is offline   Reply With Quote
Old 24/05/2018, 06:48 PM   #42
Vizi10
Little Clucker
 
Join Date: May 2017
Posts: 17
Reputation: 0
Default Re: [New] How to make capture zone system (no more code repeating)

Do not show checkpoints.
what's wrong?
PHP Code:
#include <a_samp>
#include <progress2>
#include <streamer>


#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
    print(
"\n--------------------------------------");
    print(
" Blank Filterscript by your name here");
    print(
"--------------------------------------\n");
    return 
1;
}

public 
OnFilterScriptExit()
{
    return 
1;
}

#else
#endif

#pragma tabsize 0
#define CAPTURE_TIME 30 // how many seconds to capture a zone
#define COLOR_TOMATO \
    
0xFF6347FF
#define COLOR_GREEN \
    
0x00FF00FF
#define ALPHA(%1,%2) \
    
((%& ~0xFF) | clamp(%20x000xFF))
new 
PlayerText:capturePlayerTextDraw[MAX_PLAYERS];
new 
PlayerBar:capturePlayerBar[MAX_PLAYERS];
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}
};
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}, {-301.44551522.854979.0056}, 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
};

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;
}

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;
}


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;
}

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;
}

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;
}

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;
}

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;
}

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;

Vizi10 is offline   Reply With Quote
Old 11/06/2018, 04:48 AM   #43
Shadow0707
Big Clucker
 
Join Date: Sep 2016
Location: My Mothers House
Posts: 73
Reputation: 2
Default Re: [New] How to make capture zone system (no more code repeating)

PHP Code:
{"Lost Airport", {-3324224462564}, {416.51282450.194616.5000}, 0
what's wrong ? I got tag mismatch


EDIT: Fixed I just need to add .0 :3
__________________
I'm not a boss but I live like a boss
Shadow0707 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] Capture zone dieegov Scripting Help 0 15/07/2013 10:22 PM
Capture Zone [HELP] [REP+] Pravin Scripting Help 0 02/08/2012 04:11 PM
Lots of errors with zone capture system stormchaser206 Scripting Help 16 15/07/2012 07:11 PM
Capture Zone [WTF]Godfather Scripting Help 4 17/05/2012 05:10 AM
Make This Zone Code Takable? <Weponz> Help Archive 0 25/10/2010 12:59 PM


All times are GMT. The time now is 02:21 AM.


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