03.11.2015, 15:18
Hey fellow scripters, I've been working on a lottery feature to my RP server. However I'm experiencing some difficulties. Two, if to be exact.
1) I can't verify who won the lottery - When a user enters the correct number is shows as if he entered a wrong number.
2) The indicators don't show up well(%d, %i, %s) - Most of the time there's an error inwhich it shows that the winning ticket was 65565 when there wasn't even a ticket like that. Also it doesn't show the prize and the possible ticket range.
Here's a photo to demonstrate the 2nd problem(about the indicators)
As you can see, the reward doesn't appear, same goes for the range (0-0 instead of 0-X).
The ticket number is not the real ticket number. It shows up as 65K when I wrote 50.
Code:
/lot - The command you use in order to send a number to the lottery system
/startlotto - The command you use in order to start a lottery
/stoplotto - The command you use in order to stop a lottery.
Thanks for the help in advance,
+REPing the helpers! <:
1) I can't verify who won the lottery - When a user enters the correct number is shows as if he entered a wrong number.
2) The indicators don't show up well(%d, %i, %s) - Most of the time there's an error inwhich it shows that the winning ticket was 65565 when there wasn't even a ticket like that. Also it doesn't show the prize and the possible ticket range.
Here's a photo to demonstrate the 2nd problem(about the indicators)
As you can see, the reward doesn't appear, same goes for the range (0-0 instead of 0-X).
The ticket number is not the real ticket number. It shows up as 65K when I wrote 50.
Code:
/lot - The command you use in order to send a number to the lottery system
/startlotto - The command you use in order to start a lottery
/stoplotto - The command you use in order to stop a lottery.
PHP код:
new iLottoNumber;
new iAmountL;
new iTickets;
new iPrize[MAX_STRING];
new bool:IsLottoStarted=false;
new lString[MAX_STRING];
new lString1[MAX_STRING];
new lString2[MAX_STRING];
new lString3[MAX_STRING];
new lString8[MAX_STRING];
new lString9[MAX_STRING];
new iSpent;
COMMAND:startlotto(playerid, params[])
{
if(GetAdminLevel(playerid) < 10) return SendClientError(playerid, CANT_USE_CMD);
if( sscanf ( params, "ud", iLottoNumber, iAmountL, iTickets, iPrize)) return SCP(playerid, "[WinningTicket] [TicketPrice] [TicketRange] [Reward]");
if(IsLottoStarted == true) return SendClientError(playerid, "There's an ongoing lottery!");
else
{
IsLottoStarted=true;
format(lString, sizeof(lString), "{0520f2}================== [ {5ba8de} LOTTERY {0520f2} ] ==================");
format(lString1, sizeof(lString1), "{5ba8de}Admin %s has started lottery. The entry fee is: %d$. The tickets range from 0 - %d.", RPName(playerid), iAmountL, iTickets);
format(lString2, sizeof(lString2), "{5ba8de}The winner will receive %s as a reward. Goodluck and Have fun!", iPrize);
format(lString3, sizeof(lString3), "{0520f2}================== [ {5ba8de} LOTTERY {0520f2} ] ==================");
SendClientMessageToAll(COLOR_WHITE, lString);
SendClientMessageToAll(COLOR_WHITE, lString1);
SendClientMessageToAll(COLOR_WHITE, lString2);
SendClientMessageToAll(COLOR_WHITE, lString3);
}
return 1;
}
new lString10[MAX_STRING];
new lString11[MAX_STRING];
new loseSTRING11[MAX_STRING];
COMMAND:lot(playerid, params[])
{
new iGuess;
if(IsLottoStarted == false) return SendClientError(playerid, "There aren't any ongoing lotteries!");
if( sscanf ( params, "d", iGuess )) return SCP(playerid, "[Ticket Number]");
if(iAmountL>HandMoney(playerid))
{
SendClientMSG(playerid, COLOR_RED, "{a40000}[ {e80b0b}Error {a40000}]{e83535} You do not have enough money in order to participate in this lottery");
return 1;
}
if(sscanf ( params, "d", iGuess) == iLottoNumber )
{
iSpent = iAmountL + iSpent;
format(lString10, sizeof(lString10), "{0520f2}================== [ {5ba8de}LOTTERY {0520f2} ] ==================");
format(lString8, sizeof(lString8), "{5ba8de}%s has won the lottery with the number: %d! Prize: %s", RPName(playerid), iLottoNumber, iPrize);
format(lString9, sizeof(lString9), "{5ba8de}In the lottery, players spent %i$! That's impressive!", iSpent);
format(lString11, sizeof(lString11), "{0520f2}================== [ {5ba8de} LOTTERY {0520f2} ] ==================");
SendClientMessageToAll(COLOR_WHITE, lString8);
SendClientMessageToAll(COLOR_WHITE, lString9);
SendClientMessageToAll(COLOR_WHITE, lString10);
SendClientMessageToAll(COLOR_WHITE, lString11);
IsLottoStarted=false;
iLottoNumber = 0;
iAmountL = 0;
iSpent = 0;
iTickets = 0;
GivePlayerMoneyEx(playerid, -iAmountL);
}
else
{
iSpent = iAmountL + iSpent;
format(loseSTRING11, sizeof(loseSTRING11), "{0520f2}[Lottery] {5ba8de} Sorry! You did not guess the number correctly. Good luck in your next attempt!", iAmountL);
SendClientMessageToAll(COLOR_WHITE, loseSTRING11);
GivePlayerMoneyEx(playerid, -iAmountL);
}
return 1;
}
new lendString[MAX_STRING];
new lendString2[MAX_STRING];
new lendString3[MAX_STRING];
new lendString4[MAX_STRING];
COMMAND:stoplotto(playerid, params[])
{
if(IsLottoStarted == true)
{
IsLottoStarted = false;
format(lendString3, sizeof(lendString3), "{0520f2}================== [ {5ba8de}LOTTERY{0520f2} ] ==================");
format(lendString2, sizeof(lendString2), "{5ba8de}Admin %s has stopped the lottery. The winning ticket was %d!. ", RPName(playerid), iLottoNumber);
format(lendString, sizeof(lendString), "{5ba8de}In the lottery, players spent %i$! That's impressive!", iSpent);
format(lendString4, sizeof(lendString4), "{0520f2}================== [ {5ba8de}LOTTERY{0520f2} ] ==================");
SendClientMessageToAll(COLOR_WHITE, lendString3);
SendClientMessageToAll(COLOR_WHITE, lendString2);
SendClientMessageToAll(COLOR_WHITE, lendString);
SendClientMessageToAll(COLOR_WHITE, lendString4);
iLottoNumber = 0;
iAmountL = 0;
iSpent = 0;
iTickets = 0;
}
return -1;
}
+REPing the helpers! <: