Countdown Bug.
#1

Err, so I may have posted something similar to this earlier, but I've got a new bug.

I do /countdown, it counts down fine, but if someone else is near, it bugs the timer, affecting the countdown.
(Yes, I'm trying to get it to where if a player is near it counts down for them too.)

Here's the code, thanks in advance.

pawn Код:
command(countdown,playerid,params[])
{
    CountDown(playerid, 3);
    return 1;
}

forward CountDown(playerid, seconds);
public CountDown(playerid, seconds)
{
    new string[50];
    if(seconds > 0)
    {
        new Float:X, Float:Y, Float:Z;
        GetPlayerPos(playerid, X, Y, Z);
        for(new i=0;i<MAX_PLAYERS;i++) {
            if(IsPlayerInRangeOfPoint(i, 40, X, Y, Z)) {
                PlayerPlaySound(i, 1056, X, Y, Z);
                format(string, sizeof(string), "~b~%d", seconds);
                GameTextForPlayer(i, string, 1000, 3);
                seconds = seconds -1;
                SetTimerEx("CountDown", 1000, 0, "ii", playerid, seconds);
            }
        }
        return 1;
    }
    if(seconds == 0)
    {
        new Float:X, Float:Y, Float:Z;
        GetPlayerPos(playerid, X, Y, Z);
        for(new i=0;i<MAX_PLAYERS;i++) {
            if(IsPlayerInRangeOfPoint(i, 40, X, Y, Z)) {
                PlayerPlaySound(playerid, 1057, X, Y, Z);
                GameTextForPlayer(playerid, "~G~Go!", 1000, 3);
            }
        }
        return 1;
    }
    return 1;
}
LadyNyuuu's post was correct, I made a noob error.
Reply
#2

Not Alot you could do, Maybe you could slim down the area of the variable location of where you are. but honestly other then that it might be contradicting with something else in your script
Reply
#3

place this outside for loop
pawn Код:
seconds = seconds -1;
Reply
#4

Try to use this, i fixed it a little bit.
Your mistake was:

> Starting Timer more then one time, for everyone near you.
> Resetting the Timer if someone is near you (that bugs arround for you)

pawn Код:
new Timer_Countdown;
new CountDown_Time;

command(countdown,playerid,params[])
{
    CountDown(playerid, 3);
    return 1;
}

forward CountDown(playerid, seconds);
public CountDown(playerid, seconds)
{
    if(seconds > 0)
    {
        new Float:X, Float:Y, Float:Z;
        GetPlayerPos(playerid, X, Y, Z);
       
        CountDown_Time = seconds;
        CountDownThink(X,Y,Z);
        KillTimer(Timer_Countdown);
        Timer_Countdown = SetTimerEx("CountDownThink", 1000,true, "fff", X,Y,Z);
       
        return 1;
    }
    return 1;
}

forward CountDownThink(Float:X,Float:Y,Float:Z);
public CountDownThink(Float:X,Float:Y,Float:Z)
{
    new string[50];
    new seconds = CountDown_Time;
    for(new i=0;i<MAX_PLAYERS;i++)
    {
        if(IsPlayerInRangeOfPoint(i, 40, X, Y, Z))
        {
            if(seconds == 0)
            {
                PlayerPlaySound(i, 1057, X, Y, Z);
                GameTextForPlayer(i, "~G~Go!", 1000, 3);
            }
            else
            {
                PlayerPlaySound(i, 1056, X, Y, Z);
                format(string, sizeof(string), "~b~%d", seconds);
                GameTextForPlayer(i, string, 1000, 3);
                CountDown_Time = seconds -1;
            }
        }
    }
    if (seconds == 0)
    {
        KillTimer(Timer_Countdown);
    }
}
This is my fixed version ^-^.
Reply
#5

Quote:
Originally Posted by LadyNyuuu
Посмотреть сообщение
Try to use this, i fixed it a little bit.
Your mistake was:

> Starting Timer more then one time, for everyone near you.
> Resetting the Timer if someone is near you (that bugs arround for you)

pawn Код:
new Timer_Countdown;
new CountDown_Time;

command(countdown,playerid,params[])
{
    CountDown(playerid, 3);
    return 1;
}

forward CountDown(playerid, seconds);
public CountDown(playerid, seconds)
{
    if(seconds > 0)
    {
        new Float:X, Float:Y, Float:Z;
        GetPlayerPos(playerid, X, Y, Z);
       
        CountDown_Time = seconds;
        CountDownThink(X,Y,Z);
        KillTimer(Timer_Countdown);
        Timer_Countdown = SetTimerEx("CountDownThink", 1000,true, "fff", X,Y,Z);
       
        return 1;
    }
    return 1;
}

forward CountDownThink(Float:X,Float:Y,Float:Z);
public CountDownThink(Float:X,Float:Y,Float:Z)
{
    new string[50];
    new seconds = CountDown_Time;
    for(new i=0;i<MAX_PLAYERS;i++)
    {
        if(IsPlayerInRangeOfPoint(i, 40, X, Y, Z))
        {
            if(seconds == 0)
            {
                PlayerPlaySound(i, 1057, X, Y, Z);
                GameTextForPlayer(i, "~G~Go!", 1000, 3);
            }
            else
            {
                PlayerPlaySound(i, 1056, X, Y, Z);
                format(string, sizeof(string), "~b~%d", seconds);
                GameTextForPlayer(i, string, 1000, 3);
                CountDown_Time = seconds -1;
            }
        }
    }
    if (seconds == 0)
    {
        KillTimer(Timer_Countdown);
    }
}
This is my fixed version ^-^.
Sorry for such a late response, but that didn't work, the person next to me didn't see the countdown.
Reply
#6

Check the code I posted in this thread, it's kinda similar to what you want so it might help you out.
Reply
#7

pawn Код:
GameTextForPlayer(i, "~G~Go!", 1000, 3);
~G~dosnt mean anything
Reply
#8

Quote:
Originally Posted by axxelac
Посмотреть сообщение
pawn Код:
GameTextForPlayer(i, "~G~Go!", 1000, 3);
~G~dosnt mean anything
Game text styles. It's green
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)