Countdown doesn't work correctly!
#1

it just spams numbers randomly -_-
pawn Код:
public CountDown(playerid){
    new Float:X,Float:Y,Float:Z;
    GetPlayerPos(playerid,X,Y,Z);
        for(new i = 0; i < MAX_PLAYERS; i++)
    {
    if(IsPlayerInRangeOfPoint(i, 10.0, X, Y, Z))
    {
    if (Count > 0){
    GameTextForPlayer(i, CountText[Count-1], 2500, 3);
    Count--;
    SetTimer("CountDown", 1000, 0);
    }
    else{
    GameTextForPlayer(i,"~g~Go Go Go!!!", 2500, 3);
    }
    }
    }
    return 1;
}
Command:
pawn Код:
if (strcmp(cmdtext, "/count", true)==0)
    {
        new name[MAX_PLAYER_NAME], string[99];
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "%s has started countdown at their position!",name);
        SendClientMessageToAll(0xFFFF00AA, string);
        Count = 5;
        CountDown(playerid);
        return 1;
    }
pawn Код:
new Count = 5;
new CountText[5][5] ={
"~r~1",
"~r~2",
"~r~3",
"~b~4",
"~b~5"
};
Reply
#2

Use SetTimerEx and move it and the decrease of count outside the loop
Reply
#3

I would do :

pawn Код:
new Count[ MAX_PLAYERS ] = 5, countTimer[ MAX_PLAYERS ], bool: hasc[ MAX_PLAYERS ];

// onplayerconnect
hasc[ playerid ] = false;

forward Countdown( playerid );
public Countdown( playerid )
{
    new
        Float: Pos[ 3 ]
    ;

    GetPlayerPos( playerid, Pos[ 0 ], Pos[ 1 ], Pos[ 2 ] );

    for ( new p = GetMaxPlayers( ), i; i < p; i ++ )
    {
        if ( !IsPlayerConnected( i ) )
            continue;

        if ( !IsPlayerInRangeOfPoint( i, 2.0, Pos[ 0 ], Pos[ 1 ], Pos[ 2 ] ) )
            continue;

        if ( Count[ playerid ] > 0 )
            Count[ playerid ] --;

        if ( Count[ playerid ] == 0 )
            KillTimer( countTimer[ playerid ] ), GameTextForPlayer( i, "~r~GO GO GO!", 2500, 3 ), hasc[ playerid ] = false;

        new gametextFormat[ 5 ];

        format( gametextFormat, 5, "~r~%d", Count );

        GameTextForPlayer( i, gametextFormat, 2500, 3 );
    }

    return 1;
}

// Command

COMMAND:count( playerid, params[ ] )
{
    foreach (Player, i)
        if ( hasc[ i ] )
            // error: somebodys already starting countdown

    if ( hasc[ playerid ] )
        // error : you are already starting a countdown

    // Messages thingy

    Count[ playerid ] = 5;

    countTimer[ playerid ] = SetTimerEx( "Countdown", 1000, true, "i", playerid );

    hasc[ playerid ] = true;
 
    return 1;
}
EDIT: Added an area check
EDIT2: Added an antispam for a player, so he will not repeat the command everytime.
EDIT3: IMPORTANT! Edited my post, so it will not mess another people's countdown.
EDIT4: Fixed.
Reply
#4

Quote:
Originally Posted by Basicz
Посмотреть сообщение
I would do :

pawn Код:
new Count = 0, countTimer[ MAX_PLAYERS ];

forward Countdown( playerid );
public Countdown( playerid )
{
    new
        Float: Pos[ 3 ]
    ;

    GetPlayerPos( playerid, Pos[ 0 ], Pos[ 1 ], Pos[ 2 ] );

    for ( new p = GetMaxPlayers( ), i; i < p; i ++ )
    {
        if ( !IsPlayerConnected( i ) )
            continue;

        if ( !IsPlayerInRangeOfPoint( i, 2.0, Pos[ 0 ], Pos[ 1 ], Pos[ 2 ] ) )
            continue;

        if ( Count < 5 )
            Count ++;

        if ( Count == 5 )
            KillTimer( countTimer[ playerid ] ), GameTextForPlayer( i, "~r~GO GO GO!", 2500, 3 );

        new gametextFormat[ 5 ];

        format( gametextFormat, 5, "~r~%d", Count );

        GameTextForPlayer( i, gametextFormat, 2500, 3 );
    }

    return 1;
}

// Command

