[Include] IsARolePlayName
#1

Yo, just putting it here so people can find it since it's so hard to find otherwise


It makes sure a string contains a upper-case first character, one underscore and a upper-case letter after that. It also checks for illegal characters and only allows A-Z and a-z.
pawn Код:
stock IsARolePlayName(name[])
{
    new
                szLastCell,
        bool:   bUnderScore;
       
    for(new i; i < strlen(name); i++)
    {
        if(name[i] == '_')
        {
            if(bUnderScore == true)
            {
                return 0;
            }
           
            bUnderScore = true;
        }
       
        else if(!szLastCell || szLastCell == '_') // Check if capitalized where it should be
        {
            if(name[i] < 'A' || name[i] > 'Z')
            {
                return 0;
            }
        }
       
        else
        {
            if(name[i] < 'a' || name[i] > 'z')
                return 0;
        }
       
        szLastCell = name[i];
    }
   
    if(bUnderScore == false)
        return 0;
       
    return 1;
}
It can also be found on pastebin: http://pastebin.com/fDXPduZU
Reply
#2

Really good job man!
Reply
#3

Nice one Lenny
Reply
#4

Why this must be an include ? It's just a function ...
Btw, well done
Reply
#5

Very nice function.
Reply
#6

Quote:
Originally Posted by MoroDan
Посмотреть сообщение
Why this must be an include ? It's just a function ...
Btw, well done
It does very much not need to be an include, but if I got to choose I'd use it as an include
Reply
#7

NVM, didn't realise there was a loop.
Reply
#8

Quote:
Originally Posted by [HiC]TheKiller
Посмотреть сообщение
pawn Код:
if(bUnderScore == true)
{
    return 0;
}
bUnderScore = true;
It's probably not going to be true if you are setting it to be true after the if statement .
Thats the point! You can only have one underscore.
Anyway, i can show you my(well, not 100% mine) system. It's a bit more advanced.
It returns 1 if nick is invalid.
pawn Код:
stock InvalidNick(playerid)
{
    if(IsPlayerNPC(playerid)) return 0;
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    new where = strfind(name,"_",true);
    new lenght = strlen(name)-1;
    new invalid = strfind(name,"[",true);
    if(invalid == -1) invalid = strfind(name,"]",true);
    if(invalid == -1) invalid = strfind(name,"'",true);

    if(name[0] < 65 || name[0] > 90)
    {
        SendClientMessage(playerid,COLOR,"* Server: Your name is invalid! The name must start from capital letter.");
        SendClientMessage(playerid,COLOR,"* Server: Correct form would be:");
        SendClientMessage(playerid,COLOR,"* Server: Name_Surname");
        return 1;
    }

    if(name[where+1] < 65 || name[where+1] > 90)
    {
        SendClientMessage(playerid,COLOR,"* Server: Your name is invalid! The surname must start from capital letter.");
        SendClientMessage(playerid,COLOR,"* Server: Correct form would be:");
        SendClientMessage(playerid,COLOR,"* Server: Name_Surname");
        return 1;
    }

    for(new i = 1; i < where-1; i++)
    {
        if(name[i] < 97 || name[i] > 122)
        {
            SendClientMessage(playerid,COLOR,"* Server: Your name is invalid! You have capital letters or numbers in the middle of the name.");
            SendClientMessage(playerid,COLOR,"* Server: Correct form would be:");
            SendClientMessage(playerid,COLOR,"* Server: Name_Surname");
            return 1;
        }
    }


    if(where == 0 || where == lenght || where==-1)
    {
        SendClientMessage(playerid,COLOR,"* Server: Your name is invalid!");
        SendClientMessage(playerid,COLOR,"* Server: Correct form would be:");
        SendClientMessage(playerid,COLOR,"* Server: Name_Surname");
        return 1;
    }

    if(strlen(name[where])<4)
    {
        SendClientMessage(playerid,COLOR,"* Server: Your name is invalid! Your surname is too short.");
        SendClientMessage(playerid,COLOR,"* Server: Correct form would be:");
        SendClientMessage(playerid,COLOR,"* Server: Name_Surname");
        return 1;
    }

    if(where<3)
    {
        SendClientMessage(playerid,COLOR,"* Server: Your name is invalid! Your name is too short.");
        SendClientMessage(playerid,COLOR,"* Server: Correct form would be:");
        SendClientMessage(playerid,COLOR,"* Server: Name_Surname");
        return 1;
    }


    if(invalid != -1)
    {
        SendClientMessage(playerid,COLOR,"* Server: Your name is invalid! Illegal characters found.");
        SendClientMessage(playerid,COLOR,"* Server: Correct form would be:");
        SendClientMessage(playerid,COLOR,"* Server: Name_Surname");
        return 1;
    }

    for(new i = where+2; i < MAX_PLAYER_NAME; i++)
    {
        if(name[i] < 97 || name[i] > 122)
        {
            if(name[i] == 0){i = MAX_PLAYER_NAME; return 0;}
            SendClientMessage(playerid,COLOR,"* Server: Your name is invalid! Capital letters or numbers in the middle of the word.");
            SendClientMessage(playerid,COLOR,"* Server: Correct form would be:");
            SendClientMessage(playerid,COLOR,"* Server: Name_Surname");
            return 1;
        }
    }
    return 0;
}
Reply
#9

Very nice code, nonetheless.
Reply
#10

Nice You can add forbidden names like Barack_Obama, Harry_potter, Mickael_Jackson etc?? It's a good idea I think. It will be really "IsAProperRolePlayName" haha (easy to make)

Thanks. And tell me what
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)