General > Developers Corner

Tags

<< < (3/5) > >>

Megiddo:
Default color is approximately Color(150,200,255)

easer7:
This is for a Trouble in Terrorist Town server so the color of the name changes if you are innocent or detective in the chat though. So I don't know if there is any way to set it to be like that.

Megiddo:
It's could be their team color.

easer7:
But they change teams, like so if trusted is purple, and if they are detective, the code clashes.  This is trying to make it purple and the other is trying to make him blue (detective).  But in another round he could be traitor, so his name would be green, but the code would again clash b/c it would try to make his name purple.

JamminR:
Ok, just to confuse you, here's how I would do it.
ULib has a command that I'd hoped Garry would just create, but apparently never did.
We wrote a 'GetUserGroup' command IN ULib. Simply enough, it returns the group name the user is a part of. (not including inherits, just the top group)
Using that, I got rid of all your if/else IsUserGroup statements.

Now, the code below probably won't work as is.
See if you can figure it out though.
First I set a table of 'tags' by group/color/title.
Then, guessing that your gamemode uses teams for each job, I set a group of 'job' team colors. That is where you'd have to look in the original game mode to see what colors for each team they used.
ProTip, learn to concatenate in Lua. Not having so many table inserts will save you lua code time. Even if you end up going back to your if/then/elseif tree (because you want your code to run on NON ULib servers too), you can still save some table.inserts by using

--- Code: ---table.insert( tab, jobcolor .. pl:Name() .. ": " .. msg )

--- End code ---
rather than

--- Code: ---table.insert( tab, msg )
table.insert( tab, ": ")
table.insert( tab, pl:Nick() )
table.insert( tab, jobcolor )

--- End code ---

Again, below is example, untested. 98% guaranteed not to work out of the box.

--- Code: ---if (SERVER) then
        AddCSLuaFile("autorun/tags.lua")
end

-- Table of TAG colors and name per group
taggroup_color =  { }
taggroup_color.headmanagement =  { Color( 255, 0, 0, 255 ) .. "[Head Management] " }
taggroup_color.superadmin = { Color( 0, 255, 0, 255 ) .. "[Head Management] " }
taggroup_color.admin = { Color( 0, 255, 0, 255 ) ..  "[Administrator] " }
taggroup_color.leadmanagement = { Color( 0, 255, 0, 255 ) ..  "[Lead Management] " }
-- and so on .

-- Table of JOB (team??) colors, as specified somewhere in your gamemode already.
tagjob_color = { }
tagjob_color.1 = { Color( #whatever, #color, #here ) }
tagjob_color.2 = { Color( #whatever, #color, #here ) }
tagjob_color.someotherjobteam# = { Color( #whatever, #color, #here ) }
 -- and so on for each job(team?) color as used in your gamemode.
 
if (CLIENT) then
function TagInsert( pl, msg )
local tab = {}
local group = pl:GetUserGroup() -- THIS IS A ULib ONLY command. If you don't want the code ULib required, you must then use your 'if/then' for every group test tree as your originally had
local job = pl:GetTeam()
local grouptag = taggroup_color[group]
local jobcolor = tagjob_color[job]
--error checks
if grouptag == nil then grouptag = Color( 255, 0, 0, 255 ) .. "[Unknown] " end
if jobcolor =- nil then jobcolor = Color( #some, #generic, #color ) end
        table.insert( tab, grouptag )
table.insert( tab, jobcolor .. pl:Nick() .. ": " .. msg )
        chat.AddText( unpack(tab) )
return true
end
end
hook.Add("OnPlayerChat", "InsertTags", TagInsert)

--- End code ---

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version