SA-MP Forums Archive
ReturnUser and IsNumeric - 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: ReturnUser and IsNumeric (/showthread.php?tid=116292)



ReturnUser and IsNumeric - TheNuttyScientist - 28.12.2009

I've followed the tutorial at wiki.sa-mp.com about creating an admin script.
I also found ReturnUser and IsNumeric when I searched here.
But, how do I use them?


Re: ReturnUser and IsNumeric - dice7 - 28.12.2009

pawn Code:
if(IsNumeric("2345"))
{
  //the string has numbers only
}

new id = ReturnUser("dice");
// 'id' now has the playerid of dice, if he's connected to the server. Else it has INVALID_PLAYER_ID
And here are the 2 functions
pawn Code:
IsNumeric(const string[])
{
    new i;
    while(string[i] != '\0') //end of string
    {
        if (string[i] > '9' || string[i] < '0'){return 0;}
        i++;
    }
    return 1;
}

ReturnUser(text[], playerid = INVALID_PLAYER_ID)
{
    new pos = 0;
    while (text[pos] < 0x21)
    {
        if (text[pos] == 0) return INVALID_PLAYER_ID;
        pos++;
    }

    new userid = INVALID_PLAYER_ID;
    if (IsNumeric(text[pos]))
    {
        userid = strval(text[pos]);
        if (userid >=0 && userid < MAX_PLAYERS)
        {
            if(!IsPlayerConnected(userid))
            userid = INVALID_PLAYER_ID;
            else return userid;
        }
    }

    new len = strlen(text[pos]);
    new count = 0;
    new pname[MAX_PLAYER_NAME];

    for (new i = 0; i < MAX_PLAYERS; i++)
    {
        if (IsPlayerConnected(i))
        {
            GetPlayerName(i, pname, sizeof (pname));
            if (strcmp(pname, text[pos], true, len) == 0)
            {
                if (len == strlen(pname)) return i;
                else
                {
                    count++;
                    userid = i;
                }
            }
        }
    }
   
    if (count != 1)
    {
        if (playerid != INVALID_PLAYER_ID)
        {
            if (count) SendClientMessage(playerid, COLOR_WHITE, "Enter the full name of the user.");
            else SendClientMessage(playerid, COLOR_GREY, "No results found for the specified phrase.");
        }
        userid = INVALID_PLAYER_ID;
    }
    return userid;
}



Re: ReturnUser and IsNumeric - TheNuttyScientist - 28.12.2009

ok, where should I put it?