Raised This Month: $12 Target: $400
 3% 

[CS:S/CS:GO] Change Player's Name


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GoD-Tony
Veteran Member
Join Date: Jul 2005
Old 07-02-2011 , 10:22   [CS:S/CS:GO] Change Player's Name
Reply With Quote #1

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

Last edited by GoD-Tony; 07-22-2015 at 01:49.
GoD-Tony is offline
Dr!fter
The Salt Boss
Join Date: Mar 2007
Old 07-02-2011 , 11:17   Re: [CS:S] Change Player's Name
Reply With Quote #2

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.
Dr!fter is offline
GoD-Tony
Veteran Member
Join Date: Jul 2005
Old 07-02-2011 , 11:47   Re: [CS:S] Change Player's Name
Reply With Quote #3

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).

Last edited by GoD-Tony; 07-02-2011 at 11:54.
GoD-Tony is offline
KyleS
SourceMod Plugin Approver
Join Date: Jul 2009
Location: Segmentation Fault.
Old 07-02-2011 , 19:34   Re: [CS:S] Change Player's Name
Reply With Quote #4

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;


Last edited by KyleS; 07-03-2011 at 05:32.
KyleS is offline
GoD-Tony
Veteran Member
Join Date: Jul 2005
Old 07-03-2011 , 08:12   Re: [CS:S] Change Player's Name
Reply With Quote #5

Quote:
Originally Posted by KyleS View Post
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.

Last edited by GoD-Tony; 07-03-2011 at 08:14.
GoD-Tony is offline
KyleS
SourceMod Plugin Approver
Join Date: Jul 2009
Location: Segmentation Fault.
Old 07-03-2011 , 17:53   Re: [CS:S] Change Player's Name
Reply With Quote #6

Quote:
Originally Posted by GoD-Tony View Post
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
KyleS is offline
TnTSCS
AlliedModders Donor
Join Date: Oct 2010
Location: Undisclosed...
Old 09-09-2011 , 13:41   Re: [CS:S] Change Player's Name
Reply With Quote #7

Thank you - added to my ever growing TnTlib.inc LoL
TnTSCS is offline
sinblaster
Grim Reaper
Join Date: Feb 2010
Location: Australia
Old 09-13-2011 , 16:42   Re: [CS:S] Change Player's Name
Reply With Quote #8

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
__________________
Happy Happy Joy Joy

sinblaster is offline
RedSword
SourceMod Plugin Approver
Join Date: Mar 2006
Location: Quebec, Canada
Old 09-13-2011 , 17:26   Re: [CS:S] Change Player's Name
Reply With Quote #9

Quote:
Originally Posted by sinblaster View Post
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.
__________________
My plugins :
Red Maze
Afk Bomb
RAWR (per player/rounds Awp Restrict.)
Kill Assist
Be Medic

You can also Donate if you appreciate my work
RedSword is offline
sinblaster
Grim Reaper
Join Date: Feb 2010
Location: Australia
Old 09-13-2011 , 17:35   Re: [CS:S] Change Player's Name
Reply With Quote #10

Awesome thanks for the link Red!
__________________
Happy Happy Joy Joy

sinblaster is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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