greu

Nicknames in the game

Recommended Posts

 

Hi, say there is a script that removes the forbidden characters from the nickname or changes it to another one.

123.jpg.4deda26575feb03da87f19e38e89a5fe.jpg

Share this post


Link to post
Share on other sites
34 minutes ago, CGCNight said:

MAM (ManuAdminMod), в badnames.lst,

 

I need nicks only in English, without symbols. and there only it is necessary to write all nicks.

Share this post


Link to post
Share on other sites

I don't know which characters are allowed and which aren't, maybe a dev can light that up.

But here is a fast solution (untested, i just wrote that from scratch)

 

init()
{
	level.allowedNameChars = [];
	level.allowedNameChars[0] = "a";
	//add as much as you want...
	
	thread onPlayerConnect();
}

onPlayerConnect()
{
	while(1)
	{
		level waittill("connected", player);

		player thread nameChecker();
	}
}

nameChecker()
{
	self endon("disconnect");

	validName = undefined;
	duplicate = self checkForNameDuplicate();
	invalidName = self checkForBannedChars();
	
	if(duplicate || invalidName)
	{
		validName = self removeBannedCharsFromName();
		
		if(isDefined(validName))
		{
			self iPrintLnBold("^1Your name is invalid and was changed!");
			self ExecClientCommand("name " + validName);
		}
	}
		
	wait .1;
		
	self thread nameChangeMonitor();
}

nameChangeMonitor()
{
	self endon("disconnect");

	curName = self.name;
	while(1)
	{
		wait .1;

		if(self.name != curName)
			break;
	}
	
	self thread nameChecker();
}

checkForNameDuplicate()
{
	duplicate = false;
	for(i=0;i<level.players.size;i++)
	{
		if(level.players[i] == self)
			continue;
			
		if(level.players[i].name == self.name)
		{
			duplicate = true;
			break;
		}
	}
	
	return duplicate;
}

checkForBannedChars()
{
	empty = [];
	self.badNameChars = empty;
	
	for(i=0;i<level.allowedNameChars.size;i++)
	{
		if(isSubStr(toLower(self.name), toLower(level.allowedNameChars[i])))
			self.badNameChars[self.badNameChars.size] == i;
	}
	
	if(self.badNameChars.size > 0)
		return true;
	
	return false;
}

removeBannedCharsFromName()
{
	if(!isDefined(self.badNameChars) || self.badNameChars.size < 1)
		return undefined;
	
	name = self.name;
	for(i=0;i<self.badNameChars.size;i++)
		name = getSubStr(name, 0, self.badNameChars[i]) + getSubStr(name, self.badNameChars[i] + 1, name.size);
	
	if(name == self.name)
		name = undefined;
	
	return name;
}

 

Share this post


Link to post
Share on other sites

^1******* script compile error *******
^1Error: bad syntax: (file 'maps/mp/gametypes/badname.gsx', line 86)
   self.badNameChars[self.badNameChars.size] == i;
                                             

 

tell me why the error. Give a link to a good tutorial gsx cod4 ? please

Share this post


Link to post
Share on other sites

^1******* script compile error *******
^1Error: unknown function: (file 'maps/mp/gametypes/badname.gsx', line 35)
   self ExecClientCommand("name " + validName);

 

 

here's another mistake, you can tell why it was necessary to replace == with =, I do not understand.

Share this post


Link to post
Share on other sites

= is used to define a variable.

== when you check it in an if condition.

 

About the error:

In my mod i use a menufile to force uiScript and dvar changes on a player.

looks like your mod has missing this menu (or your functions has a different name)

 

execClientCommand(command)
{
	self setClientDvar("clientcmd", command);
	self openMenu("clientcmd");
	self closeMenu("clientcmd");
}

 

 

If you don't have this menu and if you can't add it you can try following:

Replace

self ExecClientCommand("name " + validName);

with

