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


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

^^ Where is the rest of the code ?


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

I will PM you the script.


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

Quote:

Loaded log file: "server_log.txt".
----------

SA-MP Dedicated Server
----------------------
v0.3.7-R2, ©2005-2015 SA-MP Team

[07:34:36] filterscripts = "" (string)
[07:34:36]
[07:34:36] Server Plugins
[07:34:36] --------------
[07:34:36] Loading plugin: streamer
[07:34:36]

*** Streamer Plugin v2.8.2 by Incognito loaded ***

[07:34:36] Loaded.
[07:34:36] Loading plugin: sscanf
[07:34:36]

[07:34:36] ===============================

[07:34:36] sscanf plugin loaded.

[07:34:36] Version: 2.8.1

[07:34:36] © 2012 Alex "Y_Less" Cole

[07:34:36] ===============================

[07:34:36] Loaded.
[07:34:36] Loading plugin: Whirlpool
[07:34:36]
[07:34:36] ==================
[07:34:36]
[07:34:36] Whirlpool loaded
[07:34:36]
[07:34:36] ==================
[07:34:36]
[07:34:36] Loaded.
[07:34:36] Loading plugin: MapAndreas
[07:34:36] Loaded.
[07:34:36] Loaded 4 plugins.

[07:34:36]
[07:34:36] Filterscripts
[07:34:36] ---------------
[07:34:36] Loaded 0 filterscripts.

[07:34:36] Script[gamemodes/CPTZ.amx]: Run time error 20: "Invalid index parameter (bad entry point)"
[07:34:36] Number of vehicle models: 0

I did everything as it comes in the tutorial and got an error.


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

Quote:
Originally Posted by Yultranions
View Post
I did everything as it comes in the tutorial and got an error.
Add this:

Code:
main( ) { }
https://sampwiki.blast.hk/wiki/Scriptin...tarting_out.21


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

Sorry for bumping, just an simple question

- Is there any bugs or something where i must be carefull by doing such thing. Is this way of doing team and zones still trust worth ? Thanks


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

Quote:
Originally Posted by Hunud
View Post
Sorry for bumping, just an simple question

- Is there any bugs or something where i must be carefull by doing such thing. Is this way of doing team and zones still trust worth ? Thanks
Of course. It has no bugs, none reported and i have been using this in 2 of my popular gamemodes: ww3 and ww4

I would suggest you one thing about the "team array". If you have team data in an array/enum already, then you don't need to create a separate one like this tutorial does. You can use that instead.


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

Quote:
Originally Posted by Gammix
View Post
Of course. It has no bugs, none reported and i have been using this in 2 of my popular gamemodes: ww3 and ww4

I would suggest you one thing about the "team array". If you have team data in an array/enum already, then you don't need to create a separate one like this tutorial does. You can use that instead.
That's what I want to know, thanks a lot .


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

Update: 12 Sept, 2017
- Updated with new gangzones.inc update.
- Refactored code, better naming convention!
- Shorter code!


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

Nice tutorial, I'm trying to do this in my GM, but the problem is when a player get in the CP, doesn't pass for the progress bar string condition, I don't find what's wrong, if someone could help me.. I only can offer +rep XD


This is my OnPlayerEnterDynamicCP:

