Getting numbers with dialogs
#1

Fixed
Reply
#2

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;
}
Reply
#3

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!");
Reply
#4

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.
Reply
#5

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)