29.10.2019, 15:31
okay, it means that we have to prioritize the lotto numbers first, then if there is not a winner by that number, we should start a new lottery by the players, so, I'll write a code here to do that.
PHP Code:
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++;
LottoNumber[i] = 0;
//break; NO NEED, WILL CAUSE ISSUES
}
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; NO NEED, THIS WILL STOP WHOLE FUNCTION
LottoNumber[i] = 0;
}
LottoNum = 0;
if(TotalWinners == 0) //So if there is not a winner, start a second lottery.
{
new winnerID = random(GetPlayerPoolSize());
while(IsPlayerConnected(winnerID))
{
winnerID = random(GetPlayerPoolSize());
}
GetPlayerName(winnerID, Name, sizeof(Name));
format(Msg, sizeof(Msg), "{FFFF00}LOTTO: Congratulations, you have won $%i in the lottery!", LottoPrize);
SendClientMessage(winnerID, COLOR_WHITE, Msg);
format(Msg, sizeof(Msg), "{FFFF00}LOTTO: %s has won $%i in the lottery. Congratulations!", Name, LottoPrize);
SendClientMessageToAll(COLOR_WHITE, Msg);
GivePlayerMoney(winnerID, LottoPrize);
}
LottoPrize = 0;