/buyticket command.
#2

pawn Code:
//Vars
new Ticket[MAX_PLAYERS];

CMD:buyticket(playerid, params[])
{
    new number;
    if(Ticket[playerid] != 0) return SendClientMessage(playerid, -1, "You already have a lotto ticket!");
    if(GetPlayerMoney(playerid) < 1000) return SendClientMessage(playerid, -1, "You can't afford the lotto ticket!");
    if(sscanf(params, "i", number) return SendClientMessage(playerid, -1, "Syntax: /buyticket <number>");
    if(number > 100 || number < 1) return SendClientMessage(playerid, -1, "Lotto number must be between 1-100!");
    //The rest happens if all above checks out
    Ticket[playerid] = number;
    SendClientMessage(playerid, -1. "Ticket bought!");
    GivePlayerMoney(playerid, -1000);
    return 1;
}

stock CheckTickets()
{
    new rand = rand2(1,100);
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(rand == Ticket[i])
        {
            SendClientMessage(i, -1, "You've won the lotto!");
            GivePlayerMoney(i, 5000);
            return 1;
        }
    }
    return 1;
}

stock rand2(min, max)
{    
    new rand = random(max-min)+min;    
    return rand;
}
untested, wrote it up in notepad quickly.. you'd have to use checktickets with a timer or what not
Reply


Messages In This Thread
/buyticket command. - by iGetty - 11.08.2011, 02:14
Re: /buyticket command. - by PrawkC - 11.08.2011, 04:36
Re: /buyticket command. - by iGetty - 11.08.2011, 05:48

Forum Jump:


Users browsing this thread: 1 Guest(s)