Name checker - 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)
+--- Thread: Name checker (
/showthread.php?tid=491848)
Name checker -
CH | FuDo - 01.02.2014
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.
Re: Name checker -
Konstantinos - 01.02.2014
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] != '_');
}
Re: Name checker -
CH | FuDo - 01.02.2014
Could you explain me, how this works, what I need to do?
Thank you for fast answer. REP+ for you.
Re: Name checker -
Konstantinos - 01.02.2014
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;
}