Lottery Script
#7

EDIT: Dam, I was too slow, I'll leave my reply here anyways.

Hopefully you're looking for something like this, pretty much it just picks a random number, the server will loop through all of the players to find a ticket winner, if somebody has it, tell the server somebody won and give them their prize, if nobody is found in the loop the somebodywon will still be = to 0 and It'll tell the server that nobody has won after the loop has been completed.

You may have to add some additional checks to the script, like check if they have actually entered. But I'm assuming when a player doesn't sign up for a ticket there var would be '0' anyways, so not a problem. Nothing the less It gives you a fair idea on how you go about it.

pawn Код:
forward LottoDraw();
public LottoDraw()
{
    new somebodywon = 0, lottowinner = randomEx(1,100); //Pick some numbers to choose between, then we'll loop through the players to see if anybody had that ticket.
    foreach(Player,i)
    {
        if(PlayerLotteryNumber[i] == lottowinner) // Somebody won, give them their prize and tell the server that they've won.
        {
            somebodywon = 1;
            new string[128];
            format(string, sizeof(string), "LOTTERY: The lottery winner is %s(%d) with the ticket %d, they have won a total of $150!", Name(i), i, PlayerLotteryNumber[i]);
            SendClientMessageToAll(COLOR_WHITE, string);
            LotteryIsOn = 0;
            EnterLotto[i] = 0;
        }
    }
    if(somebodywon == 0) //Nobody won, tell the server so.
    {
        SendClientMessageToAll(COLOR_WHITE, "INFO: There was no winner.");
    }
    return 1;
}
In addition you'll also need the randomEx function, you could change it back to the normal rand function, but I like using this one better .

pawn Код:
stock randomEx(min, max)
{
    new rand = random(max-min)+min;
    return rand;
}
Hopefully I've helped you out with what you wanted, if not don't hesitate to ask again.
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)