PDA

View Full Version : Shortening nick player



Moczulak
21st March 2013, 09:28
Hello all.
I write the script:


if (player.name.size > 10)
{
player.name = getsubstr(player.name, player.name.size, player.name.size-1);
player setClientCvar("ui_cvar", player.name);
}

He wants to limit the length of the name players...
But i have this error: "player field name is read-only:"

IzNoGoD
21st March 2013, 11:19
getsubstr(string, start, end)

Your start is not 0, but is player.name.size. fix it.

Also: dont write to player.name, write to player cvar "name"

Moczulak
21st March 2013, 12:05
So what if I do this calculation? I do not know exactly how it works getsubstr function () I only know its possible...

kung foo man
21st March 2013, 12:53
That should be enough:




if (player.name.size > 10)
{
newName = getsubstr(player.name, 0, 10);
player setClientCvar("ui_cvar", newName); // whatever this is for
player setClientCvar("name", newName); // set new name to player
}

Tally
21st March 2013, 13:10
Hello all.
I write the script:


if (player.name.size > 10)
{
player.name = getsubstr(player.name, player.name.size, player.name.size-1);
player setClientCvar("ui_cvar", player.name);
}

He wants to limit the length of the name players...
But i have this error: "player field name is read-only:"

The error "player field name is read-only" is telling you you cannot reassign the player.name field, which is what you were doing when you wrote this:


player.name = getsubstr(player.name, 0, player.name.size-1);

You will get similar errors every time you try to reassign an existing engine field. All existing engine fields are protected and you cannot change them or reassign them.

You can do this:


player.myname = getsubstr(player.name, 0, player.name.size-1);
player setClientCvar("name", player.myname);

But not the first.

BTW - this:


player.name = getsubstr(player.name, 0, player.name.size-1);

Would give you the name of the player, minus 1 letter. So, for example, if it were my name, this:


player.name = getsubstr(player.name, 0, player.name.size-1);

Would produce this:


Tall

Is that what you wanted?

Moczulak
21st March 2013, 14:25
Very thanks Tally and Kung Foo Man :) :D

Moczulak
21st March 2013, 15:35
Shortened nickname player has to see self ,please help me..
This script not work:



player.myname = getsubstr(player.name, 0, player.name.size-1);
self setClientCvar("ui_dvarmenu", player.myname);

kung foo man
21st March 2013, 15:39
I dont understand your goal :confused:

EvoloZz
21st March 2013, 15:39
player setClientCvar() instead of self setClientCvar()

Moczulak
21st March 2013, 17:29
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

Ni3ls
21st March 2013, 17:38
Please speak english, I don't understand you

Moczulak
21st March 2013, 18:27
Look page 1 ,i edit post ;)

Tally
21st March 2013, 19:08
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:



{
name = sanitizeName( self.name );
}

sanitizeName( str )
{
if( !isDefined( str ) || str == "" ) return "";

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

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 );
}


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.

Moczulak
21st March 2013, 19:26
Thank you for the finished script, I wanted to limit the name to save space on the menu :P

serthy
21st March 2013, 19:43
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!

IzNoGoD
21st March 2013, 19:44
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;
}

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)

IzNoGoD
21st March 2013, 19:44
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;
}

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)