[NEED]Quick Help in Capture Zone REP+ -
HydraHumza - 11.07.2015
Hello Forum SA-MP Members
I am facing a small problem in my capture zone that 2 player can capture 1 zone at once i want to do that 1 player can capture at once but the problem is that 2 player stand in zone and the timer start and it capture by twice please help me REP+ who help me to fix that problem
Код:
#include <a_samp>
#include <streamer>
#define SNAKE 0 //Snakes farm
public OnGameModeInit()
{
tCP[SNAKE] = TEAM_NONE;
UnderAttack[SNAKE] = 0;
CP[SNAKE] = CreateDynamicCP(-36.5458, 2347.6426, 24.1406,3, -1,-1,-1,100.0);
Zone[SNAKE] = GangZoneCreate(-62.5000000000005,2318.359375,23.4375,2390.625);
return 1;
}
public OnPlayerConnect(playerid)
{
IsPlayerCapturing[playerid][SNAKE] = 0;
CountVar[playerid][SNAKE] = 25;
if(tCP[SNAKE] == TEAM_NONE) GangZoneShowForPlayer(playerid,Zone[SNAKE], ZONE_WHITE);
else if(tCP[SNAKE] == TEAM_EURASIA) GangZoneShowForPlayer(playerid,Zone[SNAKE], TEAM_ZONE_EURASIA_COLOR);
else if(tCP[SNAKE] == TEAM_ARAB) GangZoneShowForPlayer(playerid,Zone[SNAKE], TEAM_ZONE_ARAB_COLOR);
else if(tCP[SNAKE] == TEAM_USA) GangZoneShowForPlayer(playerid,Zone[SNAKE], TEAM_ZONE_USA_COLOR);
else if(tCP[SNAKE] == TEAM_AUS) GangZoneShowForPlayer(playerid,Zone[SNAKE], TEAM_ZONE_AUS_COLOR);
else if(tCP[SNAKE] == TEAM_SOVIET) GangZoneShowForPlayer(playerid,Zone[SNAKE], TEAM_ZONE_SOVIET_COLOR);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
if(Captured[playerid][SNAKE] == 0 && IsPlayerCapturing[playerid][SNAKE] == 1)
{
LeavingSnakeFarm(playerid);
}
return 1;
}
public OnPlayerSpawn(playerid)
{
if(Captured[playerid][SNAKE] == 0 && IsPlayerCapturing[playerid][SNAKE] == 1 && IsPlayerInDynamicCP(playerid, CP[SNAKE]))
{
LeavingSnakeFarm(playerid);
}
return 1;
}
//================================CAPTURE ZONES=================================
stock CaptureZoneMessage(playerid, messageid)
{
switch(messageid)
{
case 1:
{
SendClientMessage(playerid, dred,"*You cannot capture while in vehicle!");
}
case 2:
{
SendClientMessage(playerid, dred,"*This zone is already being taken over!");
}
case 3:
{
SendClientMessage(playerid, dred,"*Admins on-duty Cannot capture areas.");
}
}
return 1;
}
//===============SNAKE FARMS====================================================
stock ActiveSnakeFarm(playerid)
{
if(Spectating[playerid] == 0 && PlayerInfo[playerid][OnDuty] == 0 && gTeam[playerid] != TEAM_MERC)
{
if(UnderAttack[SNAKE] == 0)
{
if(!IsPlayerInAnyVehicle(playerid))
{
UnderAttack[SNAKE] = 1;
timer[playerid][SNAKE] = SetTimerEx("SnakeFarm", 25000, false,"i",playerid);
Captured[playerid][SNAKE] = 0;
SendClientMessage(playerid, 0xFFFFFFFF,"| - Stay in this checkpoint for 25 seconds to capture! - |");
if(gTeam[playerid] == TEAM_EURASIA)
{
GangZoneFlashForAll(Zone[SNAKE], TEAM_ZONE_EURASIA_COLOR);
}
else if(gTeam[playerid] == TEAM_ARAB)
{
GangZoneFlashForAll(Zone[SNAKE], TEAM_ZONE_ARAB_COLOR);
}
else if(gTeam[playerid] == TEAM_SOVIET)
{
GangZoneFlashForAll(Zone[SNAKE], TEAM_ZONE_SOVIET_COLOR);
}
else if(gTeam[playerid] == TEAM_USA)
{
GangZoneFlashForAll(Zone[SNAKE], TEAM_ZONE_USA_COLOR);
}
else if(gTeam[playerid] == TEAM_AUS)
{
GangZoneFlashForAll(Zone[SNAKE], TEAM_ZONE_AUS_COLOR);
}
//------Message-----
if(tCP[SNAKE] == TEAM_EURASIA)
{
SendClientMessage(playerid, COLOR_WHITE,"This flag is controlled by team "COL_RED"<EURASIA>");
SendTeamMessage(TEAM_EURASIA, green,"*Snakes Farm is under attack!");
}
else if(tCP[SNAKE] == TEAM_ARAB)
{
SendClientMessage(playerid, COLOR_WHITE,"This flag is controlled by team "COL_RED"<ARAB>");
SendTeamMessage(TEAM_ARAB, green,"*Snakes Farm is under attack!");
}
else if(tCP[SNAKE] == TEAM_SOVIET)
{
SendClientMessage(playerid, COLOR_WHITE,"This flag is controlled by team "COL_RED"<SOVIET>");
SendTeamMessage(TEAM_SOVIET, green,"*Snakes Farm is under attack!");
}
else if(tCP[SNAKE] == TEAM_USA)
{
SendClientMessage(playerid, COLOR_WHITE,"This flag is controlled by team "COL_RED"<USA>");
SendTeamMessage(TEAM_USA, green,"*Snakes Farm is under attack!");
}
else if(tCP[SNAKE] == TEAM_AUS)
{
SendClientMessage(playerid, COLOR_WHITE,"This flag is controlled by team "COL_RED"<AUSTRALIA>");
SendTeamMessage(TEAM_AUS, green,"*Snakes Farm is under attack!");
}
else if(tCP[SNAKE] == TEAM_NONE)
{
SendClientMessage(playerid, COLOR_WHITE,"This flag is not controlled by any team");
}
//---------loop-------//
for(new i = 0; i < MAX_PLAYERS; i ++)
{
IsPlayerCapturing[i][SNAKE] = 1;
}
}
else return CaptureZoneMessage(playerid, 1);
}
else return CaptureZoneMessage(playerid, 2);
}
else return CaptureZoneMessage(playerid, 3);
return 1;
}
stock SnakeFarmCaptured(playerid)
{
Captured[playerid][SNAKE] = 1;
UnderAttack[SNAKE] = 0;
KillTimer(timer[playerid][SNAKE]);
CountVar[playerid][SNAKE] = 25;
GivePlayerScore(playerid, 3);
GivePlayerMoney(playerid, 2000);
new str[128];
Savestatus(playerid);
TextStats(playerid);
SendClientMessage(playerid,yellow,"*You have earned +$2000 and +3 score from this zone.");
//==========================================================================
for(new i = 0; i < MAX_PLAYERS; i++)
{
IsPlayerCapturing[i][SNAKE] = 0;
if(gTeam[i] == gTeam[playerid] && i != playerid && PlayerInfo[i][OnDuty] == 0)
{
SendClientMessage(i, 0xFFFFFFFF,"*Your team has captured "cred"Snakes farm"cwhite"! You received +1 score for it!");
GivePlayerScore(i, 1);
}
}
//==========================================================================
tCP[SNAKE] = gTeam[playerid];
GangZoneStopFlashForAll(Zone[SNAKE]);
//==========================================================================
if(gTeam[playerid] == TEAM_EURASIA)
{
GangZoneShowForAll(Zone[SNAKE], TEAM_ZONE_EURASIA_COLOR);
}
else if(gTeam[playerid] == TEAM_ARAB)
{
GangZoneShowForAll(Zone[SNAKE], TEAM_ZONE_ARAB_COLOR);
}
else if(gTeam[playerid] == TEAM_SOVIET)
{
GangZoneShowForAll(Zone[SNAKE], TEAM_ZONE_SOVIET_COLOR);
}
else if(gTeam[playerid] == TEAM_USA)
{
GangZoneShowForAll(Zone[SNAKE], TEAM_ZONE_USA_COLOR);
}
else if(gTeam[playerid] == TEAM_AUS)
{
GangZoneShowForAll(Zone[SNAKE], TEAM_ZONE_AUS_COLOR);
}
//==========================================================================
format(str, sizeof(str),"~w~%s has captured ~b~~h~Snakes Farm ~w~for team %s", pName(playerid), GetTeamName(playerid));
SendBoxMessage(str);
return 1;
}
stock LeavingSnakeFarm(playerid)
{
if(IsPlayerCapturing[playerid][SNAKE] == 1) {
Captured[playerid][SNAKE] = 1;
UnderAttack[SNAKE] = 0;
KillTimer(timer[playerid][SNAKE]);
CountVar[playerid][SNAKE] = 25;
SendClientMessage(playerid, white,"*You have Failed to Capture this Zone.");
GangZoneStopFlashForAll(Zone[SNAKE]);
} else return 0;
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerCapturing[i][SNAKE] == 1) return 0;
else IsPlayerCapturing[i][SNAKE] = 0;
}
return 1;
}
forward SnakeFarm(playerid);
public SnakeFarm(playerid)
{
SnakeFarmCaptured(playerid);
return 1;
}
public OnPlayerEnterDynamicCP(playerid, checkpointid)
{
if(checkpointid == CP[SNAKE])
{
if(Spectating[playerid] == 0) {
if(UnderAttack[SNAKE] == 0) {
if(PlayerInfo[playerid][OnDuty] == 0) {
if(tCP[SNAKE] != gTeam[playerid]) {
if(gTeam[playerid] != TEAM_MERC) {
CountVar[playerid][SNAKE] = 25;
ActiveSnakeFarm(playerid);
} else return SendClientMessage(playerid, red,"*Mercenary team cannot capture zones");
} else return SendClientMessage(playerid, -1,"*This zone is controlled by your team!");
} else return CaptureZoneMessage(playerid, 3);
} else return CaptureZoneMessage(playerid, 2);
} else return 0;
}
return 1;
}
public OnPlayerLeaveDynamicCP(playerid, checkpointid)
{
if(checkpointid == CP[SNAKE] && Captured[playerid][SNAKE] == 0 && IsPlayerCapturing[playerid][SNAKE] == 1 && !IsPlayerInDynamicCP(playerid, CP[SNAKE]))
{
LeavingSnakeFarm(playerid);
}
return 1;
}
Re: [NEED]Quick Help in Capture Zone REP+ -
Moudix - 11.07.2015
check this tutorial :
https://sampforum.blast.hk/showthread.php?tid=453013
on top :
PHP код:
new UnderAttack[30] = 0;
GameModeInit:
PHP код:
UnderAttack[CAPZONE] = 0;
PHP код:
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;
}
At your capture timer add :
PHP код:
UnderAttack[CAPZONE] = 1
And when the capture is done :
PHP код:
UnderAttack[CAPZONE] = 0
if you still got any question , go ahead and ask

