Raised This Month: $12 Target: $400
 3% 

You can simplify this?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
mlibre
Veteran Member
Join Date: Nov 2015
Location: return PLUGIN_CONTINUE
Old 12-17-2015 , 22:34   You can simplify this?
Reply With Quote #1

PHP Code:
new const code[][] = {
"1","2","3","4","5","6","7","8","9","0","a","b","c","d","f","g","h","i","j","k","l","m","n","o",
"p","q","r","s","t","u","v","w","x","y","z","-","*","_","(",")","=","+","<",">","@","$","&","[",
"]","?","{","}","'"
}

public 
client_connectid 

        static 
szName32 ]; 
        
get_user_nameidszNamecharsmaxszName ) ); 
    
        if(
contain(szName"Player") != -1)
        { 
        
client_cmd(id"name ^"%s%s%s%s%s^""szName,
        
code[random(sizeof(code))], code[random(sizeof(code))],code[random(sizeof(code))],
        
code[random(sizeof(code))] )
        } 
        else if (
contain(szName"unnamed") != -1)
        { 
        
client_cmd(id"name ^"%s%s%s%s%s^""szName,
        
code[random(sizeof(code))], code[random(sizeof(code))],code[random(sizeof(code))],
        
code[random(sizeof(code))] )
        } 
        else if (
contain(szName"emply") != -1)
        { 
        
client_cmd(id"name ^"%s%s%s%s%s^""szName,
        
code[random(sizeof(code))], code[random(sizeof(code))],code[random(sizeof(code))],
        
code[random(sizeof(code))] )
        }

Example:

The goal is to change the name "Player" to "Player1d5*_" or "unnamed" to "unnamed-d=d1" ...

So add 4 characters a random way to the name.

Last edited by mlibre; 12-17-2015 at 22:52.
mlibre is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-17-2015 , 23:14   Re: You can simplify this?
Reply With Quote #2

Code:
new const code[] = 
{
	'1','2','3','4','5','6','7','8','9','0','a','b','c','d','f','g','h','i','j','k','l','m','n','o',
	'p','q','r','s','t','u','v','w','x','y','z','-','*','_','(',')','=','+','<','>','@','$','&','[',
	']','?','{','}','''
}
#define GetChar()	code[random(sizeof(code))]

public client_connect( id ) 
{ 
        new szName[ 32 ]; 
        get_user_name( id , szName , charsmax( szName ) ); 
    
        if( ( contain( szName , "Player" ) != -1 ) || ( contain( szName , "unname" ) != -1 ) || ( contain( szName , "emply" ) != -1 ) )
		client_cmd( id , "name ^"%s%c%c%c%c^"" , szName , GetChar() , GetChar() , GetChar() , GetChar() );
}
__________________
Bugsy is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 12-18-2015 , 12:16   Re: You can simplify this?
Reply With Quote #3

god damn bugsy stop writing in alien language...
also, what is %c ?
__________________

Last edited by Depresie; 12-18-2015 at 12:16.
Depresie is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 12-18-2015 , 12:46   Re: You can simplify this?
Reply With Quote #4

%c is for characters.
__________________

Last edited by HamletEagle; 12-18-2015 at 12:46.
HamletEagle is offline
Andu.
Member
Join Date: Oct 2013
Location: Belgravistan
Old 12-18-2015 , 16:53   Re: You can simplify this?
Reply With Quote #5

Code:
new const szNames = {
	"Player",
	"unname",
	"emply"
new const code[] = 
{
	'1','2','3','4','5','6','7','8','9','0','a','b','c','d','f','g','h','i','j','k','l','m','n','o',
	'p','q','r','s','t','u','v','w','x','y','z','-','*','_','(',')','=','+','<','>','@','$','&','[',
	']','?','{','}','''
}
#define GetChar()	code[random(sizeof(code))]

public client_connect( id ) 
{ 
        new szName[ 32 ]; 
        get_user_name( id , szName , charsmax( szName ) ); 
    
        for(new i;i<sizeof(szNames);i++)
	if( ( contain( szName , szNames[i] ) != -1 ) )
		client_cmd( id , "name ^"%s%c%c%c%c^"" , szName , GetChar() , GetChar() , GetChar() , GetChar() );
}

Last edited by Andu.; 12-18-2015 at 16:53.
Andu. is offline
mlibre
Veteran Member
Join Date: Nov 2015
Location: return PLUGIN_CONTINUE
Old 01-01-2016 , 20:04   Re: You can simplify this?
Reply With Quote #6

