SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 05/04/2013, 08:38 PM   #1
L.Hudson
Huge Clucker
 
L.Hudson's Avatar
 
Join Date: Jul 2012
Location: Fairy Tail, Fiore
Posts: 227
Reputation: 16
Default Simple Lottery System [ZCMD | SSCANF]

Introduction
This is a simple and custom Lottery System that I started scripting a while ago and decided to publish it now. The Lottery System scripting tutorial will include a command for players to pick their number and a command for administrators to set the lotto price.

Scripting

Step.1
Under our defines section we put two new variables which will include the Lotto Number and the prize.
pawn Code:
new LottoNum; // The Lottery Number
new LottoPrize; // The prize of the lotto
new LottoNumber[MAX_PLAYERS]; // The variable for the lottery number of the player

Step.2
Using sscanf and ZCMD we are gonna procceed on scripting the commands.

For administrators:

pawn Code:
CMD:setlotto(playerid, params[])
{
    new string[256], lottopr;
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "[{FF0606}ERROR{FFFFFF}]: You have no authorization to use this command."); // If the player isnt logged in the RCON
    if(sscanf(params, "d", lottopr)) return SendClientMessage(playerid, -1, "Syntax: {FF9900}/setlotto <prize>"); // SSCANF, if you didn't type a prize the message /setlotto <prize> will show up as a syntax error
    if(lottopr < 10000 || lottopr > 5000000) return SendClientMessage(playerid, -1, "Invalid prize number. Prize must be between $10,000 and $5,000,000."); // Surpassing the prize limit
    if(LottoNum != 0) return SendClientMessage(playerid, -1, "There is a lottery already going on."); // Chking if there is a lottery already going on
    else
    {
        SendClientMessageToAll(-1, "A lottery has started and will end in 30 seconds! Type /lotto($100) to pick your number.");
        format(string, sizeof(string), "Prize: $%d", lottopr);
        SendClientMessageToAll(-1, string); // Sending the message to all players online
        LottoNum = 1 + random(80); // Setting the lotto number to 1 or more with a maximum of 80
        LottoPrize = lottopr; // Setting the prize of the lottery
        SetTimer("Lottery", 30000, false); // The timer until the lottery is finished
    }
    return 1;
}


For players:
pawn Code:
CMD:lotto(playerid, params[])
{
    new string[256], number;
    if(sscanf(params, "d", number)) return SendClientMessage(playerid, -1, "Syntax: {FF9900}/lotto <number>"); // SSCANF, if the player didn't type a number a syntax error message will show up
    if(LottoNumber[playerid] > 0) return SendClientMessage(playerid, -1, "You already have a lotto number."); // Check if the player has already a lottery number
    if(number < 1 || number > 80) return SendClientMessage(playerid, -1, "Invalid lotto number. Number must be between 1 and 80."); // Checks if the player surpassed the lottery number litmit.
    if(LottoNum == 0) return SendClientMessage(playerid, -1, "There is not a lottery going on."); // Checks if there is a lottery going on
    else
    {
        format(string, sizeof(string), "You picked number %d for the lottery.", number);
        SendClientMessage(playerid, -1, string); // Sends a message to the player informing him about his number pick
        LottoNumber[playerid] = number; // Setting the player's lotto number
        GivePlayerMoney(playerid, -100); // Takes away $100 from the player for the lottery ticket
    }
    return 1;
}

Step.3
Lastly, putting the timer.

pawn Code:
forward Lottery(playerid);
public Lottery(playerid)
{
    new name[MAX_PLAYER_NAME], string[256];
    format(string, sizeof(string), "The lottery winning number is %d!",LottoNum);
    SendClientMessageToAll(COLOR_ORANGE, string); // Sends a message to players online stating the winning number
    foreach(Player, i) // Gets every player nline
    {
        GetPlayerName(i, name, sizeof(name)); // Gets their name
        if(LottoNumber[i] == LottoNum) // Checks if the player's number is equal to the lottery number
        {
            format(string, sizeof(string), "Congratulations! You have won the lottery of {FFFFFF}$%d.", LottoPrize);
            SendClientMessage(i, -1, string); // Sending a message to the winner saying he won the lottery
            format(string, sizeof(string), "Congratulations to %s! He has won the lottery of $%d!", RPN(i), LottoPrize);
            SendClientMessageToAll(-1, string); // Announces the winner and the prize of the lottery set
            GivePlayerMoney(i, LottoPrize); // Gives the money to the winner
            break; // Completely stops the loop
        }
        else SendClientMessage(i, -1, "You haven't won the lottery! Better luck next time."); // If the player didn't win a message is sent to him
    }
    foreach(Player, i) LottoNumber[i] = 0; // Setting every player's online lottery number to 0
    LottoNum = 0; // Setting the Lottery Winning Number to 0
    LottoPrize = 0; // Setting the Lottery Prize to 0
    return 1;
}

Benefits
This simple lottery system can entertain your players and give them a chance to earn fast cash, if they are lucky that is.

Extra Notes
If you noticed that something didn't work properly or the tutorial wasn't helpful, let me know.

