Lottery Script
#10

@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.

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.");
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?
pawn Код:
new winning = random(100);
if(winning == 0)
{
      return LottoDraw();
}
You can simply avoid winning variable ever becoming 0.
pawn Код:
new winning = random(100) + 1;
Another thing is this:
pawn Код:
if(lwiner == -1)
{
    //THERE IS NO WINNER
    return 1;
}
if(lwiner != -1)
{
    // WINNER ID IS STORED WITHIN THE VAR 'lwiner'
    return 1;
}
The second check is simply useless. How can it be -1 when you already check if it is -1 before?
pawn Код:
if(lwiner == -1)
{
    // No winner
    return 1;
}
// winner id is stored in var 'lwiner'
@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!
Reply


Messages In This Thread
Lottery Script - by Luis- - 30.03.2012, 18:59
Re: Lottery Script - by T0pAz - 30.03.2012, 19:30
Re: Lottery Script - by antonio112 - 30.03.2012, 19:31
Re: Lottery Script - by Luis- - 30.03.2012, 19:35
Re: Lottery Script - by antonio112 - 30.03.2012, 19:36
Re: Lottery Script - by AndreT - 30.03.2012, 20:05
Re: Lottery Script - by Haydz - 30.03.2012, 20:10
Re: Lottery Script - by Luis- - 30.03.2012, 21:42
Re: Lottery Script - by Kyle - 30.03.2012, 21:47
Re: Lottery Script - by AndreT - 30.03.2012, 23:48

Forum Jump:


Users browsing this thread: 1 Guest(s)