Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: Shortening nick player

  1. #11
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    Please speak english, I don't understand you

  2. #12
    Private
    Join Date
    Aug 2012
    Posts
    78
    Thanks
    20
    Thanked 10 Times in 5 Posts
    Look page 1 ,i edit post

  3. #13
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    Quote Originally Posted by Moczulak View Post
    I open the menu.
    I see the name of a player.
    I would like to shorten the player name to 10 characters.

    I think I explained clearly enough what effect I would get... :P
    Well, you can't shorten a player's name to 10 characters until you know how long it is. For example, you could not shorten my name (Tally) to 10 characters because it isn't 10 characters to begin with. Secondly, you need to strip a player's name of all the symbols which don't actually make a proper player name - that is, clan tags and colored symbols. This is called "sanitizing" the name. Here is a standard way of doing that:


    PHP Code:
    {
        
    name sanitizeNameself.name );
    }

    sanitizeNamestr )
    {
        if( !
    isDefinedstr ) || str == "" ) return "";

        
    validchars "!()+,-.0123456789;=@AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz_{}~";

        
    tmpname monotonestr );
        
    string "";
        
    prevchr "";
        for( 
    0tmpname.sizei++ )
        {
            
    chr tmpname[i];
            if( 
    chr == "." )
            {
                if( !
    string.size ) continue; // avoid leading dots
                
    if( chr == prevchr ) continue; // avoid double dots
            
    }
            else if( 
    chr == "[" chr "{";
            else if( 
    chr == "]" chr "}";

            
    prevchr chr;
            for( 
    0validchars.sizej++ )
            {
                if( 
    chr == validchars[j] )
                {
                    
    string += chr;
                    break;
                }
            }
        }

        if( 
    string == "" string "noname";
        
        return 
    string;
    }

    monotonestr )
    {
        if( !
    isDefinedstr ) || ( str == "" ) )
            return( 
    "" );

        
    "";

        
    colorCheck false;
        for( 
    0str.sizei++ )
        {
            
    ch str];
            if( 
    colorCheck )
            {
                
    colorCheck false;

                switch( 
    ch )
                {
                    case 
    "0":    // black
                    
    case "1":    // red
                    
    case "2":    // green
                    
    case "3":    // yellow
                    
    case "4":    // blue
                    
    case "5":    // cyan
                    
    case "6":    // pink
                    
    case "7":    // white
                    
    case "8":    // Olive
                    
    case "9":    // Grey
                        
    break;
                    
                    default:
                        
    += ( "^" ch );
                        break;
                }
            }
            else if( 
    ch == "^" )
                
    colorCheck true;
            else
                
    += ch;
        }
        
        return( 
    );

    That will remove colored names and clan tags and give you a monotone player name.

    Now, once you've done that you need to decide what to do with it. As I said, you cannot rigidly reduce a player's name to 10 characters unless it is longer than 10 characters to begin with. So, find the size of a player's name, then reduce it by however much you like based on the number of characters in the name.

    BTW - Why would you want to do this at all? It doesn't seem to have any logical purpose to it.

  4. The Following 3 Users Say Thank You to Tally For This Useful Post:

    kung foo man (21st March 2013),Moczulak (21st March 2013),Ni3ls (21st March 2013)

  5. #14
    Private
    Join Date
    Aug 2012
    Posts
    78
    Thanks
    20
    Thanked 10 Times in 5 Posts
    Thank you for the finished script, I wanted to limit the name to save space on the menu :P

  6. #15
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 296 Times in 188 Posts
    playerA setClientCvar( "ui_name" , getSubStr( playerB.name , 0 , min( 10 , playerB.name.size ) ) );

    its ur turn to create your own min() function!

    but youd be better with tally's one, so you should be able to display the decolored full name instead of a colored half one
    but you should know/see, in the menufiles every letter has another size! so 10 M's are way larger than 10 i's!
    Last edited by serthy; 21st March 2013 at 18:47.

  7. #16
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    PHP Code:
    getamountofchars(stringamount)
    {
        
    newstring "";
        
    count 0;
        for(
    0string.sizei++)
        {
            if(
    count == amount)
                break;
            if(
    string.size && string[i] == "^" && issubstr("0123456789"string[1]))
            {
                
    //color thingy
                
    newstring += string[i];
                
    i++;
                
    newstring += string[i];
            }
            else
            {
                
    newstring += string[i];
                
    count++;
            }
        }
        return 
    newstring;

    will accept a string and a maximum length and return a string with only the said amount of chars. If there are colors in there, they are ignored BUT they are returned in the result.

    So if i call string = getamountofchars(self.name, 10); and my name is abcdefghijklmnopqrstuvwxyz, it will return abcdefghij. If my name is ^1a^2b^3c^d^4e^5f^6g^7h^8i^9j^0k^1l^2m, it will return ^1a^2b^3c^d^4e^5f^6g^7h^8i^9j^0k (which, as far as strings go, is longer than 10 chars. But it is the char with length 10 when not counting the color-chars)

  8. The Following User Says Thank You to IzNoGoD For This Useful Post:

    Moczulak (21st March 2013)

  9. #17
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    PHP Code:
    getamountofchars(stringamount)
    {
        
    newstring "";
        
    count 0;
        for(
    0string.sizei++)
        {
            if(
    count == amount)
                break;
            if(
    string.size && string[i] == "^" && issubstr("0123456789"string[1]))
            {
                
    //color thingy
                
    newstring += string[i];
                
    i++;
                
    newstring += string[i];
            }
            else
            {
                
    newstring += string[i];
                
    count++;
            }
        }
        return 
    newstring;

    will accept a string and a maximum length and return a string with only the said amount of chars. If there are colors in there, they are ignored BUT they are returned in the result.

    So if i call string = getamountofchars(self.name, 10); and my name is abcdefghijklmnopqrstuvwxyz, it will return abcdefghij. If my name is ^1a^2b^3c^d^4e^5f^6g^7h^8i^9j^0k^1l^2m, it will return ^1a^2b^3c^d^4e^5f^6g^7h^8i^9j^0k (which, as far as strings go, is longer than 10 chars. But it is the char with length 10 when not counting the color-chars)

  10. The Following User Says Thank You to IzNoGoD For This Useful Post:

    Moczulak (21st March 2013)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •