Check if numeric
#1

mainly I got this code:

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[]){
    new idx, cmd[256], rest[256];
    cmd = strtok(cmdtext, idx);
    strpack(rest, cmdtext);
    strdel(rest, 0, idx + 1);

    if(strfind(cmd, "/race", true) == 0){
        if(strfind(rest, "help", true) == 0) return RaceHelp(playerid);
        if(strfind(rest, "create", true) == 0) return RaceCreate(playerid);
        if(strfind(rest, "checkpoint", true) == 0) return RaceCheckpoint(playerid);
        if(strfind(rest, "end", true) == 0) return RaceEnd(playerid);
        if(strfind(rest, "invite", true) == 0) return RaceInvite(playerid, rest);
        if(strfind(rest, "accept", true) == 0) return RaceAccept(playerid);
        RaceHelp(playerid);
        return 1;
    }
    return 0;
}
Now, if a player inserts /race invite [playerid] a player will be invited trough a stock. But within this stock i tried to create a script to check if the text submitted in [playerid] was numeric, some way it allways is no matter what you give in. I really tried everything:

- strval; but when text is inserted it will be 0, making the script inviting player number 0.
- isnumeric (with #include <YSI/y_utils>); but seems to be allways numeric
- etcetera

Please help :S
Reply
#2

Didn't read... sorry

Look into sscanf by Y-Less. It has a parameter that will use either the player's name or ID. Its a plugin and is much more efficient and can be simpler to use.
Reply
#3

pawn Код:
stock IsNumeric( string[ ] ) { for (new i = 0, j = strlen( string); i < j; i++) if ( string[i] > '9' || string[i] < '0') return 0; return 1; } // thanks to Calgon from VX:RP
This the same one in YSI?
Reply
#4

//Or that^

search for any isNumeric( sInput[ ] ) stock function at pastebin.
Reply
#5

Quote:
Originally Posted by thiaZ_
Посмотреть сообщение
search for any isNumeric( sInput[ ] ) stock function at pastebin.
FYI, not all pastebin material is correctly coded. so you have to be careful when taking things from pastebin. Just like using Wikipedia as your main source for an English essay, you never know what you are gonna get.
Reply
#6

Quote:
Originally Posted by randomkid88
Посмотреть сообщение
Didn't read... sorry

Look into sscanf by Y-Less. It has a parameter that will use either the player's name or ID. Its a plugin and is much more efficient and can be simpler to use.
There is no sscanf, where to find it?
Reply
#7

Search harder next time. Click here for a direct link to the sscanf release thread.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)