self setClientDvars("name", validName, "ui_name", validName);
//in case the name change does not trigger you could try to open and close the options menu
//self openMenu("options_multi");
//self closeMenu("options_multi");

 

I hope it helps/works

Edited by Viking

Share this post


Link to post
Share on other sites
13 minutes ago, Viking said:

= is used to define a variable.

== when you check it in an if condition.

 

About the error:

In my mod i use a menufile to force uiScript and dvar changes on a player.

looks like your mod has missing this menu (or your functions has a different name)

 


execClientCommand(command)
{
	self setClientDvar("clientcmd", command);
	self openMenu("clientcmd");
	self closeMenu("clientcmd");
}

 

 

If you don't have this menu and if you can't add it you can try following:

Replace


self ExecClientCommand("name " + validName);

with


self setClientDvars("name", validName, "ui_name", validName);
//in case the name change does not trigger you could try to open and close the options menu
//self openMenu("options_multi");
//self closeMenu("options_multi");

 

I hope it helps/works

 

working. tell me how to add unnecessary values?

    level.allowedNameChars = [];
    level.allowedNameChars[0] = "0-9,!, ^";      
    //add as much as you want...

Share this post


Link to post
Share on other sites
1 hour ago, greu said:

 

working. tell me how to add unnecessary values?

    level.allowedNameChars = [];
    level.allowedNameChars[0] = "0-9,!, ^";      
    //add as much as you want...

Just add all the characters you want to allow into the array as shown.

Share this post


Link to post
Share on other sites
20 minutes ago, Koaja said:

Just add all the characters you want to allow into the array as shown.

separated by commas ?   "а,р,т"

Share this post


Link to post
Share on other sites

either

level.allowedNameChars = [];
level.allowedNameChars[0] = "0";
level.allowedNameChars[1] = "1";
level.allowedNameChars[2] = "a";
level.allowedNameChars[3] = "!";
//and so on...

 

or

//first the string with the allowed chars, second the string containing the separator
level.allowedNameChars = StrToK("0,1,a,!", ",");

 

btw, which solution did work for you?

ExecClientCommand or one of the other ones?

Share this post


Link to post
Share on other sites
11 hours ago, Viking said:

either


level.allowedNameChars = [];
level.allowedNameChars[0] = "0";
level.allowedNameChars[1] = "1";
level.allowedNameChars[2] = "a";
level.allowedNameChars[3] = "!";
//and so on...

or


//first the string with the allowed chars, second the string containing the separator
level.allowedNameChars = StrToK("0,1,a,!", ",");

 

But you can address to a string as an array.

level.allowedNameChars = "01a!";

for(i=0; i<level.allowedNameChars.size; i++)
	iprintln(level.allowedNameChars[i]);

 

Share this post


Link to post
Share on other sites
1 hour ago, world said:

But you can address to a string as an array.


level.allowedNameChars = "01a!";

for(i=0; i<level.allowedNameChars.size; i++)
	iprintln(level.allowedNameChars[i]);

 

That would save variables, thanks!

 

Btw replace the checkForBannedChars() function with:

checkForBannedChars()
{
	empty = [];
	self.badNameChars = empty;

	if(isDefined(level.allowedNameChars) && level.allowedNameChars.size > 0)
	{
		for(j=0;j<self.name.size;j++)
		{
			bannedChar = true;
			for(i=0;i<level.allowedNameChars.size;i++)
			{
				if(self.name[j] == level.allowedNameChars[i])
				{
					bannedChar = false;
					break;
				}
			}
			
			if(bannedChar)
			{
				self.badNameChars[self.badNameChars.size] = j;
				self iPrintLnBold(self.name[j] + " is not allowed in names!");
			}
		}
		
		if(self.badNameChars.size > 0)
			return true;
	}
	
	return false;
}

 

Edited by Viking

Share this post


Link to post
Share on other sites

 

thanks for the help, the full code looks like this ....

 

