Countdown doesn't work correctly! -
[WSF]ThA_Devil - 04.09.2011
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"
};
AW: Countdown doesn't work correctly! -
Nero_3D - 04.09.2011
Use SetTimerEx and move it and the decrease of count outside the loop
Re: Countdown doesn't work correctly! -
Basicz - 04.09.2011
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.
Re: Countdown doesn't work correctly! -
[WSF]ThA_Devil - 04.09.2011
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
Re: Countdown doesn't work correctly! -
Basicz - 04.09.2011
Please use the last edit, it can mess up another player's countdown.
Re: Countdown doesn't work correctly! -
[WSF]ThA_Devil - 04.09.2011
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
Re: Countdown doesn't work correctly! -
iMonk3y - 04.09.2011
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;
}
Re: Countdown doesn't work correctly! -
[WSF]ThA_Devil - 04.09.2011
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...
Re: Countdown doesn't work correctly! -
Basicz - 04.09.2011
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 )
Re: Countdown doesn't work correctly! -
[WSF]ThA_Devil - 04.09.2011
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