SA-MP Forums Archive
Limit the input - 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: Limit the input (/showthread.php?tid=406235)



Limit the input - iRenegade - 09.01.2013

Hi guys, I got a quick question. Help is highly appreciated!

I'm building a lotto script, and I'm currently working on ticket purchase system. Everything is pretty much self explanatory: The player types /lotto 1-100, gets 100$ removed and gets a ticket. However, I can't seem to understand how to limit the input to 1-100. Because now, I can do /lotto 'anything' and it will show the ticket as 'Your lotto ticket number: 'anything'. I tried using > < <= signs, but they don't show any effect.

So the question is pretty simple: how do I limit the input to 1-100?

My code:
Код:
	if (strcmp (cmd, "/lotto", true)==0)                                     
	{
        new tmp[28];
		tmp = strtok(cmdtext, idx);
		if(strlen(tmp) == 0) return SendClientMessage(playerid, 0xDC143CAA, "USAGE: /lotto [1-100]"); //This one works
		if(strlen(tmp) < (1)) return SendClientMessage(playerid, 0xDC143CAA, "USAGE: /lotto [1-100]"); //This one is somewhy ignored
		if(strlen(tmp) > (100)) return SendClientMessage(playerid, 0xDC143CAA, "USAGE: /lotto [1-100]"); //This one is somewhy ignored
		if(strlen(tmp) <= (100))
		SendClientMessage(playerid, 0x10F441AA, "You have purchased a lotto ticket!");
		SendClientMessage(playerid, 0x10F441AA, tmp);
		SendClientMessage(playerid, 0x10F441AA, "Wait for the draw.. Good luck!");
		return 1;
	}
Thank you very much!

PS. Ignore that it doesn't really convert the input into an actual ticket number, it's just to see if everything works in the input type.


Re: Limit the input - Vince - 09.01.2013

Strlen gets the length of the string, not its contents (hence string length). See strval.


Re: Limit the input - mrtms - 09.01.2013

Well start with this first. Did you try to print the value tmp so for example try putting this right under the tmp variable.

printf("Text: %d",tmp);

That will let you see if the text is even being printed inside the CMD when you run your server.


Re: Limit the input - LetsOWN[PL] - 09.01.2013

Hey.
I'd recommend you to use sscanf and zcmd inc's.
Here's a working code for that:
pawn Код:
COMMAND:lotto(playerid, params[])
{
new Number;
if(!sscanf(params, "d", Number))
{
    SendClientMessage(playerid, 0xFF0000FF, "USAGE: Lotto [1-100]"); // if they write something like: /lotto or /lotto blabla
    return 1;
}
if(Number < 1 || Number > 100)
{
    SendClientMessage(playerid, 0xFF0000FF, "USAGE: Lotto [1-100]"); // if they write /lotto -3; /lotto 0; /lotto 101
    return 1;
}
SendClientMessage(playerid, 0x10F441AA, "You have purchased a lotto ticket!");
SendClientMessage(playerid, 0x10F441AA, "Wait for the draw.. Good luck!");

return 1;
}
Greetz,
LetsOWN



Re: Limit the input - iRenegade - 09.01.2013

Oh damn, thank you Vince! I'll update my progress soon.
Mrtms, look at the code more carefully:
Код:
SendClientMessage(playerid, 0x10F441AA, tmp);
Thank you LetsOWN[PL]! I'll put that into my code! I'll update if I get any more problems.

Umm.. Which part of the script do I put your code into?


Re: Limit the input - LetsOWN[PL] - 09.01.2013

Hey.
You can paste it anywhere you want. I'd recommend you to paste it to the very bottom of your script, like other commands. You can orientate in the script a way better then

Greetz,
LetsOWN



Re: Limit the input - iRenegade - 09.01.2013

Pardon me for a silly question.. I've never used COMMAND:, it tells me that 'lotto' is never used. I'm used to making commands in the 'onplayercommandtext'
COMMAND:lotto(playerid, params[])
Any ideas?


Re: Limit the input - LetsOWN[PL] - 09.01.2013

Please make sure that COMMAND:lotto(playerid, params[]) is not under any public and that there is #include <zcmd> line on the top of your script and you've latest version of this include in your Include folder.

Greetz,
LetsOWN



Re: Limit the input - iRenegade - 09.01.2013

That's the problem - I don't have ZCMD in my include folder. Thank you, setting that up!


Re: Limit the input - mastermax7777 - 09.01.2013

use strval()