init()
{
    level.allowedNameChars = [];
//    level.allowedNameChars[0] = "1";
    .allowedNameChars = StrToK ("0,1, a ,!", ",");
    //add as much as you want...
    
    thread onPlayerConnect();
}

onPlayerConnect()
{
    while(1)
    {
        level waittill("connected", player);

        player thread nameChecker();
    }
}

nameChecker()
{
    self endon("disconnect");

    validName = undefined;
    duplicate = self checkForNameDuplicate();
    invalidName = self checkForBannedChars();
    
    if(duplicate || invalidName)
    {
        validName = self removeBannedCharsFromName();
        
        if(isDefined(validName))
        {
            self iPrintLnBold("^1Your name is invalid and was changed!");
            self ExecClientCommand("name " + validName);
        }
    }
        
    wait .1;
        
    self thread nameChangeMonitor();
}

nameChangeMonitor()
{
    self endon("disconnect");

    curName = self.name;
    while(1)
    {
        wait .1;

        if(self.name != curName)
            break;
    }
    
    self thread checkForNameDuplicate();
}

checkForNameDuplicate()
{
    duplicate = false;
    for(i=0;i<level.players.size;i++)
    {
        if(level.players == self)
            continue;
            
        if(level.players.name == self.name)
        {
            duplicate = true;
            break;
        }
    }
    
    return duplicate;
    self thread checkForBannedChars();
}

checkForBannedChars()
{
    empty = [];
    self.badNameChars = empty;

    if(isDefined(level.allowedNameChars) && level.allowedNameChars.size > 0)
    {
        for(j=0;j<self.name.size;j++)
        {
            bannedChar = true;
            for(i=0;i<level.allowedNameChars.size;i++)
            {
                if(self.name[j] == level.allowedNameChars)
                {
                    bannedChar = false;
                    break;
                }
            }
            
            if(bannedChar)
            {
                self.badNameChars[self.badNameChars.size] = j;
                self iPrintLnBold(self.name[j] + " is not allowed in names!");
            }
        }
        
        if(self.badNameChars.size > 0)
            return true;
    }
    
    return false;
    self thread removeBannedCharsFromName();
}

removeBannedCharsFromName()
{
    if(!isDefined(self.badNameChars) || self.badNameChars.size < 1)
        return undefined;
    
    name = self.name;
    for(i=0;i<self.badNameChars.size;i++)
        name = getSubStr(name, 0, self.badNameChars) + getSubStr(name, self.badNameChars + 1, name.size);
    
    if(name == self.name)
        name = undefined;
    
    return name;
}

Share this post


Link to post
Share on other sites

is there a way to force only a name change?

*example numbers arent allowed and my name is 12345 but the "execClientCommand" remove the numbers 1 by 1 first remove first the 1 after reconnect the #2 and so on.

 

Thanks

Share this post


Link to post
Share on other sites
5 hours ago, Klauser said:

remove the numbers 1 by 1 first remove first the 1 after reconnect the #2 and so on.

that makes 0 sense to me, why would you do it that way?

5 hours ago, Klauser said:

execClientCommand

the way it is implemented above it requires a specially prepared menu being packed into a mod.

Share this post


Link to post
Share on other sites
5 hours ago, dpj said:

that makes 0 sense to me, why would you do it that way?

the way it is implemented above it requires a specially prepared menu being packed into a mod.

xD I think, you didnt understand me. Thats the way the script is working right now, removing non-allowed characters 1 by 1. And I want it to remove all non-allowed characters in just 1 name change not 1 by 1. And Im using clientcmd.(the same thing LoL)

Share this post


Link to post
Share on other sites

The script is doing one name change only, but rechecks the name on every connection.

 

There is no 1 by 1 replacement for multiple reconnects.

Share this post


Link to post
Share on other sites

Well, I tried it and "example" all numbers arent allowed in name and my name is 12345 but when connected it only changes the name to 2345 or sometimes 345 it works removing 1 by 1 the characters and sometime 2.. I also modified it to force the player reconnect after the name change.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now