Capture the Flag timer bug -
Stefand - 31.08.2012
Hey all,
Im making my own Capture the flag GM, but when the timer turns 00:00 it starts counting down again so 00:-10 example.
Also the most points check doesnt work. it just sends the first message.
Code:
This is under onesecondpublic, a Public that does a action each 1sec.
pawn Код:
if(PlayTimeMinutes >= 9)
{
PlayTimeSeconds --;
if(PlayTimeSeconds == 0)
{
PlayTimeMinutes --;
PlayTimeSeconds = 60;
}
format(string, sizeof(string), "%d:%d", PlayTimeMinutes, PlayTimeSeconds);
TextDrawSetString(TimeTD,string);
}
if(PlayTimeMinutes <= 10)
{
PlayTimeSeconds --;
if(PlayTimeSeconds == 0)
{
PlayTimeMinutes --;
PlayTimeSeconds = 60;
}
format(string, sizeof(string), "0%d:%d", PlayTimeMinutes, PlayTimeSeconds);
TextDrawSetString(TimeTD,string);
}
if(PlayTimeMinutes == 0)
{
if(PlayTimeSeconds >= 0)
{
PlayTimeSeconds --;
format(string, sizeof(string), "00:%d", PlayTimeSeconds);
TextDrawSetString(TimeTD,string);
}
if(PlayTimeSeconds == 0)
{
format(string, sizeof(string), "00:00");
TextDrawSetString(TimeTD,string);
TogglePlayerControllable(i, 0);
SetTimerEx("StartNewRound", 15000, false, "d", i);
if(BlueScore >= RedScore)
{
format(string, sizeof(string), "Congratulations to {0000FF}Team Blue, {FFFF00}they have won with %d point!", BlueScore);
SendClientMessageToAll(YELLOW, string);
}
else if(RedScore >= BlueScore)
{
format(string, sizeof(string), "Congratulations to {FF0000}Team Red, {FFFF00}they have won with %d point!", RedScore);
SendClientMessageToAll(YELLOW, string);
}
else if(RedScore == BlueScore)
{
format(string, sizeof(string), "Nobody won this match, {0000FF}%d {FFFF00}vs {FF0000}%d", BlueScore, RedScore);
SendClientMessageToAll(YELLOW, string);
}
}
}
Re: Capture the Flag timer bug -
Misiur - 31.08.2012
You overdid it. You can replace your whole chunk with this:
pawn Код:
if(0 == PlayTimeSeconds && 0 == PlayTimeMinutes) {
TogglePlayerControllable(i, 0);
SetTimerEx("StartNewRound", 15000, false, "d", i);
if(BlueScore >= RedScore) format(string, sizeof(string), "Congratulations to {0000FF}Team Blue, {FFFF00}they have won with %d point!", BlueScore);
else if(RedScore >= BlueScore) format(string, sizeof(string), "Congratulations to {FF0000}Team Red, {FFFF00}they have won with %d point!", RedScore);
else format(string, sizeof(string), "Nobody won this match, {0000FF}%d {FFFF00}vs {FF0000}%d", BlueScore, RedScore);
SendClientMessageToAll(YELLOW, string);
//Kill the current timer here
} else {
PlayTimeSeconds--;
if(PlayTimeSeconds == 0)
{
PlayTimeMinutes --;
PlayTimeSeconds = 60;
}
}
format(string, sizeof(string), "%2d:%2d", PlayTimeMinutes, PlayTimeSeconds);
TextDrawSetString(TimeTD,string);
Don't forget to substitute "kill the timer" comment with real killtimer
Also solution using gettime could be better.
Re: Capture the Flag timer bug -
Stefand - 31.08.2012
What do you mean with gettime?
Re: Capture the Flag timer bug -
Stefand - 31.08.2012
And the Timer is still bugged it keeps counting down
Re: Capture the Flag timer bug -
Misiur - 31.08.2012
pawn Код:
new timey = 0;
forward Tick(time);
main() {
new minutes = 10, seconds = 0;
timey = SetTimerEx("Tick", 1000, true, "d", minutes*60+seconds);
}
public Tick(time) {
static limit = gettime() + time;
new current = gettime(), diff = limit - current;
printf("%2d:%2d", diff / 60, diff % 60);
if(0 == diff) KillTimer(timey);
}
Your homework is to analyse this code.
`e:
If you didn't kill the timer then even Satan won't help you.