29.10.2019, 15:10
Quote:
Well, first, use GetPlayerPoolSize instead of MAX_PLAYERS, no need to loop through whole 1000 player if they're not connected.
Second, you're making it correct, but return is extra, you don't need that. remove return from code. so correct code looks like this PHP Code:
|
Code:
while(TotalWinners < 1) { LottoNum = 1 + random(59); for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++) { if(!IsPlayerConnected(i)) continue; if(LottoNumber[i] == LottoNum) { // Get the player's name GetPlayerName(i, Name, sizeof(Name)); format(Msg, sizeof(Msg), "{FFFF00}LOTTO: Congratulations, you have won $%i in the lottery!", LottoPrize); SendClientMessage(i, COLOR_WHITE, Msg); format(Msg, sizeof(Msg), "{FFFF00}LOTTO: %s has won $%i in the lottery. Congratulations!", Name, LottoPrize); SendClientMessageToAll(COLOR_WHITE, Msg); GivePlayerMoney(i, LottoPrize); TotalWinners++; break; } else if(LottoNumber[i] != 0 && LottoNumber[i] != LottoNum && TotalWinners > 0) { SendClientMessage(i, COLOR_WHITE, "{FFFF00}LOTTO: Unfortunately you haven't won the lottery. Good luck next time!"); } else return 0; } if(TotalWinners > 0) { for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++) { LottoNumber[i] = 0; LottoNum = 0; LottoPrize = 0; break; } }