"IsRoleplayName();"-Function
#1

Hello.

I'm searching for a little function to check if the string is a roleplay-name.
It also checks how many "_" or "." are in the String.
It should be only 1 "_" or "." ^^

And the first name must be 2 or more letters.
No numbers in the name.

Only "John_Smith", "Joe_Smith" ect.

The Function should be like this:
IsRoleplayName(name[]); - Return "true" if yes
or
IsRoleplayName(playerid); - Return "true" if yes

^^

Thanx :*
Reply
#2

pawn Код:
new plname[MAX_PLAYER_NAME];
    GetPlayerName(playerid, plname, sizeof(plname));
    new namestring = strfind(plname, "_", true);
    if(namestring == -1)
    {
       
        return false;
    }
    else
    {
     return true;
    }
Untested
Reply
#3

PHP код:
stock IsRoleplayName(playerid)
{
    new 
pName[MAX_PLAYER_NAME];
    
GetPlayerName(playeridpNamesizeof(pName));
    new 
namestring strfind(pName"_"true);
    if(
namestring == -1)
    {
        
SendClientMessage(playerid0xFF0000C8"Your name isґnt a RP format.");
        
Kick(playerid);
    }
    return 
1;

Reply
#4

But then, they can do Names like:

_Sk1llz0r_

-.-
Reply
#5

Use this stock then
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 returns 0 if false and 1 if true
Reply
#6

Thanx

But what about using "_" and "." concurrently?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)