Raised This Month: $32 Target: $400
 8% 

Changing Players Name Silently


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
midnight9
Senior Member
Join Date: Nov 2012
Old 10-15-2017 , 14:53   Changing Players Name Silently
Reply With Quote #1

Hello! Im using SetClientName to change players name and im wondering if there is a way to do it without in chat name change announcement.
midnight9 is offline
sdz
Senior Member
Join Date: Feb 2012
Old 10-15-2017 , 15:11   Re: Changing Players Name Silently
Reply With Quote #2

PHP Code:
#include <sourcemod>

public void OnPluginStart()
{
    
//This hooks the event, we'll implement a listener for it.
    
bool exists HookEventEx("player_changename"Event_NameChangedEventHookMode_Pre);
    if(!
existsSetFailState("[SM] SetFailState: player_changename event does not exist. Unloading...");
}

public 
Action Event_NameChanged(Event event, const char[] namebool dontBroadcast)
{
    
//This gets the client's user ID then translates it to a client index
    
int client GetClientOfUserId(event.GetInt("userid"));

    
//Validity of client
    
if(client MaxClients || client 1) return Plugin_Continue;
    if(!
IsClientConnected(client) || !IsClientInGame(client)) return Plugin_Continue;

    
//Get the new name of client
    
char newName[MAX_NAME_LENGTH];
    
event.GetString("newname"newNamesizeof(newName));
    
    if(
StrContains(newName"[AFK]"false) != -|| StrContains(newName"[CRASHED]"false) != -1
    {
        
SetClientName(client"hot");
        
SetEventBroadcast(eventtrue);
        
PrintToChatAll("asd");
        return 
Plugin_Handled;
    }

    else return 
Plugin_Continue;
}

public 
Plugin myinfo 
{
    
name "Block Namechange Message",
    
author "Sidezz",
    
description "Stuff for people",
    
version SOURCEMOD_VERSION,
    
url "http://www.coldcommunity.com"
}; 

Last edited by sdz; 10-15-2017 at 15:12.
sdz is offline
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 10-15-2017 , 15:18   Re: Changing Players Name Silently
Reply With Quote #3

You can just edit the normal rename.sp and remove that part.
Attached Files
File Type: smx playercommands.smx (10.7 KB, 163 views)
File Type: sp Get Plugin or Get Source (rename.sp - 249 views - 4.9 KB)
__________________

Last edited by PinHeaDi; 10-15-2017 at 15:20.
PinHeaDi is offline
midnight9
Senior Member
Join Date: Nov 2012
Old 10-15-2017 , 15:22   Re: Changing Players Name Silently
Reply With Quote #4

Hi, thanks for reply, i have allready tried player_changename event but it doesnt block any name change announcements at all.
midnight9 is offline
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 10-15-2017 , 15:27   Re: Changing Players Name Silently
Reply With Quote #5

Quote:
Originally Posted by midnight9 View Post
Hi, thanks for reply, i have allready tried player_changename event but it doesnt block any name change announcements at all.
Try with the plugin I attached, it should work. The .SP is if you want to compile playercommands.smx by yourself.
__________________
PinHeaDi is offline
midnight9
Senior Member
Join Date: Nov 2012
Old 10-15-2017 , 15:28   Re: Changing Players Name Silently
Reply With Quote #6

Quote:
Originally Posted by PinHeaDi View Post
You can just edit the normal rename.sp and remove that part.
Sorry i didnt make it clear enough. Im using SetClientName in a simple plugin that automatically renames player upon connection. I want only remove remove notification when this plugin changes players name, any other name changes should be announced as normal.
midnight9 is offline
sdz
Senior Member
Join Date: Feb 2012
Old 10-15-2017 , 15:32   Re: Changing Players Name Silently
Reply With Quote #7

Quote:
Originally Posted by midnight9 View Post
Sorry i didnt make it clear enough. Im using SetClientName in a simple plugin that automatically renames player upon connection. I want only remove remove notification when this plugin changes players name, any other name changes should be announced as normal.
Then you could just have a client variable like g_Rename[client] = true; when the player joins, call SetClientName and in the name changed event you just check for the value of that variable
sdz is offline
midnight9
Senior Member
Join Date: Nov 2012
Old 10-15-2017 , 15:44   Re: Changing Players Name Silently
Reply With Quote #8

I have allready thought of that so i just tried this:
Code:
#include <sourcemod>

public void OnPluginStart()
{
    //This hooks the event, we'll implement a listener for it.
    bool exists = HookEventEx("player_changename", Event_NameChanged, EventHookMode_Pre);
    if(!exists) SetFailState("[SM] SetFailState: player_changename event does not exist. Unloading...");
}

public Action Event_NameChanged(Event event, const char[] name, bool dontBroadcast)
{

    SetEventBroadcast(event, true);
    PrintToChatAll("asd");
    return Plugin_Handled;
}
to see if it will block all name changes but it doesnt.

Last edited by midnight9; 10-15-2017 at 15:45.
midnight9 is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 10-16-2017 , 19:55   Re: Changing Players Name Silently
Reply With Quote #9

i got you, fam

NAME_CHANGE_STRING will be different for games that aren't cs:s or cs:go

Code:
#include <sourcemod>
#include <sdktools>

#pragma semicolon 1
#pragma newdecls required

#define NAME_CHANGE_STRING "#Cstrike_Name_Change"

bool gB_HideNameChange = false;

public void OnPluginStart()
{
	RegConsoleCmd("sm_name", Command_Name);

	HookUserMessage(GetUserMessageId("SayText2"), Hook_SayText2, true);
}

public Action Command_Name(int client, int args)
{
	if(client == 0)
	{
		return Plugin_Handled;
	}

	char[] sArgs = new char[MAX_NAME_LENGTH];
	GetCmdArgString(sArgs, MAX_NAME_LENGTH);

	gB_HideNameChange = true; // do this whenever you want name changes to be silent
	SetClientName(client, sArgs);

	return Plugin_Handled;
}

public Action Hook_SayText2(UserMsg msg_id, any msg, const int[] players, int playersNum, bool reliable, bool init)
{
	if(!gB_HideNameChange)
	{
		return Plugin_Continue;
	}

	char[] sMessage = new char[24];

	if(GetUserMessageType() == UM_Protobuf)
	{
		Protobuf pbmsg = msg;
		pbmsg.ReadString("msg_name", sMessage, 24);
	}

	else
	{
		BfRead bfmsg = msg;
		bfmsg.ReadByte();
		bfmsg.ReadByte();
		bfmsg.ReadString(sMessage, 24, false);
	}

	if(StrEqual(sMessage, NAME_CHANGE_STRING))
	{
		gB_HideNameChange = false;

		return Plugin_Handled;
	}

	return Plugin_Continue;
}
__________________
retired
shavit is offline
midnight9
Senior Member
Join Date: Nov 2012
Old 10-17-2017 , 05:51   Re: Changing Players Name Silently
Reply With Quote #10

Quote:
Originally Posted by shavit View Post
i got you, fam

NAME_CHANGE_STRING will be different for games that aren't cs:s or cs:go

Code:
#include <sourcemod>
#include <sdktools>

#pragma semicolon 1
#pragma newdecls required

#define NAME_CHANGE_STRING "#Cstrike_Name_Change"

bool gB_HideNameChange = false;

public void OnPluginStart()
{
	RegConsoleCmd("sm_name", Command_Name);

	HookUserMessage(GetUserMessageId("SayText2"), Hook_SayText2, true);
}

public Action Command_Name(int client, int args)
{
	if(client == 0)
	{
		return Plugin_Handled;
	}

	char[] sArgs = new char[MAX_NAME_LENGTH];
	GetCmdArgString(sArgs, MAX_NAME_LENGTH);

	gB_HideNameChange = true; // do this whenever you want name changes to be silent
	SetClientName(client, sArgs);

	return Plugin_Handled;
}

public Action Hook_SayText2(UserMsg msg_id, any msg, const int[] players, int playersNum, bool reliable, bool init)
{
	if(!gB_HideNameChange)
	{
		return Plugin_Continue;
	}

	char[] sMessage = new char[24];

	if(GetUserMessageType() == UM_Protobuf)
	{
		Protobuf pbmsg = msg;
		pbmsg.ReadString("msg_name", sMessage, 24);
	}

	else
	{
		BfRead bfmsg = msg;
		bfmsg.ReadByte();
		bfmsg.ReadByte();
		bfmsg.ReadString(sMessage, 24, false);
	}

	if(StrEqual(sMessage, NAME_CHANGE_STRING))
	{
		gB_HideNameChange = false;

		return Plugin_Handled;
	}

	return Plugin_Continue;
}

Hi, HookUserMessage works indeed. I did it in a different way but you gave me an idea of how to do it, thanks
midnight9 is offline
Reply



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 23:09.


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