ChangeName Need help

[lua]function ccChangeName( ply, cmd, args )

local name = args[ 1 ];

if( string.len( name ) > 33 ) then

	Notify(player, 1, 4, "Name to long! Max 32 characters" );
	return;
	
end
ply:SetNWString("name", name);

end
concommand.Add( “rp_changename”, ccChangeName );[/lua]

I’m trying to allow player’s to change their names in my roleplay mod I’m making. No it’s not Cake nor DarkRP. Anyways this wonderful code doesn’t change there name nor does it give errors.

You can’t actually change the player’s “Name”. You’ll have to give each player an RPName and use that everywhere the regular name is used.

I think you can with setinfo.

Actually here is how DarkRP does it (in cl_init.lua) : [lua]-- Make sure the client sees the RP name where they expect to see the name
local pmeta = FindMetaTable(“Player”)

pmeta.Name = function(self)
return self:GetNWString(“rpname”)
end

pmeta.GetName = pmeta.Name
pmeta.Nick = pmeta.Name
– End
[/lua]

This effectively uses the RPName everywhere the name is needed.

I know how DarkRP does it, i’m just saying, the real name can be changed.

[lua]function ccChangeName( ply, cmd, args )

local name = args[ 1 ];

if( string.len( name ) > 33 ) then

	Notify(player, 1, 4, "Name to long! Max 32 characters" );
	return;
	
end
hook.Add("Think","Name", function() RunConsoleCommand("setinfo","name",name) end)

end
concommand.Add( “rp_changename”, ccChangeName );[/lua]

[lua]function Originalname()

hook.Add(“Think”,“Name”, function() return end) --Makes there name Original again

end
concommand.Add( “rp_originalname”, Originalname );[/lua]

I wouldn’t set people’s actual names though. They’d get pissed.

The server can no longer set the players name using setinfo thanks to ‘fcvar_server_can_execute’ whitelist, so wouldn’t be a problem.

So this doesn’t work either?

Garry fuxed it up everything on http://wiki.garrysmod.com/?title=G.RunConsoleCommand should be blocked not every fucking console command T.T


function ConvertArgs(args)
	local ret_args = ""
	
	for k, v in pairs(args) do
		ret_args = ret_args..v
		
		if k != #args then
			ret_args = ret_args.." "
		end
	end
	
	return ret_args
end

function ccSetName( ply, cmd, args )
	local name = ConvertArgs(args);
	
	if( string.len( name ) > 33 ) then
		Notify(player, 1, 4, "Name to long! Max 32 characters" );
		return;		
	end
	
	ply:SetNWString("name", name);	
end

concommand.Add( "rp_changename", ccSetName )

function ccGetName( ply )
	local ret_name = ply:GetNWString("name")
	
	if (ret_name == "") then
		ret_name = LocalPlayer():Name()
	end
	
	return ret_name
end

hook.Add( "OnPlayerChat", "PlayerName", function(ply, msg)
	chat.AddText( team.GetColor(ply:Team()), ccGetName(ply), Color(255, 255, 255, 255), ": "..msg )
	return true
end )

You might want to add a check to make sure players can’t have the same name.

Thanks for the help guys. I figured it out.