Detecting a character in a players name - 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: Detecting a character in a players name (
/showthread.php?tid=311627)
Detecting a character in a players name -
LiamM - 17.01.2012
Hey guys, I have a /changename cmd but I only jsut realized that people can put spaces and shit in there name and it fucks up the MySQL database. So whats the best way I could check if theres any spaces or unwanted characters in the players name?
Re: Detecting a character in a players name - T0pAz - 17.01.2012
mysql_real_escape_string.
Re: Detecting a character in a players name -
LiamM - 17.01.2012
Quote:
Originally Posted by T0pAz
|
Yes but... I mean.. if a player uses a space in his name, SetPlayerName will not work. So how can I return a message to say that they are not allowed to use a space in there name? I know about the mysql_real_escape_string.
Re: Detecting a character in a players name -
MP2 - 17.01.2012
pawn Код:
stock IsValidName(name[])
{
if(strlen(name) < 3) return 0;
new i, ch;
while ((ch = name[i++]) && ((ch == '(') || (ch == ')') || (ch == '$') || (ch == '.') || (ch == '=') || (ch == '@') || (ch == ']') || (ch == '[') || (ch == '_') || ('0' <= ch <= '9') || ((ch |= 0x20) && ('a' <= ch <= 'z')))) {}
return !ch;
}
Re: Detecting a character in a players name -
LiamM - 18.01.2012
Thanks man, that really helped. Sorry for such a late reply too!