SA-MP Forums Archive
Check if numeric - 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: Check if numeric (/showthread.php?tid=227027)



Check if numeric - Anteino - 16.02.2011

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


Re: Check if numeric - randomkid88 - 16.02.2011

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.


Re: Check if numeric - Hal - 16.02.2011

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?


AW: Check if numeric - thiaZ_ - 16.02.2011

//Or that^

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


Re: AW: Check if numeric - Hal - 16.02.2011

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.


Re: Check if numeric - Anteino - 16.02.2011

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?


Re: Check if numeric - Calgon - 16.02.2011

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