SA-MP Forums Archive
Countdown Bug. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Countdown Bug. (/showthread.php?tid=354572)



Countdown Bug. [FIXED] - TyThaBomb - 27.06.2012

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.


Re: Countdown Bug. - Slaykler - 27.06.2012

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


Re: Countdown Bug. - [MM]RoXoR[FS] - 27.06.2012

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



AW: Countdown Bug. - LadyNyuuu - 27.06.2012

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 ^-^.


Re: AW: Countdown Bug. - TyThaBomb - 28.06.2012

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.


Re: Countdown Bug. - [KHK]Khalid - 28.06.2012

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


Respuesta: Countdown Bug. - Chris1337 - 28.06.2012

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


Re: Respuesta: Countdown Bug. - [KHK]Khalid - 28.06.2012

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