31.07.2016, 22:39
PHP Code:
stock ValidateRoleplayName(playerid)
{
new
name[MAX_PLAYER_NAME]
;
GetPlayerName(playerid, name, sizeof(name));
new
new_name[MAX_PLAYER_NAME];
format(new_name, sizeof(new_name), ConvertNameToRoleplay(name));
if(isnull(new_name))
{
return -1;
}
else
{
new tempName[MAX_PLAYER_NAME];
format(tempName, sizeof(tempName), "player_%i", playerid);
SetPlayerName(playerid, tempName);
SetPlayerName(playerid, new_name);
}
return 1;
}
stock ConvertNameToRoleplay(name[])
{
new
pos = strfind(name, "_", true),
new_name[MAX_PLAYER_NAME]
;
if(pos == -1)
{
// his name not is roleplay
return new_name;
}
new
firstChar = GetASCIIDec(name),
firstCharID = 0,
changeFirstChar = -1,
changeSecondChar = -1
;
if(!charIsLetter(firstChar))
{
// his name not is roleplay
return new_name;
}
else{
if(charIsLetterLowercase(firstChar))
{
// Su inicial es minuscula
changeFirstChar = firstChar;
}
}
new secondCharID = pos+1;
if(name[secondCharID] == '\0')
{
// his name not is roleplay
return new_name;
}
else{
new secoundChar = GetASCIIDec(name[secondCharID]);
if(!charIsLetter(secoundChar))
{
// his name not is roleplay
return new_name;
}
else
{
if(charIsLetterLowercase(secoundChar))
{
changeSecondChar = secoundChar;
}
}
}
format(new_name, sizeof(new_name), name);
if(changeFirstChar != -1)
new_name[firstCharID] = GetMayusASCII(changeFirstChar);
if(changeSecondChar != -1)
new_name[secondCharID] = GetMayusASCII(changeSecondChar);
return new_name;
}
stock GetMayusASCII(charid)
{
if(!charIsLetterLowercase(charid))
return charid;
return charid-32;
}
stock GetASCIIDec(str[])
{
new
s[4]
;
format(s, sizeof(s), "%c", str);
format(s, sizeof(s), "%i", s);
return strval(s);
}
stock charIsLetter(decimal)
return decimal >= 65 && decimal <= 90 || decimal >= 97 && decimal <= 122;
stock charIsLetterLowercase(decimal)
return decimal >= 97 && decimal <= 122;
PHP Code:
public OnPlayerConnect(playerid)
{
if(ValidateRoleplayName(playerid) == -1)
{
// Nombre no es Ropleay
Kick(playerid);
}
// No es necesario un else, pues si es valido pero no cumple con las mayusculas lo va a kickear nada mas.
}