SA-MP Forums Archive
Check username format. - 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: Check username format. (/showthread.php?tid=187224)



Check username format. - jm2rock - 01.11.2010

How would I go on about checking username format? So basically if username is in First_Last formart and if there is any numbers in the name?


Re: Check username format. - Miguel - 02.11.2010

I'd use sscanf and strfind:
pawn Код:
public OnPlayerConnect(playerid)
{
    new
        name[24],
        string[2];
       
    GetPlayerName(playerid, name, sizeof(name)); // we need player's name
    if(sscanf(name, "{p<_>s[12]s[12]}") != 0) // we check if there is a delimiter "_" splitting two strings (name and lastname)
    {
        SendClientMessage(playerid, 0xFFFFFFFF, "* You have been banned because your nickname didn't have a \"_\"!");
        Ban(playerid); // we ban the player if there was no "_"
    }
    for(new i = 0; i < 10; i ++) // we make a loop from 0 to 9
    {
        format(string, sizeof(string), "%d", i); // we set "i" (the number being worked) to the string
        if(strfind(name, string, true) != -1) // is there any number in "name"?
        {
            SendClientMessage(playerid, 0xFFFFFFFF, "* You have been banned because your nickname had a number!");
            Ban(playerid); // if yes then BAN!!!!!!    
        }
    }
    return 1;
}



Re: Check username format. - Retardedwolf - 02.11.2010

Lol Miguel nice code there but you don't need to ban someone for those reasons do you


Re: Check username format. - Rafa - 02.11.2010

oh my god hahahahahah !!


Re: Check username format. - LarzI - 02.11.2010

And instead of formatting, you could just use valstr