.
Re: [NEED]Quick Help in Capture Zone REP+ -
HydraHumza - 11.07.2015
Код:
new tCP[50];
new UnderAttack[50] = 0;
new CP[50];
new Zone[50];
new Captured[MAX_PLAYERS][50];
new UpdateTimer[MAX_PLAYERS];
new timer[MAX_PLAYERS][50];
new CountVar[MAX_PLAYERS][50];
new Text:CountText[MAX_PLAYERS];
new Text:CountText2[MAX_PLAYERS];
new IsPlayerCapturing[MAX_PLAYERS][50];
i already defiend that sorry i didn't mention in my post
Re: [NEED]Quick Help in Capture Zone REP+ -
Moudix - 11.07.2015
hmm, so OnPlayerEnterDynamicCP :
PHP код:
if(UnderAttack[yourzonehere] == 1) return SendClientMessage(playerid, COLOR_RED, "This Zone is already being taken over!");
else
{
UnderAttack[yourzonehere] = 1;
}
OnPlayerLeaveDynamicCP:
PHP код:
UnderAttack[yourzonehere] = 0;
And when the timer ends :
PHP код:
UnderAttack[yourzonehere] = 0;
Re: [NEED]Quick Help in Capture Zone REP+ -
HydraHumza - 11.07.2015
i am getting this error for now in zone
This Zone is already being taken over!
Re: [NEED]Quick Help in Capture Zone REP+ -
Moudix - 11.07.2015
Oh well i've made a mistake above..
OnPlayerEnterDynamicCP :
PHP код:
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;
}
OnPlayerLeaveDynamicCP :
PHP код:
UnderAttack[Zone] = 0;
KillTimer(timer[playerid][Zone]);
GangZoneStopFlashForAll(Zone[Zone]);
This anywhere but not under a callback :
PHP код:
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;
}
PHP код:
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;
}
Also those on top :
PHP код:
new tCheck[30];
new zDefine[MAX_PLAYERS];
new UnderAttack[30];
new timer[MAX_PLAYERS][30];
Feel free to Add or Edit whatever you like so the codes fit with your system.
Re: [NEED]Quick Help in Capture Zone REP+ -
HydraHumza - 11.07.2015
new zDefine[MAX_PLAYERS]; can i know why this is we using??
Re: [NEED]Quick Help in Capture Zone REP+ -
Moudix - 11.07.2015
used to check the zone color etc..
https://sampforum.blast.hk/showthread.php?tid=370571
Here's a tutorial.
Re: [NEED]Quick Help in Capture Zone REP+ -
HydraHumza - 11.07.2015
I am using same thing as it mention but won't help me at all
Re : [NEED]Quick Help in Capture Zone REP+ -
KillerDVX - 12.07.2015
Use foreach as a loop, it's more faster.