Capture zone problem rep+
#1

How to add countdown when player capturing the zone?

here?
Код:
stock ActiveTown(playerid)
{
        if(UnderAttack[Town] == 0)
        {
            if(!IsPlayerInAnyVehicle(playerid))
            {
                UnderAttack[Town] = 1;
                timer[playerid][Town] = SetTimerEx("TownTimer", 25000, false,"i",playerid);
                Captured[playerid][Town] = 0;
                SendClientMessage(playerid, -1,"| Stay in this checkpoint for {FFFFFF}25 {FFFFFF}seconds {FFFFFF}to capture it! |");
                if(gTeam[playerid] == C1)
                {
                  GangZoneFlashForAll(Zone[Town], COLOR_BLUE);
                }
                else if(gTeam[playerid] == T1)
                {
                  GangZoneFlashForAll(Zone[Town], RED);
                }
                 else if(gTeam[playerid] == BG)
                {
                  GangZoneFlashForAll(Zone[Town], RED);
                }

                //------Message-----
                if(tCP[Town] == C1)
                {
                  SendClientMessage(playerid, C_COLOR,"This flag is controlled by Cops!");
                  SendClientMessageToAll(-1,"{FFFFFF}>{FFFFFF}Old observatory is under attack!");
                }
                else if(tCP[Town] == T1)
                {
                  SendClientMessage(playerid, T_COLOR,"This flag is controlled by Terrorists!");
                  SendClientMessageToAll(-1,"{FFFFFF}>{FFFFFF}Old observatory is under attack!");
                }
				else if(tCP[Town] == BG)
                {
                  SendClientMessage(playerid, T_COLOR,"This flag is controlled by Terrorists!");
                  SendClientMessageToAll(-1,"{FFFFFF}>{FFFFFF}Old observatory is under attack!");
                }
                else if(tCP[Town] == NONE)
                {
                  SendClientMessage(playerid, COLOR_WHITE,"This flag is not controlled by any team!");
                }
                //---------loop-------//
                for(new i = 0; i < MAX_PLAYERS; i ++)
                {
                   IsPlayerCapturing[i][Town] = 1;
                }
            }
            else return CaptureZoneMessage(playerid, 1);
        }
        else {
		 CaptureZoneMessage(playerid, 2);
		 TextDrawHideForPlayer(playerid, CountText[playerid]);
		 }
        return 1;
}

stock TownCaptured(playerid)
{

    Captured[playerid][Town] = 1;
    UnderAttack[Town] = 0;
    KillTimer(timer[playerid][Town]);
    CountVar[playerid][Town] = 25;
    GivePlayerScore(playerid, 5);

    F_GivePlayerMoney(playerid, 5000);
    SendClientMessage(playerid, COLOR_GREEN,"{FFFFFF}Congratulations! You have captured the Old observatory! You received +5 scores and +$5000 cash!");
    //==========================================================================
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
       IsPlayerCapturing[i][Town] = 0;
       if(gTeam[i] == gTeam[playerid])
       {
           SendClientMessage(i, -1,"{FFFFFF}Your team has captured the Old observatory! You received +1 score for it!");
           GivePlayerScore(i, 1);
       }
    }
    //==========================================================================
    tCP[Town] = gTeam[playerid];
    GangZoneStopFlashForAll(Zone[Town]);
    //==========================================================================
    if(gTeam[playerid] == C1)
    {
       GangZoneShowForAll(Zone[Town], COLOR_BLUE);
    }
    else if(gTeam[playerid] == T1)
    {
    GangZoneShowForAll(Zone[Town], RED);
    }
    else if(gTeam[playerid] == BG)
    {
    GangZoneShowForAll(Zone[Town], RED);
    }
    //==========================================================================
    new str[128];
    format(str, sizeof(str),"{39AB2E}%s has captured the Old observatory!", GetName(playerid));
    SendClientMessageToAll(-1, str);
    return 1;
}

