Lottery problem -
L.Hudson - 17.03.2013
Fixed
Re: Lottery problem -
mastermax7777 - 17.03.2013
where do u define/set pLottoNum ? what number does it show in [OwnerMsg]: The number for lotto is %d
also ur forward Lottery(playerid); shouldn't have a playerid in it
Re: Lottery problem -
stabker - 17.03.2013
Try to use it:
pawn Код:
CMD:setlotto(playerid, params[])
{
new string[256], lottonum;
if(!IsPlayerLoggedIn(playerid)) return SCM(playerid, COLOR_GREY, "You must be logged in to use commands.");
if(PlayerInfo[playerid][pAdmin] < 5) return SCM(playerid, COLOR_WHITE, "[{FF0606}ERROR{FFFFFF}]: You have no authorization to use this command.");
if(sscanf(params, "d", lottonum)) return SCM(playerid, COLOR_GREY, "USAGE: /setlotto [prize]");
if(lottonum < 10000 || lottonum > 1500000) return SCM(playerid, COLOR_GREY, "Invalid prize number. Prize must be between $10,000 and $1,500,000.");
if(LottoNum != 0) return SCM(playerid, COLOR_GREY, "There is a lottery already going on.");
else
{
SCMTA(COLOR_ORANGE, "A lottery has started and will end in 30 seconds! Type /lotto to pick your number.");
format(string, sizeof(string), "Prize: $%d", lottonum);
SCMTA(COLOR_ORANGE, string);
LottoNum = random(99)+1;
LottoPrize = lottonum;
SetTimer("Lottery", 30000, false);
format(string, sizeof(string), "[OwnerMsg]: The number for lotto is %d.", LottoNum);
SendAdminMessage(COLOR_LIGHTRED, 7, string);
}
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);
SCMTA(COLOR_ORANGE, string);
foreach(Player, i)
{
//add authorization checks!
if(PlayerInfo[i][pLottoNum] == LottoNum)
{
GetPlayerName(i, name, sizeof(name));
LottoNum = -1;
format(string, sizeof(string), "Congratulations! You have won the lottery of {FFFFFF}$%d.", LottoPrize);
SCM(i, COLOR_GREY, string);
format(string, sizeof(string), "Congratulations to %s! He has won the lottery of $%d!", RPN(i), LottoPrize);
SCMTA(COLOR_ORANGE, string);
GiveZaiatMoney(i, LottoPrize);
LottoPrize = 0;
}
else SCM(i, COLOR_GREY, "You haven't won the lottery! Better luck next time."), PlayerInfo[i][pLottoNum] = 0;
PlayerInfo[i][pLottoNum] = 0;
}
return 1;
}
Re: Lottery problem -
Konstantinos - 17.03.2013
I found your problem.
pawn Код:
// ---
foreach(Player, i)
{
GetPlayerName(i, name, sizeof(name));
if(PlayerInfo[i][pLottoNum] == LottoNum)
{
LottoNum = 0;
format(string, sizeof(string), "Congratulations! You have won the lottery of {FFFFFF}$%d.", LottoPrize);
SCM(i, COLOR_GREY, string);
format(string, sizeof(string), "Congratulations to %s! He has won the lottery of $%d!", RPN(i), LottoPrize);
SCMTA(COLOR_ORANGE, string);
GiveZaiatMoney(i, LottoPrize);
LottoPrize = 0;
}
else
{
LottoNum = 0; // This
SCM(i, COLOR_GREY, "You haven't won the lottery! Better luck next time.");
}
PlayerInfo[i][pLottoNum] = 0;
}
Let's say there are 5 players online and the winner is id 4. It checks if ID 0's pLottoNum is equal to LottoNum. If it's not, it calls the else statement and sets LottoNum to 0. Then it checks if ID 1's pLottoNum is equal to LottoNum which is 0 and it's equal, so the winner is ID 1.
I'd use it like that:
pawn Код:
forward Lottery(playerid);
public Lottery(playerid)
{
new name[MAX_PLAYER_NAME], string[256];
format(string, sizeof(string), "The lottery winning number is %d!",LottoNum);
SCMTA(COLOR_ORANGE, string);
foreach(Player, i)
{
GetPlayerName(i, name, sizeof(name));
if(PlayerInfo[i][pLottoNum] == LottoNum)
{
format(string, sizeof(string), "Congratulations! You have won the lottery of {FFFFFF}$%d.", LottoPrize);
SCM(i, COLOR_GREY, string);
format(string, sizeof(string), "Congratulations to %s! He has won the lottery of $%d!", RPN(i), LottoPrize);
SCMTA(COLOR_ORANGE, string);
GiveZaiatMoney(i, LottoPrize);
LottoNum = 0;
}
else SCM(i, COLOR_GREY, "You haven't won the lottery! Better luck next time.");
PlayerInfo[i][pLottoNum] = 0;
}
LottoPrize = 0;
return 1;
}
Re: Lottery problem -
L.Hudson - 17.03.2013
Thanks Dwane! And everyone else for your attempts of help also.