Lottery issue - an error with an IF sentence + indicators +REP
#1

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.


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(playeridparams[])
{
    if(
GetAdminLevel(playerid) < 10) return SendClientError(playeridCANT_USE_CMD);
    if( 
sscanf params"ud"iLottoNumberiAmountLiTicketsiPrize))  return SCP(playerid"[WinningTicket] [TicketPrice] [TicketRange] [Reward]");
    if(
IsLottoStarted == true) return SendClientError(playerid"There's an ongoing lottery!");
 else
 {
    
IsLottoStarted=true;
    
format(lStringsizeof(lString), "{0520f2}================== [ {5ba8de} LOTTERY {0520f2} ] ==================");
    
format(lString1sizeof(lString1), "{5ba8de}Admin %s has started lottery. The entry fee is: %d$. The tickets range from 0 - %d."RPName(playerid), iAmountLiTickets);
    
format(lString2sizeof(lString2), "{5ba8de}The winner will receive %s as a reward. Goodluck and Have fun!"iPrize);
    
format(lString3sizeof(lString3), "{0520f2}================== [ {5ba8de} LOTTERY {0520f2} ] ==================");
    
SendClientMessageToAll(COLOR_WHITElString);
    
SendClientMessageToAll(COLOR_WHITElString1);
    
SendClientMessageToAll(COLOR_WHITElString2);
    
SendClientMessageToAll(COLOR_WHITElString3);
    }
    
    return 
1;
}
new 
lString10[MAX_STRING];
new 
lString11[MAX_STRING];
new 
loseSTRING11[MAX_STRING];
COMMAND:lot(playeridparams[])
{
    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(playeridCOLOR_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(lString10sizeof(lString10), "{0520f2}================== [ {5ba8de}LOTTERY {0520f2} ] ==================");
        
format(lString8sizeof(lString8), "{5ba8de}%s has won the lottery with the number: %d! Prize: %s"RPName(playerid), iLottoNumberiPrize);
        
format(lString9sizeof(lString9), "{5ba8de}In the lottery, players spent %i$! That's impressive!"iSpent);
        
format(lString11sizeof(lString11), "{0520f2}================== [ {5ba8de} LOTTERY {0520f2} ] ==================");
        
SendClientMessageToAll(COLOR_WHITElString8);
        
SendClientMessageToAll(COLOR_WHITElString9);
        
SendClientMessageToAll(COLOR_WHITElString10);
        
SendClientMessageToAll(COLOR_WHITElString11);
        
IsLottoStarted=false;
        
iLottoNumber 0;
        
iAmountL 0;
        
iSpent 0;
        
iTickets 0;
        
GivePlayerMoneyEx(playerid, -iAmountL);
     }
     else
    {
    
iSpent iAmountL iSpent;
    
format(loseSTRING11sizeof(loseSTRING11), "{0520f2}[Lottery] {5ba8de} Sorry! You did not guess the number correctly. Good luck in your next attempt!"iAmountL);
        
SendClientMessageToAll(COLOR_WHITEloseSTRING11);
        
GivePlayerMoneyEx(playerid, -iAmountL);
    }
    
    return 
1;
}
new 
lendString[MAX_STRING];
new 
lendString2[MAX_STRING];
new 
lendString3[MAX_STRING];
new 
lendString4[MAX_STRING];
COMMAND:stoplotto(playeridparams[])
{
        if(
IsLottoStarted == true)
        {
        
IsLottoStarted false;
         
format(lendString3sizeof(lendString3), "{0520f2}================== [ {5ba8de}LOTTERY{0520f2} ] ==================");
        
format(lendString2sizeof(lendString2), "{5ba8de}Admin %s has stopped the lottery. The winning ticket was %d!.  "RPName(playerid), iLottoNumber);
        
format(lendStringsizeof(lendString), "{5ba8de}In the lottery, players spent %i$! That's impressive!"iSpent);
        
format(lendString4sizeof(lendString4), "{0520f2}================== [ {5ba8de}LOTTERY{0520f2} ] ==================");
        
SendClientMessageToAll(COLOR_WHITElendString3);
        
SendClientMessageToAll(COLOR_WHITElendString2);
        
SendClientMessageToAll(COLOR_WHITElendString);
        
SendClientMessageToAll(COLOR_WHITElendString4);
        
iLottoNumber 0;
        
iAmountL 0;
        
iSpent 0;
        
iTickets 0;
        }
        return -
1;

Thanks for the help in advance,
+REPing the helpers! <:
Reply
#2

Try this:
pawn Код:
PHP Code:
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, "iiii", 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, "i", 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(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;
}
Reply
#3

sscanf ( params, "ud", iLottoNumber, iAmountL, iTickets, iPrize )
You are taking 2 variables, shoving them into 4 ? 65565 is INVALID_PLAYER_ID I think, it's because you are using 'u' as the param type
sscanf ( params, "dddd", iLottoNumber, iAmountL, iTickets, iPrize ) << right way
Reply
#4

Quote:
Originally Posted by PrO.GameR
Посмотреть сообщение
sscanf ( params, "ud", iLottoNumber, iAmountL, iTickets, iPrize )
You are taking 2 variables, shoving them into 4 ? 65565 is INVALID_PLAYER_ID I think, it's because you are using 'u' as the param type
sscanf ( params, "dddd", iLottoNumber, iAmountL, iTickets, iPrize ) << right way
Thanks, do you happen to know how can I add ',' between each 3 digits?
e.g: instead of 1000000 -> 1,000,000?
Reply
#5

Well .. not the best way, but I came up with it right now
PHP код:
new string[20];
            
format(stringsizeof(string), "%i"number);
            for(new 
i=strlen(string)-3;i>0;i-=3)
            {
                
strins(string","i);
            } 
This way it starts at very last 3 digits, starts inserting a ',' every 3 digit till it reaches the string[0]
Reply
#6

Reminds me of Italy Mafia.

I pm'ed you the way it's done.
Reply
#7

Quote:
Originally Posted by PrO.GameR
Посмотреть сообщение
Well .. not the best way, but I came up with it right now
PHP код:
new string[20];
            
format(stringsizeof(string), "%i"number);
            for(new 
i=strlen(string)-3;i>0;i-=3)
            {
                
strins(string","i);
            } 
This way it starts at very last 3 digits, starts inserting a ',' every 3 digit till it reaches the string[0]
Or just use AddCommas();

https://sampwiki.blast.hk/wiki/AddCommas
Reply
#8

Quote:
Originally Posted by Michie
Посмотреть сообщение
Reminds me of Italy Mafia.

I pm'ed you the way it's done.
Because it is Italy Mafia.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)