05.04.2013, 20:38
(
Last edited by L.Hudson; 05/04/2013 at 09:55 PM.
)
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.
Step.2
Using sscanf and ZCMD we are gonna procceed on scripting the commands.
For administrators:
For players:
Step.3
Lastly, putting the timer.
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.
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
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;
}
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;
}
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.