Looping problem! -
AnonScripter - 08.06.2014
pawn Код:
if(gminutes == 11 && gseconds == 0)
{
for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(LottoPurchased[i] == true && LottoNumber[i] == RandomNumber)
{
GivePlayerMoney(i, CurrentJackpot);
format(string, sizeof(string), "winning num is %i, %s(%d) has won the lottery of $%i", RandomNumber , GetName(i), i, Jackpot);
}
else
{
format(string, sizeof(string), "winning num is %i, Nobody has won the lottery of $%i", RandomNumber , Jackpot);
}
LottoPurchased[i] = false;
LottoNumber[i] = -1;
}
SendClientMessageToAll(-1, string);
Jackpot = jackrand;
RandomNumber = numrand;
}
Hello! i have made this lotto system, on 11:00 oclock the lotto will be win to any player.
/lotto [random num]
on OnGameModeinIt i have a random number to win the lotto. so if the player is lucky and choosed this num, he's the winner.
i don't know why this only works for the last player id in the server.
example: if there are 4 players in the server
so ID 0,1,2,3 in the server
and each of them did /lotto
if ID 3 is the winner, on 11 oclock he will get the money with a message to all:
"winning num is %i, %s(%d) has won the lottery of $%i"
if someone else below this ID like (0,1,2) is the winner, he will get the money with a message to all:
"winning num is %i, Nobody has won the lottery of $%i"
can somebody tell me why ?
Re: Looping problem! -
Konstantinos - 08.06.2014
Like that, it will send the message as many times as the online players are.
pawn Код:
if(gminutes == 11 && gseconds == 0)
{
new winner = INVALID_PLAYER_ID;
for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(LottoPurchased[i] == true && LottoNumber[i] == RandomNumber)
{
winner = i;
GivePlayerMoney(i, CurrentJackpot);
}
LottoPurchased[i] = false;
LottoNumber[i] = -1;
}
}
if (winner != INVALID_PLAYER_ID) format(string, sizeof(string), "winning num is %i, %s(%d) has won the lottery of $%i", RandomNumber , GetName(winner), winner, Jackpot);
else format(string, sizeof(string), "winning num is %i, Nobody has won the lottery of $%i", RandomNumber , Jackpot);
SendClientMessageToAll(-1, string);
Jackpot = jackrand;
RandomNumber = numrand;
}
Keep in mind though that if more than 1 player has got the correct number, it will say the winner is the player with the highest ID.
Re: Looping problem! -
AnonScripter - 08.06.2014
Thank you +rep