Timer dont stop sometimes:s
#1

Heey guys,
I made a capture system just 2 captures for test but sometimes you still show the progres bar and the timer then repeats.
Here is code:
Код:
public OnCheckpointEnter(playerid, checkpointid)
{
      	if(checkpoint1 && gTeam[playerid]==TEAM_EUROPE && europecapture == 0)
		{
		europetaken=1;
		capture1=1;
		ShowProgressBarForPlayer(playerid,capture);
		areatimer=SetTimer("count1",1000,1);
		}
		if(checkpoint1 && gTeam[playerid]==TEAM_EUROPE && europecapture ==1)
		{
		SendClientMessage(playerid,red,"Your team already has Area51!");
		}
		if(checkpoint1 && gTeam[playerid]==TEAM_USA && usacapture ==0)
		{
		usataken=1;
		capture1=1;
		ShowProgressBarForPlayer(playerid,capture);
		areatimer=SetTimer("count1",1000,1);
		}
		if(checkpoint1 && gTeam[playerid]==TEAM_USA && usacapture ==1)
		{
		SendClientMessage(playerid,red,"Your team already has Area51!");
		}
		return 1;
}
timer:
Код:
forward count1(playerid);
public count1(playerid)
{
//new string[56];
counter++;
SetProgressBarValue(capture, counter);
SetProgressBarMaxValue(capture, 20);
UpdateProgressBar(capture, playerid);
//format(string, sizeof(string),"~r~Wait %d seconds to capture Area51!!",counter);
//GameTextForAll(string,1000,5);
if(counter==20)
{
	if(europetaken==1 && capture1==1)
	{
			GangZoneShowForAll( area, GZ_YELLOW);
   			SetPlayerScore(playerid,GetPlayerScore(playerid)+4);
   			GiveTeamScore(gTeam[playerid]=TEAM_EUROPE, 1);
   			europecapture=1;
			capturedzones[playerid]++;
			KillTimer(areatimer);
	}
	if(usataken==1 && capture1==1)
	{
			GangZoneShowForAll( area, GZ_LIGHTBLUE);
   			SetPlayerScore(playerid,GetPlayerScore(playerid)+4);
            GiveTeamScore(gTeam[playerid]=TEAM_EUROPE, 1);
   			usacapture=1;
			capturedzones[playerid]++;
			KillTimer(areatimer);
	}
	counter=20;
	HideProgressBarForPlayer(playerid, capture);
}
How can i fix this?
Reply
#2

Your code is extremely messy, the problem is taht there's probably a logic path in the code in which the KillTimer function does not exist therefore it never ends. You are going to need to figure that out for yourself. Although there's another logical problem too, this will only ever work for a player with the ID of 0, because you're passing any playerid to the function even though you're expecting one? Why do that?

You need to pass a playerid to the callback in order for it to work as you're expecting it to, for example:

pawn Код:
SetTimerEx("count1", 1000, 1, "i", playerid);
Doesn't that make more sense? Anyway like I said there's most likely a path in which the KillTimer function is not called, therefore the timer isn't ended, you need to fix that. I can tell by looking at it there's probably an issue with the fact that you're only checking if "usataken" or "europtaken" are 1 only when the counter variable is 20, so it has to be at 20 for the timer to be killed.
Reply
#3

Never worked with captures. I was trying it by myself but only have this problem. I need to change my timer to yours?
Reply
#4

You've never had problems with this timer but have you tested it with more than one person? Reality is that it'll only work for ID 0 and when it's called again by another player it'll actually just run for ID 0 too, so ID 0 will have several timers.

I really don't know why people don't understand this, it's very simple:

pawn Код:
public function(playerid, vehicleid)
{
    printf("The player %d is driving vehicle %d", playerid, vehicleid);
    return 1;
}
Using this timer:

pawn Код:
SetTimer("function", 1000, 0);
Will cause the print to output: The player 0 is driving vehicle 0, this is because you are not passing any data to the callback like it is expecting, so instead it defaults those variables to 0, which is logical and makes sense.

pawn Код:
SetTimerEx("function", 1000, "ii", 24, 50);
This will print: The player 24 is driving vehicle 50, this is because you have actually passed the information that the callback is expecting and it has assigned it to the variables as intended.

Doesn't that make sense to you? If it doesn't I highly suggest starting back at the beginning with the PAWN manuals over at CompuPhase which will teach you basic programming logic.
Reply
#5

I will try to fix it by myself. Thanks dude.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)