Well, now how do to avoid duplicate names such as "(1)Player"

PHP Code:
new const szNames[][] = 
{
    
"(1)%s"// any name ("%s", szName) 
    
"(2)",
    
"(3)"
}

new const 
code[] = 
{
    
'1','2','3','4','5','6','7','8','9','0','a','b','c','d','f','g','h','i','j','k','l','m','n','o',
    
'p','q','r','s','t','u','v','w','x','y','z','-','*','_','(',')','=','+','<','>','@','$','&','[',
    
']','?','{','}'
}
#define GetChar()    code[random(sizeof(code))]

public client_connectid )
{
    new 
szName32 ]
    
get_user_nameidszNamecharsmax(szName) )

    for(new 
i;<sizeof(szNames); i++)
    {
        if( 
equali(szNameszNames[i] ))
        {
            
client_cmdid "name ^"%c%c%c%c^"" GetChar() , GetChar() , GetChar() , GetChar() );
        }
    }


Last edited by mlibre; 01-01-2016 at 20:05.
mlibre is offline
FromTheFuture
Senior Member
Join Date: Jan 2013
Old 01-01-2016 , 22:02   Re: You can simplify this?
Reply With Quote #7

No need a cycle.
FromTheFuture is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-01-2016 , 23:50   Re: You can simplify this?
Reply With Quote #8

Quote:
Originally Posted by HamletEagle View Post
%c is for characters.
For clarity, %c is for a single character.


Quote:
Originally Posted by mlibre View Post
Well, now how do to avoid duplicate names such as "(1)Player"
The easiest method, I think, would be to check for the duplicate name before assigning it. If that name already exists, create new one for them.

I had a friend who wrote a plugin to simply change their name to one that is in a preset list. Each time that a name was used, a counter would be incremented so that the next person to get a name forcibly, would get the next in the list. You merely need to make sure that the list of names that you chose from was long enough to not repeat. The list that we used wasn't really all that long because 1) there aren't that many people who join with the default name and 2) they would usually either leave or change their name at some point.

Also, instead of using client_cmd(), you should use set_user_info(id, "name", "new name here"). This will help prevent people from leaving and joining again with that same name which might be a duplicate of someone else that was assigned that name while they were gone.
__________________
fysiks is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 01-02-2016 , 06:01   Re: You can simplify this?
Reply With Quote #9

Use ASCII table and char, and delete constants array, and next use bugsy's code.Like this:

PHP Code:

#define GetChar()    random(47,123)

public client_connectid 

        new 
szName32 ]; 
        
get_user_nameid szName charsmaxszName ) ); 
    
        if( ( 
containszName "Player" ) != -) || ( containszName "unname" ) != -) || ( containszName "emply" ) != -) )
        
client_cmdid "name ^"%s%c%c%c%c^"" szName GetChar() , GetChar() , GetChar() , GetChar() );

Like this, and you dont need to declare constant array at the top.
siriusmd99 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-02-2016 , 07:39   Re: You can simplify this?
Reply With Quote #10

Quote:
Originally Posted by siriusmd99 View Post
Use ASCII table and char, and delete constants array, and next use bugsy's code.Like this:

PHP Code:

#define GetChar()    random(47,123)

public client_connectid 

        new 
szName32 ]; 
        
get_user_nameid szName charsmaxszName ) ); 
    
        if( ( 
containszName "Player" ) != -) || ( containszName "unname" ) != -) || ( containszName "emply" ) != -) )
        
client_cmdid "name ^"%s%c%c%c%c^"" szName GetChar() , GetChar() , GetChar() , GetChar() );

Like this, and you dont need to declare constant array at the top.
I like the approach, though minimal improvement since it is only eliminating the array which isn't a heavy lift to begin with. Plus, you are not giving him the exact chars he specified, though I'm not sure if it matters or not to the OP. You could exclude a set of chars using a bit-sum or something, but then it's easier to just use the array.
Code:
'$' = 36
'&' = 38
''' = 39
'(' = 40
')' = 41
'*' = 42
'+' = 43
'-' = 45
'0' = 48
'9' = 57
'<' = 60
'=' = 61
'>' = 62
'?' = 63
'@' = 64
'[' = 91
']' = 93
'_' = 95
'a-z' = 97-122
'{' = 123
'}' = 125
__________________
Bugsy is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:41.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode