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
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;
}
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;
}
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;
}
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;
Using 256 cells for a string that only requires 128, 3 damn times.
|