COMMAND:count( playerid, params[ ] )
{
    // Messages thingy

    Count = 0;

    countTimer[ playerid ] = SetTimerEx( "Countdown", 1000, true, "i", playerid );
 
    return 1;
}
EDIT: Added an area check
WTF O.o didn't undarstood anything but k, gotta try xD
Reply
#5

Please use the last edit, it can mess up another player's countdown.
Reply
#6

well it counts up not down and second... it misses every second number... well it works when i am alone... but when we are to one gets 1 3 5 and second 2 and 4
Reply
#7

SetTimer will get called as many times as there are players in range of point. I would do the following operation: Remove red and add green.
Код:
public CountDown()
{
    new Float:X,Float:Y,Float:Z;
    GetPlayerPos(playerid,X,Y,Z);
    for(new i = 0; i < MAX_PLAYERS; i++)
    foreach(Player,i)
    {
        GetPlayerPos(i,X,Y,Z);
        if(IsPlayerInRangeOfPoint(i, 10.0, X, Y, Z))
        {
            if (Count > 0)
            {
                GameTextForPlayer(i, CountText[Count-1], 2500, 3);
                Count--;
                SetTimer("CountDown", 1000, 0);
            }
            else
            {
                GameTextForPlayer(i,"~g~Go Go Go!!!", 2500, 3);
            }
        }
    }
    if(Count > 0) SetTimer("CountDown", 1000, 0);
    return 1;
}
Reply
#8

Quote:
Originally Posted by iMonk3y
Посмотреть сообщение
SetTimer will get called as many times as there are players in range of point. I would do the following operation: Remove red and add green.
Код:
public CountDown()
{
    new Float:X,Float:Y,Float:Z;
    GetPlayerPos(playerid,X,Y,Z);
    for(new i = 0; i < MAX_PLAYERS; i++)
    foreach(Player,i)
    {
        GetPlayerPos(i,X,Y,Z);
        if(IsPlayerInRangeOfPoint(i, 10.0, X, Y, Z))
        {
            if (Count > 0)
            {
                GameTextForPlayer(i, CountText[Count-1], 2500, 3);
                Count--;
                SetTimer("CountDown", 1000, 0);
            }
            else
            {
                GameTextForPlayer(i,"~g~Go Go Go!!!", 2500, 3);
            }
        }
    }
    if(Count > 0) SetTimer("CountDown", 1000, 0);
    return 1;
}
well as i undarstood every1 will get countdown but i want at one player position...
Reply
#9

Try my last edit, I have made it counts down + not letting another player counts when someone in near of him/her is counting.

( EDIT4 has been edited 2 times )
Reply
#10

Quote:
Originally Posted by Basicz
Посмотреть сообщение
I would do :

pawn Код:
new Count[ MAX_PLAYERS ] = 5, countTimer[ MAX_PLAYERS ], bool: hasc[ MAX_PLAYERS ];

// onplayerconnect
hasc[ playerid ] = false;

forward Countdown( playerid );
public Countdown( playerid )
{
    new
        Float: Pos[ 3 ]
    ;

    GetPlayerPos( playerid, Pos[ 0 ], Pos[ 1 ], Pos[ 2 ] );

    for ( new p = GetMaxPlayers( ), i; i < p; i ++ )
    {
        if ( !IsPlayerConnected( i ) )
            continue;

        if ( !IsPlayerInRangeOfPoint( i, 2.0, Pos[ 0 ], Pos[ 1 ], Pos[ 2 ] ) )
            continue;

        if ( Count[ playerid ] > 0 )
            Count[ playerid ] --;

        if ( Count[ playerid ] == 0 )
            KillTimer( countTimer[ playerid ] ), GameTextForPlayer( i, "~r~GO GO GO!", 2500, 3 ), hasc[ playerid ] = false;

        new gametextFormat[ 5 ];

        format( gametextFormat, 5, "~r~%d", Count );

        GameTextForPlayer( i, gametextFormat, 2500, 3 );
    }

    return 1;
}

// Command

COMMAND:count( playerid, params[ ] )
{
    foreach (Player, i)
        if ( hasc[ i ] )
            // error: somebodys already starting countdown

    if ( hasc[ playerid ] )
        // error : you are already starting a countdown

    // Messages thingy

    Count[ playerid ] = 5;

    countTimer[ playerid ] = SetTimerEx( "Countdown", 1000, true, "i", playerid );

    hasc[ playerid ] = true;
 
    return 1;
}
EDIT: Added an area check
EDIT2: Added an antispam for a player, so he will not repeat the command everytime.
EDIT3: IMPORTANT! Edited my post, so it will not mess another people's countdown.
EDIT4: Fixed.
well Edit 4 works quiet good but... i don't get that GO GO GO message
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)