Please speak english, I don't understand you
Please speak english, I don't understand you
Look page 1 ,i edit post
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:
That will remove colored names and clan tags and give you a monotone player name.PHP Code:
{
name = sanitizeName( self.name );
}
sanitizeName( str )
{
if( !isDefined( str ) || str == "" ) return "";
validchars = "!()+,-.0123456789;=@AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz_{}~";
tmpname = monotone( str );
string = "";
prevchr = "";
for( i = 0; i < tmpname.size; i++ )
{
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( j = 0; j < validchars.size; j++ )
{
if( chr == validchars[j] )
{
string += chr;
break;
}
}
}
if( string == "" ) string = "noname";
return string;
}
monotone( str )
{
if( !isDefined( str ) || ( str == "" ) )
return( "" );
s = "";
colorCheck = false;
for( i = 0; i < str.size; i++ )
{
ch = str[ i ];
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:
s += ( "^" + ch );
break;
}
}
else if( ch == "^" )
colorCheck = true;
else
s += ch;
}
return( s );
}
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.
kung foo man (21st March 2013),Moczulak (21st March 2013),Ni3ls (21st March 2013)
Thank you for the finished script, I wanted to limit the name to save space on the menu :P
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.
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.PHP Code:
getamountofchars(string, amount)
{
newstring = "";
count = 0;
for(i = 0; i < string.size; i++)
{
if(count == amount)
break;
if(i < string.size - 1 && string[i] == "^" && issubstr("0123456789", string[i + 1]))
{
//color thingy
newstring += string[i];
i++;
newstring += string[i];
}
else
{
newstring += string[i];
count++;
}
}
return newstring;
}
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)
Moczulak (21st March 2013)
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.PHP Code:
getamountofchars(string, amount)
{
newstring = "";
count = 0;
for(i = 0; i < string.size; i++)
{
if(count == amount)
break;
if(i < string.size - 1 && string[i] == "^" && issubstr("0123456789", string[i + 1]))
{
//color thingy
newstring += string[i];
i++;
newstring += string[i];
}
else
{
newstring += string[i];
count++;
}
}
return newstring;
}
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)
Moczulak (21st March 2013)