This system is totaly custom and not copied. You can use this command however you like. For future updates I might be adding some textdraws or a more advanced winning method.

Thank you for taking your time and reading this tutorial.

Last edited by L.Hudson; 05/04/2013 at 09:55 PM.
L.Hudson is offline   Reply With Quote
Old 05/04/2013, 09:31 PM   #2
ervinmasic
Big Clucker
 
Join Date: Mar 2013
Posts: 55
Reputation: 0
Default Re: Simple Lottery System [ZCMD | SSCANF]

Thanks man this is so good (Y)
ervinmasic is offline   Reply With Quote
Old 05/04/2013, 09:33 PM   #3
L.Hudson
Huge Clucker
 
L.Hudson's Avatar
 
Join Date: Jul 2012
Location: Fairy Tail, Fiore
Posts: 227
Reputation: 16
Default Re: Simple Lottery System [ZCMD | SSCANF]

Quote:
Originally Posted by ervinmasic View Post
Thanks man this is so good (Y)
Thanks!

Last edited by L.Hudson; 10/12/2013 at 03:35 PM.
L.Hudson is offline   Reply With Quote
Old 27/02/2014, 12:16 PM   #4
rakshith122
Huge Clucker
 
Join Date: Nov 2013
Location: Soviet Russia
Posts: 241
Reputation: 4
Default Re: Simple Lottery System [ZCMD | SSCANF]

Good job!
rakshith122 is offline   Reply With Quote
Old 19/04/2014, 03:28 PM   #5
danish007
Huge Clucker
 
danish007's Avatar
 
Join Date: Apr 2014
Posts: 445
Reputation: 26
Default Re: Simple Lottery System [ZCMD | SSCANF]

Can u Add Pastebin Link?
danish007 is offline   Reply With Quote
Old 23/11/2014, 07:18 PM   #6
Somalez
Big Clucker
 
Join Date: Jun 2014
Location: Bucharest , Romania
Posts: 54
Reputation: 0
Default Re: Simple Lottery System [ZCMD | SSCANF]

Is it possible that instead of prize based on money to be whatever you want? I mean i want for example to put a vehicle or a house and by this i mean just won text no need for automatically giving the prize
Somalez is offline   Reply With Quote
Old 23/11/2014, 08:38 PM   #7
Flori
Huge Clucker
 
Flori's Avatar
 
Join Date: Sep 2014
Location: Germany
Posts: 396
Reputation: 26
Default AW: Simple Lottery System [ZCMD | SSCANF]

Well done man. Interesting.
Flori is offline   Reply With Quote
Old 23/11/2014, 09:25 PM   #8
LeXuZ
Huge Clucker
 
Join Date: Oct 2014
Location: United Kingdom
Posts: 305
Reputation: 12
Default Re: Simple Lottery System [ZCMD | SSCANF]

Looks good, Maybe you could make it so admins do not have to setlotto, have it like auto timer, so every 30 minutes lotto will be drawn, winner gets money, lotto reset, and over and over, would make it really cool!
LeXuZ is offline   Reply With Quote
Old 25/11/2014, 10:16 PM   #9
sammp
Gangsta
 
sammp's Avatar
 
Join Date: Jan 2014
Posts: 616
Reputation: 49
Default Re: Simple Lottery System [ZCMD | SSCANF]

Using 256 cells for a string that only requires 128, 3 damned times.


pawn Code:
foreach(Player, i) LottoNumber[i] = 0; // Setting every player's online lottery number to 0
    LottoNum = 0; // Setting the Lottery Winning Number to 0
    LottoPrize = 0;

Why are you setting all of these variables outside of the loop?

Just an observation
__________________
SA-MP must become open-source to maximise longetivity of the project.
sammp is offline   Reply With Quote
Old 02/01/2015, 08:11 AM   #10
SecretBoss
Gangsta
 
SecretBoss's Avatar
 
Join Date: Dec 2014
Location: Greece
Posts: 818
Reputation: 103
Default Re: Simple Lottery System [ZCMD | SSCANF]

Compile error

pawn Code:
C:\Users\Nikos\Desktop\Server\Agamemode\gamemodes\blank.pwn(1358) : warning 235: public function lacks forward declaration (symbol "Lottery")
C:\Users\Nikos\Desktop\Server\Agamemode\gamemodes\blank.pwn(1370) : error 017: undefined symbol "RPN"
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


1 Error.
__________________
SecretBoss is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] Making a simple PM system with ZCMD & sscanf Toni Tutorials 36 30/04/2018 01:24 PM
[Tutorial] Simple zcmd and sscanf Tutorial [Explained] GAMER_PS2 Tutorials 20 10/03/2016 10:33 AM
[Tutorial] Simple Ingame Mapper system [Yini|sscanf|zcmd|streamer] faff Tutorials 15 29/04/2014 01:46 AM
[Tutorial] Making a very simple VIP system with /setvip command using dini+sscanf+ZCMD electrux Tutorials 2 25/07/2012 09:00 AM
[Tutorial] Simple Private Message System Using zCMD And Sscanf with Logs Jason_Thunde Tutorials 3 19/10/2011 08:59 PM


All times are GMT. The time now is 05:25 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.