Name checker
#1

Hey guys, I need the RolePlayNameChecker. I ******d, but I need Checker which will check for "_", then first letter of name and surname need to be capital letters, and to check for numbers in player's nick. Thank you.
Reply
#2

pawn Код:
stock NameCheck(const source[])
{
    new
        length = strlen(source);
   
    if (!(3 <= length <= 20)) return 0;
   
    new
        pos = strfind(source, "_");
   
    if (pos == -1) return 0;
   
    new
        us_count;
   
    for (new i; i != length; ++i)
    {
        switch (source[i])
        {
            case '_': ++us_count;
        }
       
        if (!i || i == pos + 1)
        {
            switch (source[i])
            {
                case 'A' .. 'Z': continue;
                default: return 0;
            }
        }
        else if (i && i != pos && i != pos + 1)
        {
            switch (source[i])
            {
                case 'a' .. 'z': continue;
                default: return 0;
            }
        }
    }
    return (us_count == 1 && source[length - 1] != '_');
}
Reply
#3

Could you explain me, how this works, what I need to do?

Thank you for fast answer. REP+ for you.
Reply
#4

It returns 1 if the name is valid (1 underscore only, the first letters of name/surname to be capital and the rest lowercase, not containing numbers or any other character other than alphabet letters and not underscore in the beginning or end of the name).

An example:
pawn Код:
public OnPlayerConnect(playerid)
{
    new
        sz_Name[MAX_PLAYER_NAME];
   
    GetPlayerName(playerid, sz_Name, MAX_PLAYER_NAME);
   
    if (!NameCheck(sz_Name))
    {
        // invalid name..
        // Kick..
        return 1;
    }
    // rest of code..
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)