SA-MP Forums Archive
[Tutorial] [TUT]Lotto script - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] [TUT]Lotto script (/showthread.php?tid=160025)

Pages: 1 2 3


[TUT]Lotto script - [HiC]TheKiller - 15.07.2010

[TUT]Lotto script
Alot of people where asking for this and it's pretty basic so here it is .

Lets start with the defines (You can change most of them to what suits you)

pawn Код:
#include <a_samp> //You need the a_samp include in almost every script.
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1 //DCMD
#define LOTTO_JACKPOT 10000   //How much it goes up every 30 seconds or whenever someone buys a ticket
#define LOTTO_START      200000 //How much the lotto starts off at every draw
#define LOTTO_DRAW      10         //How many minutes between each lotto draw
#define TICKET_COST      1000     //How much a ticket will cost
new Jackpot = LOTTO_START;                                 //Jackpot amount
new Numbers[100];                      //So 2 people don't get the same #
Now we are going to add the timers for the lotto timers (Jackpot and Update).

pawn Код:
public OnFilterScriptInit()
{
    SetTimer("UpdateJP", 30000, true); //Updates the jackpot
    SetTimer("Draw", LOTTO_DRAW*1000*60, true); //Updates the jackpot
    return 1;
}

forward UpdateJP(); //Always forward a timer

public UpdateJP()
{
    Jackpot = Jackpot + LOTTO_JACKPOT; //Ads to the lotto jackpot
    return 1;
}
Now that we have that out of the way, we are going to do the command in DCMD

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(lotto, 5, cmdtext);
    return 0;
}

dcmd_lotto(playerid, params[])
{
    if(!strlen(params)) //If the player doesn't put a nubmer
    {
        SendClientMessage(playerid, 0x62FF32FF, "***Lotto information***"); //Lotto info
        SendClientMessage(playerid, 0x62FF32FF, "Pick a number between 1 and 100 with /lotto [1-100]"); //Lotto info
        new str[75]; //Creates the string
        format(str, sizeof(str), "Current Jackpot is $%d!!!!", Jackpot); //Formats the jackpot string
        SendClientMessage(playerid, 0x62FF32FF, str); //Shows the current jackpot
    }
    new Num = strval(params); //Makes the param that the player entered into a intiger
    if(Numbers[Num] == 1) //If the number is used
    {
        new str[75]; //Makes a variable
        format(str, sizeof(str), "Lotto number %d is already taken!", Num); //Formats a str
        SendClientMessage(playerid, 0xE21F1FFF, str); //Sends the message
        return 1;
    }
    if(GetPVarInt(playerid, "LottoNumber") != 0) return SendClientMessage(playerid, 0xE21F1FFF, "You have already got a lotto number");
    SetPVarInt(playerid, "LottoNumber", Num); //Sets the players number
    Numbers[Num] = 1; //Number is used
    GivePlayerMoney(playerid, -TICKET_COST); //Takes away the ticket cost.
    new str[75];
    format(str, sizeof(str), " Lotto ticket brought! You now have number %d for the next draw", Num);
    SendClientMessage(playerid, 0x62FF32FF, str); //Lotto info
    format(str, sizeof(str), " Draws are held every %d minutes and the winners are announced. Current jackpot is $%d", LOTTO_DRAW, Jackpot);
    Jackpot = Jackpot + LOTTO_JACKPOT; //Ads to the lotto jackpot
    SendClientMessage(playerid, 0x62FF32FF, str); //Lotto info
    return 1;
}
Now for the actual lotto draw (Picks a random number between 0 and 100, checks against all players numbers and if the player has that number they win).

pawn Код:
forward Draw();
public Draw()
{
    new Lnum = random(100) + 1; //Picks a random number
    new winner = -1; //Winners ID variable
    for(new i; i<MAX_PLAYERS; i++) //checks through all players
    {
        if(!IsPlayerConnected(i)) continue; //Players not connected
        if(GetPVarInt(i, "LottoNumber") == Lnum) winner = i; //If the players number is the winning number
        SetPVarInt(i, "LottoNumber", 0); //Resets the number
    }
    if(winner != -1) //If there was a winner
    {
        new Pname[24];
        GetPlayerName(winner, Pname, 24);
        new str[100];
        SendClientMessageToAll(0x62FF32FF, "****LOTTO INFORMATION****"); //Lotto info
        format(str, sizeof(str), "WE HAVE A WINNER! %s(%d) won $%d!!!!", Pname, winner, Jackpot);
        SendClientMessageToAll(0x62FF32FF, str); //Lotto info
        SendClientMessageToAll(0x62FF32FF, "Make sure you get a ticket for next draw /lotto [1-100]!!"); //Lotto info
        GivePlayerMoney(winner, Jackpot); //Gives the winner the cash
        Jackpot = LOTTO_START; //Resets the jackpot
    }
    if(winner == -1) //No winner
    {
                new str[100];
        SendClientMessageToAll(0x62FF32FF, "****LOTTO INFORMATION****"); //Lotto info
        format(str, sizeof(str), "There was no lotto winner for this draw. The jackpot will go up to $%d!", Jackpot);
        SendClientMessageToAll(0x62FF32FF, str); //Lotto info
        SendClientMessageToAll(0x62FF32FF, "Make sure you get a ticket for next draw /lotto [1-100]!!");
    }
    for(new s; s<100; s++)
    {
        Numbers[s] = 0; //Resets all numbers so they are usable.
    }
    return 1;
}
Hope you enjoyed this tutorial, feal free to post bugs/comments .


