30.03.2012, 23:48
@Luis
I don't even understand how you want the number generation to work. Obviously you should, on top of LottoDraw, generate the winning number and when iterating through connected players, compare the two numbers.
This code is not tested and it is based on my previous example, not the example of anyone else.
@KyleSmith
Do you realize that this is useless?
You can simply avoid winning variable ever becoming 0.
Another thing is this:
The second check is simply useless. How can it be -1 when you already check if it is -1 before?
@Haydz
Hehe, sorry for that. Also, you don't exactly need to create a new variable to see if anyone won or not. Simply play around with the LotteryIsOn variable a little bit and as you can see from Luis' original code, he resets it to 0 in a loop. If it has not been reset to 0 after the loop, it means there was no winner!
I don't even understand how you want the number generation to work. Obviously you should, on top of LottoDraw, generate the winning number and when iterating through connected players, compare the two numbers.
pawn Код:
new winningNumber = random(100) + 1, LotteryParticipants;
foreach(Player, i)
{
if(EnterLotto[i] == 0)
continue; // Don't do anything else for this player, he is not participating in the lottery
// The player is in the lotto, however might not win. Still consider them as a participant!
LotteryParticipants ++;
// Now compare the winning number to the one generated when player joined the lottery
if(winningNumber == PlayerLotteryNumber[i])
{
// yay, set the lottery state to ended!
LotteryIsOn = 0;
}
}
// Now, check if there were no participants.
if(!LotteryParticipants)
SendClientMessageToAll(COLOR_WHITE, "INFO: The lottery was canceled due to nobody entering.");
// And if there were participants, but no-one won (in this case the LotteryIsOn variable is still 1 because we didn't reset it in the loop)
if(LotteryIsOn == 1)
SendClientMessageToAll(COLOR_WHITE, "INFO: There was no winner.");
@KyleSmith
Do you realize that this is useless?
pawn Код:
new winning = random(100);
if(winning == 0)
{
return LottoDraw();
}
pawn Код:
new winning = random(100) + 1;
pawn Код:
if(lwiner == -1)
{
//THERE IS NO WINNER
return 1;
}
if(lwiner != -1)
{
// WINNER ID IS STORED WITHIN THE VAR 'lwiner'
return 1;
}
pawn Код:
if(lwiner == -1)
{
// No winner
return 1;
}
// winner id is stored in var 'lwiner'
Hehe, sorry for that. Also, you don't exactly need to create a new variable to see if anyone won or not. Simply play around with the LotteryIsOn variable a little bit and as you can see from Luis' original code, he resets it to 0 in a loop. If it has not been reset to 0 after the loop, it means there was no winner!