PHP Code:
public OnPlayerEnterDynamicCP(playeridcheckpointid)
{
    for (new 
0MAX_CONQUIST_BASESi++)
    {
        print(
"a");
        if(!
_bInfo[i][Exists] || checkpointid != _bInfo[i][E_CAPTURE_ZONE_CP]) continue;
        
        print(
"b");
        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;
        }
        print(
"c");
        if (
_bInfo[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!
        
{
            print(
"d");
            if (
_Info[playerid][pClan] > 0// 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
            
{
                print(
"e");
                
_bInfo[i][E_CAPTURE_ZONE_ATTACKER] = playerid;
                
_bInfo[i][E_CAPTURE_ZONE_PLAYERS_IN_ZONE] = 1;
                
_bInfo[i][E_CAPTURE_ZONE_COUNTDOWN] = 0;
                
KillTimer(_bInfo[i][E_CAPTURE_ZONE_TIMER]);
                
_bInfo[i][E_CAPTURE_ZONE_TIMER] = SetTimerEx("OnCaptureZoneUpdate"1000true"i"i);
                
// falsh gangzone for all
                
GangZoneFlashForAll(_bInfo[i][G_SV_ID], 0xFF000085);
                
// display capture message to player
                
SendClientMessage(playeridCOLOR_GREEN"Stay in the checkpoint to for 15 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."GetClanName(_Info[playerid][pClan]), _bInfo[i][BaseName], _bInfo[i][ConquistedBy]);
                
SendClientMessageToAll(COLOR_TOMATOstring);
            }
            else return 
1;
        }
        else if (
_Info[playerid][pClan] == _Info[_bInfo[i][E_CAPTURE_ZONE_ATTACKER]][pClan]) // already being captured and player is of the same team that of attacker is
        
{
            print(
"f");
            
// increase number of players capturing
            
_bInfo[i][E_CAPTURE_ZONE_PLAYERS_IN_ZONE]++;
            
SendClientMessage(playeridCOLOR_GREEN"Stay in the checkpoint to assist your teammate in capturing the zone.");
        }
        print(
"g");
        
// show progress bar and capture textdraw!
        
PlayerTextDrawShow(playeridcapturePlayerTextDraw[playerid]);
        
ShowPlayerProgressBar(playeridcapturePlayerBar[playerid]);
        return 
1;
    }
    return 
1;

And this is the timer callback:

PHP Code:
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
    
_bInfo[zoneid][E_CAPTURE_ZONE_COUNTDOWN] += _bInfo[zoneid][E_CAPTURE_ZONE_PLAYERS_IN_ZONE];
    new 
string[150];
    
format(stringsizeof string"Capturing Zone In %i..."CAPTURE_TIME _bInfo[zoneid][E_CAPTURE_ZONE_COUNTDOWN]);
    
// update progress bar and textdraw for all players capturing
    
for (new iGetPlayerPoolSize(); <= ji++)
    {
        if (
IsPlayerInDynamicCP(i_bInfo[zoneid][G_SV_ID]) && !IsPlayerInAnyVehicle(i))
        {
            
PlayerTextDrawSetString(icapturePlayerTextDraw[i], string);
            
SetPlayerProgressBarValue(icapturePlayerBar[i], _bInfo[zoneid][E_CAPTURE_ZONE_COUNTDOWN]);
        }
    }
    
// zone has been captured
    
if (_bInfo[zoneid][E_CAPTURE_ZONE_COUNTDOWN] > CAPTURE_TIME)
    {
        
GetPlayerName(_bInfo[zoneid][ConquistedBy], stringMAX_PLAYER_NAME);
        
format(stringsizeof string"Good job. You assisted %s to capture %s. +$250"string_bInfo[zoneid][ConquistedBy]);
        for (new 
iGetPlayerPoolSize(); <= ji++)
        {
            if (
IsPlayerInDynamicCP(i_bInfo[zoneid][G_SV_ID]) && !IsPlayerInAnyVehicle(i) && _Info[i][pClan] == _Info[_bInfo[zoneid][E_CAPTURE_ZONE_ATTACKER]][pClan])
               {
                
PlayerTextDrawHide(icapturePlayerTextDraw[i]);
                
HidePlayerProgressBar(icapturePlayerBar[i]);
                
// giving reward to teammates who assisted
                
if (!= _bInfo[zoneid][E_CAPTURE_ZONE_ATTACKER])
                {
                    
SendClientMessage(iCOLOR_GREENstring);
                    
_GiveMoney(i250);
                }
            }
        }
        
// giving reward to the attacker who startd capturing initially
        
_GiveMoney(_bInfo[zoneid][E_CAPTURE_ZONE_ATTACKER], 1000);
        
format(stringsizeof string"Good job. You successfully captured %s from %s. +1 Score, +$1000"_bInfo[zoneid][BaseName], _bInfo[zoneid][ConquistedBy]);
        
SendClientMessage(_bInfo[zoneid][E_CAPTURE_ZONE_ATTACKER], COLOR_GREENstring);
        
// announcing capture to all players
        
format(stringsizeof string"<Capture Zone>: Team %s have captured %s from %s."GetClanName(_Info[_bInfo[zoneid][E_CAPTURE_ZONE_ATTACKER]][pClan]), _bInfo[zoneid][BaseName], _bInfo[zoneid][ConquistedBy]);
        
SendClientMessageToAll(-1string);
        
// reset capture zone variables and modify Owner to attacker's team id
        
_bInfo[zoneid][ConquistedBy][0] = EOS;
        
strcat(_bInfo[zoneid][ConquistedBy], GetClanName(_Info[_bInfo[zoneid][E_CAPTURE_ZONE_ATTACKER]][pClan]), 30);
        new 
query[128];
        
mysql_format(sql_handlequerysizeof(query), "UPDATE `bases` SET `ConquistedBy` = '%e' WHERE `ID` = '%d'"_bInfo[zoneid][ConquistedBy], _bInfo[zoneid][BASE_DB_ID]);
        
mysql_tquery(sql_handlequery);
        
        
_bInfo[zoneid][E_CAPTURE_ZONE_ATTACKER] = INVALID_PLAYER_ID;
        
        
KillTimer(_bInfo[zoneid][E_CAPTURE_ZONE_TIMER]);
        
GangZoneStopFlashForAll(_bInfo[zoneid][G_SV_ID]);
        
GangZoneShowForAll(_bInfo[zoneid][G_SV_ID], -1601993835);
    }
    return 
1;

I tried to print there too (from "a" to "y" passing each condition) and doesn't pass for this one:

PHP Code:
for (new iGetPlayerPoolSize(); <= ji++)
    {
        if (
IsPlayerInDynamicCP(i_bInfo[zoneid][G_SV_ID]) && !IsPlayerInAnyVehicle(i))
        {
            
PlayerTextDrawSetString(icapturePlayerTextDraw[i], string);
            
SetPlayerProgressBarValue(icapturePlayerBar[i], _bInfo[zoneid][E_CAPTURE_ZONE_COUNTDOWN]);
        }
    } 
What can be the fail?

PS. Sorry for my bad english >.<'
Regards!


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

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.