Checking if no one's player-specific variable is equal to value
#7

Quote:
Originally Posted by Mugala
View Post
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:
    new TotalWinners 0;
    for(new 
0GetPlayerPoolSize(); <= ji++)
    {
        if(!
IsPlayerConnected(i)) continue; //make loop faster.
        
if(LottoNumber[i] != && LottoNumber[i] != LottoNum//check if they got a wrong number
        
{
            
SendClientMessage(iCOLOR_WHITE"{FFFF00}LOTTO: Unfortunately you haven't won the lottery. Good luck next time!");
        }
        else
        {
            
TotalWinners++; //so we got a one more winner
            //Award
        
}
    }
    if(
TotalWinners == 0SendClientMessageToAll(-1"nobody won"); 
I want a winner guaranteed every time. So I did this:

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;
			}
		}
However, it didn't output anything.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)