View Single Post
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