Getting numbers with dialogs - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Getting numbers with dialogs (
/showthread.php?tid=206371)
fixed -
Haydz - 03.01.2011
Fixed
Re: Getting numbers with dialogs -
Patrik356b - 03.01.2011
You can use this:
pawn Код:
if(isNumeric(const string[])==false)
{
SendClientMessage(playerid, color, "Invalid ammount!");
return 1;
}
If you have dutils.inc, include it, else, here is the function:
pawn Код:
stock isNumeric(const string[]) {
new length=strlen(string);
if (length==0) return false;
for (new i = 0; i < length; i++) {
if (
(string[i] > '9' || string[i] < '0' && string[i]!='-' && string[i]!='+') // Not a number,'+' or '-'
|| (string[i]=='-' && i!=0) // A '-' but not at first.
|| (string[i]=='+' && i!=0) // A '+' but not at first.
) return false;
}
if (length==1 && (string[0]=='-' || string[0]=='+')) return false;
return true;
}
Re: Getting numbers with dialogs -
Haydz - 03.01.2011
Quote:
Originally Posted by Patrik356b
You can use this:
pawn Код:
if(isNumeric(const string[])==false) { SendClientMessage(playerid, color, "Invalid ammount!"); return 1; }
If you have dutils.inc, include it, else, here is the function:
pawn Код:
stock isNumeric(const string[]) { new length=strlen(string); if (length==0) return false; for (new i = 0; i < length; i++) { if ( (string[i] > '9' || string[i] < '0' && string[i]!='-' && string[i]!='+') // Not a number,'+' or '-' || (string[i]=='-' && i!=0) // A '-' but not at first. || (string[i]=='+' && i!=0) // A '+' but not at first. ) return false; } if (length==1 && (string[0]=='-' || string[0]=='+')) return false; return true; }
|
Ah, cheers for that man. any idea about tracking the params which gets typed into the dialog and then make that into "amount"
edit: tryed something like this, is it meant to be inserted in the dialog response or as like a stock. and yeh i have #include <dutils> also.
pawn Код:
if(dialogid == DUELWAGER && response == 1)
{
if(isNumeric(const string[])==false) return SendClientMessage(playerid, COLOR_RED, "Invalid ammount!");
Re: Getting numbers with dialogs -
Vince - 03.01.2011
pawn Код:
new
amount = strval(inputtext);
if(!(10 <= amount <= 10000)) // Min 10, max 10000 - change these if you like
return SendClientMessage(playerid, COLOR_RED, "Invalid Amount!");
Would work just fine.
Re: Getting numbers with dialogs -
Haydz - 03.01.2011
Quote:
Originally Posted by Vince
pawn Код:
new amount = strval(inputtext);
if(!(10 <= amount <= 10000)) // Min 10, max 10000 - change these if you like return SendClientMessage(playerid, COLOR_RED, "Invalid Amount!");
Would work just fine.
|
Thanks so much thats works.