AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [CS:S/CS:GO] Change Player's Name (https://forums.alliedmods.net/showthread.php?t=161025)

GoD-Tony 07-02-2011 10:22

[CS:S/CS:GO] Change Player's Name
 
This is no longer needed. Use SetClientName in SourceMod 1.7.1 or later.

Edit: A CS:GO alternative, https://forums.alliedmods.net/showpo...2&postcount=26

A stock to successfully rename players in CS:S.

Code:
stock CS_SetClientName(client, const String:name[], bool:silent=false) {     decl String:oldname[MAX_NAME_LENGTH];     GetClientName(client, oldname, sizeof(oldname));     SetClientInfo(client, "name", name);     SetEntPropString(client, Prop_Data, "m_szNetname", name);     new Handle:event = CreateEvent("player_changename");     if (event != INVALID_HANDLE)     {         SetEventInt(event, "userid", GetClientUserId(client));         SetEventString(event, "oldname", oldname);         SetEventString(event, "newname", name);         FireEvent(event);     }     if (silent)         return;         new Handle:msg = StartMessageAll("SayText2");     if (msg != INVALID_HANDLE)     {         BfWriteByte(msg, client);         BfWriteByte(msg, true);         BfWriteString(msg, "Cstrike_Name_Change");         BfWriteString(msg, oldname);         BfWriteString(msg, name);         EndMessage();     } }

Dr!fter 07-02-2011 11:17

Re: [CS:S] Change Player's Name
 
Very cool. I never expected there to be a prop you could set. It was requested when i made the extension that it be added to sourcemod core. I think that this method is much better than my current one and the one I've been working on for months (and could never figure out why it timed players out after a while...) maybe you should add this to the cstrike include as a stock there. Then make the changes needed for the rename command to make the original sm_rename command work on CS:S.

GoD-Tony 07-02-2011 11:47

Re: [CS:S] Change Player's Name
 
One thing I liked about your extension is that it still allowed clients to use the "name" command, which works with the GUI. I'm not sure if that's still possible to do server-side anymore.

I still consider this useful as I use it to rename players for a variety of reasons. Maybe it could be added to the cstrike include like you said (along with psychonic's tag stocks).

KyleS 07-02-2011 19:34

Re: [CS:S] Change Player's Name
 
Thanks for this!

EDIT: Below is my attempt at trying to add some safety to this (how it's setup it can silently fail, or crash if used improperly).
PHP Code:

stock bool:SetClientName(client, const String:name[])
{
    
// Save the current name.
    
decl String:oldname[MAX_NAME_LENGTH];
    if(!
GetClientName(clientoldnamesizeof(oldname)))
    {
        return 
false;
    }

    
// Change the name.
    
SetClientInfo(client"name"name);
    
SetEntPropString(clientProp_Data"m_szNetname"name);
    
    
// Fire the event.
    
new Handle:event CreateEvent("player_changename");
    if (
event != INVALID_HANDLE)
    {
        
SetEventInt(event"userid"GetClientUserId(client));
        
SetEventString(event"oldname"oldname);
        
SetEventString(event"newname"name);
        
FireEvent(event);
    
        
// Send the usermessage.
        
new Handle:msg StartMessageAll("SayText2");
        if (
msg != INVALID_HANDLE)
        {
            
BfWriteByte(msgclient);
            
BfWriteByte(msgtrue);
            
BfWriteString(msg"Cstrike_Name_Change");
            
BfWriteString(msgoldname);
            
BfWriteString(msgname);
            
EndMessage();
            return 
true;
        }
    }
    
    return 
false;



GoD-Tony 07-03-2011 08:12

Re: [CS:S] Change Player's Name
 
Quote:

Originally Posted by KyleS (Post 1502419)
EDIT: Below is my attempt at trying to add some safety to this (how it's setup it can silently fail, or crash if used improperly).

Also keep in mind that this part of code changes the player's name:
Code:
SetClientInfo(client, "name", name); SetEntPropString(client, Prop_Data, "m_szNetname", name);
and returning false after that (for any reason) would be a bit misleading because the players name will still have changed silently. The rest of the code is cosmetic/notification stuff which shouldn't matter if it fails anyway.

KyleS 07-03-2011 17:53

Re: [CS:S] Change Player's Name
 
Quote:

Originally Posted by GoD-Tony (Post 1502728)
Also keep in mind that this part of code changes the player's name:
Code:
SetClientInfo(client, "name", name); SetEntPropString(client, Prop_Data, "m_szNetname", name);

and returning false after that (for any reason) would be a bit misleading because the players name will still have changed silently. The rest of the code is cosmetic/notification stuff which shouldn't matter if it fails anyway.

Oh I see. I was under the impression that the Usermessage and event were both required to have the change be propagated to clients :oops:

TnTSCS 09-09-2011 13:41

Re: [CS:S] Change Player's Name
 
Thank you - added to my ever growing TnTlib.inc LoL

sinblaster 09-13-2011 16:42

Re: [CS:S] Change Player's Name
 
how does one use this? (Sorry I know I am draining) Is it only for use when creating a plugin? I'd love to be able to change some names I hate some of the offensive crap some players join with in CSS

RedSword 09-13-2011 17:26

Re: [CS:S] Change Player's Name
 
Quote:

Originally Posted by sinblaster (Post 1554671)
how does one use this? (Sorry I know I am draining) Is it only for use when creating a plugin? I'd love to be able to change some names I hate some of the offensive crap some players join with in CSS

Hi sinblaster,

you could use sm_rename2 command by KyleS (does the job) :

http://forums.alliedmods.net/showpos...69&postcount=6

(add the sm_rename2 command to rename people effectively). It does use a different system but I got it to work not so long ago.

sinblaster 09-13-2011 17:35

Re: [CS:S] Change Player's Name
 
Awesome thanks for the link Red!


All times are GMT -4. The time now is 10:54.

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