I would really apprecitate any way of help on this.
I am attempting to edit the userdata of a player, so that the persons name on server is being displayed as i have set it.
Basically i want ply:Name(), to return my own set text.
If it is not possible to directly edit the userdata, on let's say authentification, then is there any better way to do this? I have been trying to findthis for quite while.
You could detour the function and make it return your value. It won't affect engine functions though.
[QUOTE=Robotboy655;43212859]You could detour the function and make it return your value. It won't affect engine functions though.[/QUOTE]
I want it to return my set name on stuff like "status" command, but i guess that, this deep editing probably is not possible. If that is not possible, ill just have to find every and all functions that use ply:Name() XD
[QUOTE=Newjorciks;43213045]I want it to return my set name on stuff like "status" command, but i guess that, this deep editing probably is not possible. If that is not possible, ill just have to find every and all functions that use ply:Name() XD[/QUOTE]
As I said, for Lua stuff you can detour the PlayerMeta:Name(), for engine functions there's nothing you can do.
You could attach a custom value to each player, so anytime you have a player reference you could lookup their "New Name" you assign them.
[CODE]function GM:PlayerInitialSpawn( ply )
ply.NewName = "Their new Name"
end[/CODE]
For the "status" command you could build your own command and function on the server, similar to status but instead using ply.NewName in place of ply:Nick()
[CODE]
function myStatusFunc(ply, cmd, arg)
-- TODO: Actually finish this code, this only returns names and SteamID
for k, ply in pairs(player.GetAll()) do
Msg("Name: "..ply.NewName.."SteamID: "..ply:SteamID())
end
end
concommand.Add( "myStatus", myStatusFunc)
[/CODE]
Then I guess if you want the scoreboard to reflect that build a custom vgui that uses ply.NewName for their name as well, and their names are essentially changed controlled by the server.
(I'm not building a scoreboard for you, I have not got around to writing one for myself yet)
You could use the above method, but it's not the best. What robotboy means by detouring a function is something like this:
[LUA]
local pMeta = FindMetaTable("Player")
local oldPNick = pMeta.Nick
function pMeta:Nick()
if self.YourName then
return self.YourName
else
return oldPNick( self )
end
end
[/LUA]
Im on my phone so sorry for any mistakes but you get the drift
Maybe:
[code]Player:SetSaveValue( "m_szNetname", "Your custom name here" )[/code]? I don't know if this value can be forced, but it is declared via DEFINE_FIELD in the SDK.
[code]
local PlayerMeta = FindMetaTable( "Player" )
local o_nick = PlayerMeta.Nick
function PlayerMeta:Nick( )
if ( self.NewName ) then
return self.NewName
end
return o_nick( self )
end
PlayerMeta.Name = PlayerMeta.Nick
PlayerMeta.GetName = PlayerMeta.Nick
[/code]
There. Just write ply.NewName = "whatever" to set a name, and ply.NewName = nil to remove it.
It would be better though, to do it shared so e.g. use NWString's if you're lazy ( but don't use too much ! ) or manually network it between the clients and the server.
NWStrings are the easiest way though, but they have a big - if there are too many, and the server isn't strong enough, it'll cause lags and the server may crash.
But if you don't give everyone a new name, just e.g. 3 of 10 players then NWString's are better better.
Sorry, you need to Log In to post a reply to this thread.