• Overriding player's name in chat?
    2 replies, posted
I'm writing a simple RP script for my server, and I'm having a tiny bit of trouble custom RP names. The player's name overrides properly in the player list/tab menu, on the voice chat indicator, and when you mouse over them, but not when they say anything in the chat. Currently I've only been able to test the script on a listen server with bots, but everything else works exactly as intended, which is what makes this so confusing. [lua] local pmeta = FindMetaTable("Player") pmeta.SteamName = pmeta.SteamName or pmeta.Name function pmeta:Name() if not self or not self.IsValid or not IsValid(self) then return "" end if not GetConVar("sbox_roleplay"):GetBool() then return self:SteamName() end if not self:GetNWString("SBoxRPName") then return self:SteamName() end return self:GetNWString("SBoxRPName") and tostring(self:GetNWString("SBoxRPName")) end pmeta.GetName = pmeta.Name pmeta.Nick = pmeta.Name [/lua] That code is being run on both the client and the server. On the client it affects the tab menu, mouseover text, and voice chat indicator, and unless I'm mistaken it SHOULD affect the chat as well, but as stated above, it doesn't. Any help any of you fine folks can offer would be greatly appreciated. Thanks in advance! Edit: Forgot to mention that that particular snippet is borrowed from the DarkRP SVN and modified a bit. Not sure if that matters, but I feel that I need to give credit where credit is due.
[lua] function GM:OnPlayerChat( ply, strText, bTeamOnly, bPlayerIsDead ) local tab = {} if ( IsValid( ply ) ) then table.insert( tab, team.GetColor( ply:Team() ) ) table.insert( tab, RPNameHere ) end table.insert( tab, Color( 255, 255, 255 ) ) table.insert( tab, ": " ..strText ) chat.AddText( unpack(tab) ) return true end[/lua] That goes in client.
Fantastic! I spent about 2 hours earlier trying in vain to hook it, and never managed to get it right. I hooked that and it works wonderfully, thank you!
Sorry, you need to Log In to post a reply to this thread.