Anyone got a IsValidName stock? -
Snipa - 25.08.2011
Title says it all...
Re: Anyone got a IsValidName stock? -
=WoR=G4M3Ov3r - 25.08.2011
PHP код:
stock IsValidName(playerid)
{
if (IsPlayerConnected(playerid))
{
new player[24];
GetPlayerName(playerid,player,24);
for(new n = 0; n < strlen(player); n++)
{
if (player[n] == '_') return 1;
if (player[n] == ']' || player[n] == '[') return 0;
}
}
return 0;
}
There you go
Re: Anyone got a IsValidName stock? -
Snipa - 25.08.2011
Not what I was looking for.. anyways, found it..
Re: Anyone got a IsValidName stock? -
mprofitt - 25.08.2011
Quote:
Originally Posted by G4M3Ov3r
PHP код:
stock IsValidName(playerid)
{
if (IsPlayerConnected(playerid))
{
new player[24];
GetPlayerName(playerid,player,24);
for(new n = 0; n < strlen(player); n++)
{
if (player[n] == '_') return 1;
if (player[n] == ']' || player[n] == '[') return 0;
}
}
return 0;
}
There you go
|
You got to be kidding me.....
There are much better exmples else where on the forum. Your function considers anything with a _ as a vailid name, everything thing else fails, as your script does.
Re: Anyone got a IsValidName stock? -
=WoR=G4M3Ov3r - 25.08.2011
Quote:
Originally Posted by mprofitt
You got to be kidding me.....
There are much better exmples else where on the forum. Your function considers anything with a _ as a vailid name, everything thing else fails, as your script does.
|
Mhm, My script eh ?, Thats what i have in my Script
PHP код:
public IsValidName(playerid)
{
new pname[MAX_PLAYER_NAME],underline=0;
GetPlayerName(playerid, pname, sizeof(pname));
if(strfind(pname,"[",true) != (-1)) return 0;
else if(strfind(pname,".",true) != (-1)) return 0;
else if(strfind(pname,"]",true) != (-1)) return 0;
else if(strfind(pname,"$",true) != (-1)) return 0;
else if(strfind(pname,"(",true) != (-1)) return 0;
else if(strfind(pname,")",true) != (-1)) return 0;
else if(strfind(pname,"=",true) != (-1)) return 0;
else if(strfind(pname,"@",true) != (-1)) return 0;
else if(strfind(pname,"1",true) != (-1)) return 0;
else if(strfind(pname,"2",true) != (-1)) return 0;
else if(strfind(pname,"3",true) != (-1)) return 0;
else if(strfind(pname,"4",true) != (-1)) return 0;
else if(strfind(pname,"5",true) != (-1)) return 0;
else if(strfind(pname,"6",true) != (-1)) return 0;
else if(strfind(pname,"7",true) != (-1)) return 0;
else if(strfind(pname,"8",true) != (-1)) return 0;
else if(strfind(pname,"9",true) != (-1)) return 0;
new maxname = strlen(pname);
for(new i=0; i<maxname; i++) { if(pname[i] == '_') underline ++; }
if(underline != 1) return 0;
pname[0] = toupper(pname[0]);
for(new x=1; x<maxname; x++)
{
if(pname[x] == '_') pname[x+1] = toupper(pname[x+1]);
else if(pname[x] != '_' && pname[x-1] != '_') pname[x] = tolower(pname[x]);
}
SetPlayerName(playerid, "New_Name");
SetPlayerName(playerid, pname);
return 1;
}
So, Don't spam bro
, Get proof, before trying to compete with me
Re: Anyone got a IsValidName stock? -
Snipa - 25.08.2011
Or instead of that long, useless code, use SetPlayerName's returns.
Returns 1 if the name was changed, 0 if the player is already using that name or -1 when the name cannot be changed (it's in use, too long or has invalid characters)
Re: Anyone got a IsValidName stock? -
=WoR=G4M3Ov3r - 25.08.2011
Quote:
Originally Posted by Snipa
Or instead of that long, useless code, use SetPlayerName's returns.
Returns 1 if the name was changed, 0 if the player is already using that name or -1 when the name cannot be changed (it's in use, too long or has invalid characters)
|
You asked for it, i gave it to you, just edit it to wtv ya want.
Re: Anyone got a IsValidName stock? -
Bakr - 26.08.2011
Quote:
Originally Posted by G4M3Ov3r
Mhm, My script eh ?, Thats what i have in my Script
PHP код:
public IsValidName(playerid)
{
new pname[MAX_PLAYER_NAME],underline=0;
GetPlayerName(playerid, pname, sizeof(pname));
if(strfind(pname,"[",true) != (-1)) return 0;
else if(strfind(pname,".",true) != (-1)) return 0;
else if(strfind(pname,"]",true) != (-1)) return 0;
else if(strfind(pname,"$",true) != (-1)) return 0;
else if(strfind(pname,"(",true) != (-1)) return 0;
else if(strfind(pname,")",true) != (-1)) return 0;
else if(strfind(pname,"=",true) != (-1)) return 0;
else if(strfind(pname,"@",true) != (-1)) return 0;
else if(strfind(pname,"1",true) != (-1)) return 0;
else if(strfind(pname,"2",true) != (-1)) return 0;
else if(strfind(pname,"3",true) != (-1)) return 0;
else if(strfind(pname,"4",true) != (-1)) return 0;
else if(strfind(pname,"5",true) != (-1)) return 0;
else if(strfind(pname,"6",true) != (-1)) return 0;
else if(strfind(pname,"7",true) != (-1)) return 0;
else if(strfind(pname,"8",true) != (-1)) return 0;
else if(strfind(pname,"9",true) != (-1)) return 0;
new maxname = strlen(pname);
for(new i=0; i<maxname; i++) { if(pname[i] == '_') underline ++; }
if(underline != 1) return 0;
pname[0] = toupper(pname[0]);
for(new x=1; x<maxname; x++)
{
if(pname[x] == '_') pname[x+1] = toupper(pname[x+1]);
else if(pname[x] != '_' && pname[x-1] != '_') pname[x] = tolower(pname[x]);
}
SetPlayerName(playerid, "New_Name");
SetPlayerName(playerid, pname);
return 1;
}
So, Don't spam bro , Get proof, before trying to compete with me
|
Why in the world would you use strfind when you could simply use switch, which is far faster?
Re: Anyone got a IsValidName stock? -
=WoR=G4M3Ov3r - 26.08.2011
Quote:
Originally Posted by Bakr
Why in the world would you use strfind when you could simply use switch, which is far faster?
|
Delete
Re: Anyone got a IsValidName stock? -
Bakr - 26.08.2011
You two obviously cannot read, or are just blatantly ignoring my posts. I said your use of strfind function was terribly slow and useless when you can use switch. If you are still having trouble understanding what I'm saying, read the example code I posted.
EDIT: I may understand how you are confused. I do not mean placing stfind inside the switch function, but looping through the string and checking each character. That method is much more efficient compared to calling strfind multiple times.