Anyone got a IsValidName stock?
#1

Title says it all...
Reply
#2

PHP код:
stock IsValidName(playerid)
{
    if (
IsPlayerConnected(playerid))
    {
        new 
player[24];
        
GetPlayerName(playerid,player,24);
        for(new 
0strlen(player); n++)
        {
            if (
player[n] == '_') return 1;
            if (
player[n] == ']' || player[n] == '[') return 0;
        }
    }
    return 
0;

There you go
Reply
#3

Not what I was looking for.. anyways, found it..
Reply
#4

Quote:
Originally Posted by G4M3Ov3r
Посмотреть сообщение
PHP код:
stock IsValidName(playerid)
{
    if (
IsPlayerConnected(playerid))
    {
        new 
player[24];
        
GetPlayerName(playerid,player,24);
        for(new 
0strlen(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.
Reply
#5

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(playeridpnamesizeof(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=0i<maxnamei++) { if(pname[i] == '_'underline ++; }
    if(
underline != 1) return 0;
    
pname[0] = toupper(pname[0]);
    for(new 
x=1x<maxnamex++)
    {
        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(playeridpname);
    return 
1;

So, Don't spam bro , Get proof, before trying to compete with me
Reply
#6

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)
Reply
#7

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.
Reply
#8

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(playeridpnamesizeof(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=0i<maxnamei++) { if(pname[i] == '_'underline ++; }
    if(
underline != 1) return 0;
    
pname[0] = toupper(pname[0]);
    for(new 
x=1x<maxnamex++)
    {
        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(playeridpname);
    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?
Reply
#9

Quote:
Originally Posted by Bakr
Посмотреть сообщение
Why in the world would you use strfind when you could simply use switch, which is far faster?
Delete
Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)