Lotto command help
#1

Hello,i need a little help with my /lotto command.The problem is,if i type just /lotto it will automatically buy the number 0,how to fix this?I think params are working.

pawn Код:
CMD:lotto(playerid, params[])
{
    if(!strlen(params)) return SendClientMessage(playerid,0xFF0000FF, "Pick a number between 1 and 50 with /lotto [50]");
    new Num = strval(params);
    if(GetPlayerMoney(playerid) <500) return SendClientMessage(playerid,0xAA3333AA, "You don't have 500$ to buy a lotto number.");
    new strl[128];
    format(strl, sizeof(strl), "Current Lotto Jackpot is {F70505}%d$", Jackpot);
    SendClientMessage(playerid, COLOR_BLUE, strl);
    if(Numbers[Num] == 1)
    {
        new str[75];
        format(str, sizeof(str), "Lotto number %d is already taken,choose another.", Num);
        SendClientMessage(playerid, 0xE21F1FFF, str);
        return 1;
    }
    if(GetPVarInt(playerid, "LottoNumber") != 0) return SendClientMessage(playerid, ORANGE, "You have already selected a lotto number,good luck!");
    Numbers[Num] = 1;
    new str[140];
    GivePlayerMoney(playerid, -TICKET_COST);
    SetPVarInt(playerid, "LottoNumber", Num);
    format(str, sizeof(str), "Lotto number %d bought! Good luck baby!", Num);
    SendClientMessage(playerid, COLOR_WHITE, str);
    format(str, sizeof(str), "Draws are held every %d minutes and the winners are announced on global chat. Current jackpot is ***%d$***", LOTTO_DRAW, Jackpot);
    Jackpot = Jackpot + LOTTO_JACKPOT;
    SendClientMessage(playerid, 0x62FF32FF, str);
    return 1;
}
Thanks.
Reply
#2

strlen doesn't work for me.
Maybe try using sscanf?
Reply
#3

Quote:
Originally Posted by SaYrOn
Посмотреть сообщение
Best option is to use sscanf, but if for some reason you don't want to, you can use the old strtok way:
Код:
new tmp;
new cmd[50];
cmd = strtok(params, tmp);
if(!strlen(cmd))
{
          ...
}
That's not reccomended, sscanf is much easier, faster and modern.
No i don't want to you strtok,thanks anyways.

Quote:
Originally Posted by Romel
Посмотреть сообщение
strlen doesn't work for me.
Maybe try using sscanf?
Thank you,i used sscanf params and it works.
Reply
#4

For extras: it says in the ZCMD topic that you should use isnull because params is never empty.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)