stock LeavingTown(playerid)
{
    Captured[playerid][Town] = 0;
    UnderAttack[Town] = 0;
    KillTimer(timer[playerid][Town]);
    CountVar[playerid][Town] = 25;
    GangZoneStopFlashForAll(Zone[Town]);

    for(new i = 0; i < MAX_PLAYERS; i++)
    {
       IsPlayerCapturing[i][Town] = 0;
    }
    SendClientMessage(playerid, COLOR_RED,"*You have failed to capture the Old observatory!");
    return 1;
}

forward TownTimer(playerid);
public TownTimer(playerid)
{
    TownCaptured(playerid);
    return 1;
}

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 F_GivePlayerMoney, there is just SetPlayerScore for the scores.
return 1;
}
Код:
forward CountDown1();
public CountDown1()
{
	foreach(Player, playerid)
	{
		if(IsPlayerInDynamicCP(playerid, CP[CAPZONE]) && UnderAttack[CAPZONE] == 1 && IsPlayerCapturing[playerid][CAPZONE] == 1)
		{
			CountVar[playerid][CAPZONE]--;
			new str1[124];
			TextDrawShowForPlayer(playerid, CountText[playerid]);
			format(str1, sizeof(str1),"~r~%d seconds ~w~left to ~g~capture", CountVar[playerid][CAPZONE]);
			TextDrawSetString(CountText[playerid], str1);
		}
	}
	return 1;
}
Reply
#2

Код:
new ctimer[MAX_PLAYERS];

stock ActiveTown(playerid)
{
        if(UnderAttack[Town] == 0)
        {
            if(!IsPlayerInAnyVehicle(playerid))
            {
                UnderAttack[Town] = 1;
                timer[playerid][Town] = SetTimerEx("TownTimer", 25000, false,"i",playerid);
                Captured[playerid][Town] = 0;
                SendClientMessage(playerid, -1,"| Stay in this checkpoint for {FFFFFF}25 {FFFFFF}seconds {FFFFFF}to capture it! |");
                if(gTeam[playerid] == C1)
                {
                  GangZoneFlashForAll(Zone[Town], COLOR_BLUE);
                }
                else if(gTeam[playerid] == T1)
                {
                  GangZoneFlashForAll(Zone[Town], RED);
                }
                 else if(gTeam[playerid] == BG)
                {
                  GangZoneFlashForAll(Zone[Town], RED);
                }

                //------Message-----
                if(tCP[Town] == C1)
                {
                  SendClientMessage(playerid, C_COLOR,"This flag is controlled by Cops!");
                  SendClientMessageToAll(-1,"{FFFFFF}>{FFFFFF}Old observatory is under attack!");
                }
                else if(tCP[Town] == T1)
                {
                  SendClientMessage(playerid, T_COLOR,"This flag is controlled by Terrorists!");
                  SendClientMessageToAll(-1,"{FFFFFF}>{FFFFFF}Old observatory is under attack!");
                }
				else if(tCP[Town] == BG)
                {
                  SendClientMessage(playerid, T_COLOR,"This flag is controlled by Terrorists!");
                  SendClientMessageToAll(-1,"{FFFFFF}>{FFFFFF}Old observatory is under attack!");
                }
                else if(tCP[Town] == NONE)
                {
                  SendClientMessage(playerid, COLOR_WHITE,"This flag is not controlled by any team!");
                }
                //---------loop-------//
                for(new i = 0; i < MAX_PLAYERS; i ++)
                {
                   IsPlayerCapturing[i][Town] = 1;
                }
                ctimer[playerid] = SetTimerEx("CountDown1", 1000, true, "i", playerid);
            }
            else return CaptureZoneMessage(playerid, 1);
        }
        else {
		 CaptureZoneMessage(playerid, 2);
		 TextDrawHideForPlayer(playerid, CountText[playerid]);
		 }
        return 1;
}
And some fixes for this function:

Код:
forward CountDown1(playerid);
public CountDown1(playerid)
{
	foreach(Player, playerid)
	{
		if(IsPlayerInDynamicCP(playerid, CP[CAPZONE]) && UnderAttack[CAPZONE] == 1 && IsPlayerCapturing[playerid][CAPZONE] == 1)
		{
                        if(CountVar[playerid][CAPZONE] == 0) return KillTimer(ctimer[playerid]);
			CountVar[playerid][CAPZONE]--;
			new str1[124];
			TextDrawShowForPlayer(playerid, CountText[playerid]);
			format(str1, sizeof(str1),"~r~%d seconds ~w~left to ~g~capture", CountVar[playerid][CAPZONE]);
			TextDrawSetString(CountText[playerid], str1);
		}
	}
	return 1;
}
Reply
#3

Replace this code with...
PHP код:
//---------loop-------//
for(new 0MAX_PLAYERS++)
{
    
IsPlayerCapturing[i][Town] = 1;

with this...
PHP код:
IsPlayerCapturing[playerid][Town] = 1
The looping code will allow any one to capture the zone and will bug the capture zone. I can explain the bug.
Reply
#4

Not working (i can't see gametext or textdraw) and 1 warning
Quote:

warning 219: local variable "playerid" shadows a variable at a preceding level

Код:
forward CountDown1(playerid);
public CountDown1(playerid)
{
	--> foreach(Player, playerid)
	{
		if(IsPlayerInDynamicCP(playerid, CP[CAPZONE]) && UnderAttack[CAPZONE] == 1 && IsPlayerCapturing[playerid][CAPZONE] == 1)
		{
  			if(CountVar[playerid][CAPZONE] == 0) return KillTimer(ctimer[playerid]);
			CountVar[playerid][CAPZONE]--;
			new str1[124];
			TextDrawShowForPlayer(playerid, CountText[playerid]);
			format(str1, sizeof(str1),"~r~%d seconds ~w~left to ~g~capture", CountVar[playerid][CAPZONE]);
			TextDrawSetString(CountText[playerid], str1);
		}
	}
	return 1;
}
Reply
#5

Quote:
Originally Posted by Mijata
Посмотреть сообщение
Not working (i can't see gametext or textdraw) and 1 warning

Код:
forward CountDown1(playerid);
public CountDown1(playerid)
{
	--> foreach(Player, playerid)
	{
		if(IsPlayerInDynamicCP(playerid, CP[CAPZONE]) && UnderAttack[CAPZONE] == 1 && IsPlayerCapturing[playerid][CAPZONE] == 1)
		{
  			if(CountVar[playerid][CAPZONE] == 0) return KillTimer(ctimer[playerid]);
			CountVar[playerid][CAPZONE]--;
			new str1[124];
			TextDrawShowForPlayer(playerid, CountText[playerid]);
			format(str1, sizeof(str1),"~r~%d seconds ~w~left to ~g~capture", CountVar[playerid][CAPZONE]);
			TextDrawSetString(CountText[playerid], str1);
		}
	}
	return 1;
}
lol why a loop,simply remove the loop ad there is no use of it here as we already defined the playerid

Код:
forward CountDown1(playerid);
public CountDown1(playerid)
{
		if(IsPlayerInDynamicCP(playerid, CP[CAPZONE]) && UnderAttack[CAPZONE] == 1 && IsPlayerCapturing[playerid][CAPZONE] == 1)
		{
  			if(CountVar[playerid][CAPZONE] == 0) return KillTimer(ctimer[playerid]);
			CountVar[playerid][CAPZONE]--;
			new str1[124];
			TextDrawShowForPlayer(playerid, CountText[playerid]);
			format(str1, sizeof(str1),"~r~%d seconds ~w~left to ~g~capture", CountVar[playerid][CAPZONE]);
			TextDrawSetString(CountText[playerid], str1);
		}
	        return 1;
}
Reply
#6

Again nothing...
Reply
#7

I forgot to set the countvar value,im dumb
Код:
new ctimer[MAX_PLAYERS];

stock ActiveTown(playerid)
{
        if(UnderAttack[Town] == 0)
        {
            if(!IsPlayerInAnyVehicle(playerid))
            {
                UnderAttack[Town] = 1;
                timer[playerid][Town] = SetTimerEx("TownTimer", 25000, false,"i",playerid);
                Captured[playerid][Town] = 0;
                SendClientMessage(playerid, -1,"| Stay in this checkpoint for {FFFFFF}25 {FFFFFF}seconds {FFFFFF}to capture it! |");
                if(gTeam[playerid] == C1)
                {
                  GangZoneFlashForAll(Zone[Town], COLOR_BLUE);
                }
                else if(gTeam[playerid] == T1)
                {
                  GangZoneFlashForAll(Zone[Town], RED);
                }
                 else if(gTeam[playerid] == BG)
                {
                  GangZoneFlashForAll(Zone[Town], RED);
                }

                //------Message-----
                if(tCP[Town] == C1)
                {
                  SendClientMessage(playerid, C_COLOR,"This flag is controlled by Cops!");
                  SendClientMessageToAll(-1,"{FFFFFF}>{FFFFFF}Old observatory is under attack!");
                }
                else if(tCP[Town] == T1)
                {
                  SendClientMessage(playerid, T_COLOR,"This flag is controlled by Terrorists!");
                  SendClientMessageToAll(-1,"{FFFFFF}>{FFFFFF}Old observatory is under attack!");
                }
				else if(tCP[Town] == BG)
                {
                  SendClientMessage(playerid, T_COLOR,"This flag is controlled by Terrorists!");
                  SendClientMessageToAll(-1,"{FFFFFF}>{FFFFFF}Old observatory is under attack!");
                }
                else if(tCP[Town] == NONE)
                {
                  SendClientMessage(playerid, COLOR_WHITE,"This flag is not controlled by any team!");
                }
                //---------loop-------//
                for(new i = 0; i < MAX_PLAYERS; i ++)
                {
                   IsPlayerCapturing[i][Town] = 1;
                }
                ctimer[playerid] = SetTimerEx("CountDown1", 1000, true, "i", playerid);
                CountVar[playerid][Town] = 25;
            }
            else return CaptureZoneMessage(playerid, 1);
        }
        else {
		 CaptureZoneMessage(playerid, 2);
		 TextDrawHideForPlayer(playerid, CountText[playerid]);
		 }
        return 1;
}
Reply
#8

PHP код:
new ctimer[MAX_PLAYERS];
stock ActiveTown(playerid)
{
        if(
UnderAttack[Town] == 0)
        {
            if(!
IsPlayerInAnyVehicle(playerid))
            {
                
UnderAttack[Town] = 1;
                
Captured[playerid][Town] = 0;
                
// Removed a unnecessary timer...
                
IsPlayerCapturing[playerid][Town] = 1//Fix
                
SendClientMessage(playerid, -1,"| Stay in this checkpoint for {FFFFFF}25 {FFFFFF}seconds {FFFFFF}to capture it! |");
                
CountVar[Town] = 25;
                if(
gTeam[playerid] == C1)
                {
                  
GangZoneFlashForAll(Zone[Town], COLOR_BLUE);
                }
                else if(
gTeam[playerid] == T1)
                {
                  
GangZoneFlashForAll(Zone[Town], RED);
                }
                 else if(
gTeam[playerid] == BG)
                {
                  
GangZoneFlashForAll(Zone[Town], RED);
                }
                
//------Message-----
                
if(tCP[Town] == C1)
                {
                  
SendClientMessage(playeridC_COLOR,"This flag is controlled by Cops!");
                  
SendClientMessageToAll(-1,"{FFFFFF}>{FFFFFF}Old observatory is under attack!");
                }
                else if(
tCP[Town] == T1)
                {
                  
SendClientMessage(playeridT_COLOR,"This flag is controlled by Terrorists!");
                  
SendClientMessageToAll(-1,"{FFFFFF}>{FFFFFF}Old observatory is under attack!");
                }
                else if(
tCP[Town] == BG)
                {
                  
SendClientMessage(playeridT_COLOR,"This flag is controlled by Terrorists!");
                  
SendClientMessageToAll(-1,"{FFFFFF}>{FFFFFF}Old observatory is under attack!");
                }
                else if(
tCP[Town] == NONE)
                {
                  
SendClientMessage(playeridCOLOR_WHITE,"This flag is not controlled by any team!");
                }
                
ctimer[playerid] = SetTimerEx("Count"1000true"i"playerid);
            }
            else return 
CaptureZoneMessage(playerid1);
        }
        else {
         
CaptureZoneMessage(playerid2);
         
TextDrawHideForPlayer(playeridCountText[playerid]);
         }
        return 
1;

PHP код:
forward Count(playerid);
public 
Count(playerid)
{
        if(
IsPlayerInDynamicCP(playeridCP[Town]) && UnderAttack[Town] == && IsPlayerCapturing[playerid][Town] == 1)
        {
              if(
CountVar[playerid][Town] == 0) return KillTimer(ctimer[playerid]);
            
CountVar[playerid][Town] --;
            new 
str1[124];
            
TextDrawShowForPlayer(playeridCountText[playerid]);
            
format(str1sizeof(str1),"~r~%d seconds ~w~left to ~g~capture"CountVar[playerid][Town]);
            
TextDrawSetString(CountText[playerid], str1);
                        if(
CountVar[playerid][Town] <= 0)
                       {
                           
TownCaptured(playerid);
                       }
        }
            return 
1;

Reply
#9

Quote:
Originally Posted by K0P
Посмотреть сообщение
I forgot to set the countvar value,im dumb
Код:
new ctimer[MAX_PLAYERS];

stock ActiveTown(playerid)
{
        if(UnderAttack[Town] == 0)
        {
            if(!IsPlayerInAnyVehicle(playerid))
            {
                UnderAttack[Town] = 1;
                timer[playerid][Town] = SetTimerEx("TownTimer", 25000, false,"i",playerid);
                Captured[playerid][Town] = 0;
                SendClientMessage(playerid, -1,"| Stay in this checkpoint for {FFFFFF}25 {FFFFFF}seconds {FFFFFF}to capture it! |");
                if(gTeam[playerid] == C1)
                {
                  GangZoneFlashForAll(Zone[Town], COLOR_BLUE);
                }
                else if(gTeam[playerid] == T1)
                {
                  GangZoneFlashForAll(Zone[Town], RED);
                }
                 else if(gTeam[playerid] == BG)
                {
                  GangZoneFlashForAll(Zone[Town], RED);
                }

                //------Message-----
                if(tCP[Town] == C1)
                {
                  SendClientMessage(playerid, C_COLOR,"This flag is controlled by Cops!");
                  SendClientMessageToAll(-1,"{FFFFFF}>{FFFFFF}Old observatory is under attack!");
                }
                else if(tCP[Town] == T1)
                {
                  SendClientMessage(playerid, T_COLOR,"This flag is controlled by Terrorists!");
                  SendClientMessageToAll(-1,"{FFFFFF}>{FFFFFF}Old observatory is under attack!");
                }
				else if(tCP[Town] == BG)
                {
                  SendClientMessage(playerid, T_COLOR,"This flag is controlled by Terrorists!");
                  SendClientMessageToAll(-1,"{FFFFFF}>{FFFFFF}Old observatory is under attack!");
                }
                else if(tCP[Town] == NONE)
                {
                  SendClientMessage(playerid, COLOR_WHITE,"This flag is not controlled by any team!");
                }
                //---------loop-------//
                for(new i = 0; i < MAX_PLAYERS; i ++)
                {
                   IsPlayerCapturing[i][Town] = 1;
                }
                ctimer[playerid] = SetTimerEx("CountDown1", 1000, true, "i", playerid);
                CountVar[playerid][Town] = 25;
            }
            else return CaptureZoneMessage(playerid, 1);
        }
        else {
		 CaptureZoneMessage(playerid, 2);
		 TextDrawHideForPlayer(playerid, CountText[playerid]);
		 }
        return 1;
}
Same problem
Reply
#10

Try my code.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)