Re: [TUT]Lotto script - willsuckformoney - 15.07.2010

moO! tanks and FIRST MOOWNED


Re: [TUT]Lotto script - jamesbond007 - 15.07.2010

a simple and stupid mistake will ruin everything

Код:
dcmd(lotto, 4, cmdtext);



Re: [TUT]Lotto script - [HiC]TheKiller - 15.07.2010

Quote:
Originally Posted by jamesbond007
Посмотреть сообщение
a simple and stupid mistake will ruin everything

Код:
dcmd(lotto, 4, cmdtext);
Yea,h my bad, tired as lol.


Re: [TUT]Lotto script - jamesbond007 - 15.07.2010

other then that awesome script! good tutorial i will use it sometime soon!


Re: [TUT]Lotto script - Aleluja - 15.07.2010

nice tutorial TheKiller


Re: [TUT]Lotto script - ViruZZzZ_ChiLLL - 15.07.2010

Another awesome and useful tutorial [HiC]TheKiller :P


Re: [TUT]Lotto script - Kar - 16.07.2010

wow finally this is exactly what i f-***in wanted


Re: [TUT]Lotto script - FireCat - 16.07.2010

nice thekiller


Re: [TUT]Lotto script - Amit_B - 17.07.2010

Where's the tutorial?
You've just posted your own lotto system and teached where to put every code in the script.


Re: [TUT]Lotto script - DiddyBop - 17.07.2010

Quote:
Originally Posted by Amit_B
View Post
Where's the tutorial?
You've just posted your own lotto system and teached where to put every code in the script.
stfu wurs your tut.


Re: [TUT]Lotto script - willsuckformoney - 17.07.2010

Quote:
Originally Posted by LilGunna
View Post
stfu wurs your tut.
OWNED & u go piggy


Re: [TUT]Lotto script - [HiC]TheKiller - 17.07.2010

Quote:
Originally Posted by Amit_B
View Post
Where's the tutorial?
You've just posted your own lotto system and teached where to put every code in the script.
You need glasses... Every line is commented for what it does and what it's for.


Re: [TUT]Lotto script - Amit_B - 18.07.2010

Quote:
Originally Posted by [HiC]TheKiller
View Post
You need glasses... Every line is commented for what it does and what it's for.
Oh okay, did'nt saw it.
Good work


Re: [TUT]Lotto script - Kar - 18.07.2010

could you make one where its automatic whereas lotto automatically starts at 12:am night and updates ++ every 4 hours maybe then draws at 20:00/8pm<.<


Re: [TUT]Lotto script - Scenario - 19.07.2010

Oh, cool. I didn't plan to integrate a lotto system into my new script, but this changed my mind. I hope its efficient, haha!


Re: [TUT]Lotto script - [HiC]TheKiller - 19.07.2010

Quote:
Originally Posted by RealCop228
View Post
Oh, cool. I didn't plan to integrate a lotto system into my new script, but this changed my mind. I hope its efficient, haha!
Yeah, most of the lotto script is pretty efficient .


Re: [TUT]Lotto script - Scenario - 19.07.2010

Quote:
Originally Posted by [HiC]TheKiller
View Post
Yeah, most of the lotto script is pretty efficient .
Fantastic! I think I will make it in ZCMD though, that's my plan.


Re: [TUT]Lotto script - Juve913 - 23.07.2010

wow perfect job HiC i must say !
JuVe here

Btw can u PM me or even better to help people post that lotto system but make it showing off at the bottom of the screen (Like CB ) u know ;p

Can u make me something like that?I would appreciate it


Re: [TUT]Lotto script - Armin_Avdic - 23.07.2010

Whoa nice work man really really good