AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Setting player name (https://forums.alliedmods.net/showthread.php?t=89093)

steel_1988 04-02-2009 07:04

Setting player name
 
Im not sure if this is an AMX bug or something? But with the following code, when you connect the first time it forces your name.. But if you retry it ignores it and does not force your name, it keeps it as whatever your counter-strike config was set to.

Any ideas? I need to force the name each time they connect.

public client_connect(id)
{
new newName[33]
get_user_info(id,"name",newName,32)

if(containi(newName,"[NEW NAME]") == -1)
{
format(newName,32,"[NEW NAME] %s",newName)
set_user_info(id,"name",newName)
}
}

Dores 04-02-2009 07:16

Re: Setting player name
 
Try checking his name at client_infochanged(id). It is called whenever his name is set/he changes his name(it is called in other events too, but the name is the important thing here).

PHP Code:

#include <amxmodx>

#define NAME_TAG    "[NEW_NAME]"

public client_infochanged(id)
{
    static 
name[32];
    
get_user_info(id"name"name31);
    
    if(
containi(nameNAME_TAG) == -1)
    {
        
format(name31"%s %s"NAME_TAGname);
        
        
set_user_info(id"name"name);
    }



steel_1988 04-02-2009 07:29

Re: Setting player name
 
Yeah but then it is only going to set their name if they change it.

If you use my code it sets their name when they join but if they retry it doesn't set it again for some reason..

With your way it is only going to set if when info is changed. I need it when they join the server (set it always.. not just the first time)

fysiks 04-02-2009 09:27

Re: Setting player name
 
In my tests, client_infochanged() is called several times when a client is connecting to the server. (3 or 4 if I remember correctly)

Dores 04-02-2009 10:58

Re: Setting player name
 
Quote:

Originally Posted by Dores (Post 795341)
Try checking his name at client_infochanged(id). It is called whenever his name is set...

What I meant by this is when he connects into the game, when the game sets his name so everyone could see it in the scoreboard, client_infochanged() is called.

YamiKaitou 04-02-2009 11:06

Re: Setting player name
 
Quote:

Originally Posted by fysiks (Post 795410)
In my tests, client_infochanged() is called several times when a client is connecting to the server. (3 or 4 if I remember correctly)

Correct, 1 for putinserver, 1 for team change, 1 for class change. There may be another, but those are the 3 that I remember. This is why you need to filter the calls by checking if the old name equals the new name.

fysiks 04-02-2009 19:41

Re: Setting player name
 
Quote:

Originally Posted by YamiKaitou (Post 795462)
Correct, 1 for putinserver, 1 for team change, 1 for class change. There may be another, but those are the 3 that I remember. This is why you need to filter the calls by checking if the old name equals the new name.

client_connect() (it showed up before connect but after putinserver)

steel_1988 04-02-2009 20:44

Re: Setting player name
 
The code should be working tho.. I did a server_print("code executed"); under where it sets the name..

It shows each time, however the persons name is not being set.. It only sets it the first time they connect...

If they then retry, their name stays as whatever their name is set to in their settings.. but i still see the message in the server console.

fysiks 04-02-2009 21:31

Re: Setting player name
 
Do some more troubleshooting. Server print name, tag, newname, or whatever to see if the name is correct or the if statement is being executed or etc. That's what I would do.

Bugsy 04-03-2009 00:00

Re: Setting player name
 
Try adding quotes around the name since it does contain space(s).

format(name, 31, "^"%s %s^"", NAME_TAG, name);


All times are GMT -4. The time now is 02:16.

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