SA-MP Forums Archive
Anyone got a IsValidName stock? - 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: Anyone got a IsValidName stock? (/showthread.php?tid=279214)



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 
0strlen(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 
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.


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(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


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(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?


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.