SA-MP Forums Archive
[Include] IsARolePlayName - 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: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] IsARolePlayName (/showthread.php?tid=270298)



IsARolePlayName - Lenny the Cup - 19.07.2011

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


Re: IsARolePlayName - kiss - 19.07.2011

Really good job man!


Re: IsARolePlayName - SpiderWalk - 19.07.2011

Nice one Lenny


Re: IsARolePlayName - MoroDan - 19.07.2011

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


Re: IsARolePlayName - SchurmanCQC - 19.07.2011

Very nice function.


Re: IsARolePlayName - Lenny the Cup - 19.07.2011

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


Re: IsARolePlayName - [HiC]TheKiller - 20.07.2011

NVM, didn't realise there was a loop.


Re: IsARolePlayName - wups - 20.07.2011

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;
}



Re: IsARolePlayName - Vipero - 20.07.2011

Very nice code, nonetheless.


Re : IsARolePlayName - mehdi-jumper - 30.11.2011

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