SA-MP Forums Archive
Lotto command help - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Lotto command help (/showthread.php?tid=382602)



Lotto command help - Face9000 - 04.10.2012

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.


Re: Lotto command help - JaKe Elite - 04.10.2012

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


Re: Lotto command help - Face9000 - 04.10.2012

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.


Re: Lotto command help - Vince - 04.10.2012

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