General > Developers Corner
Tags
easer7:
How would I give tags to moderators and admins?
This is the code I have so far.
if (SERVER) then
AddCSLuaFile("autorun/tags.lua")
end
if (CLIENT) then
function Insert( pl, msg )
local tab = {}
if pl:IsUserGroup("headmanagement") then
table.insert( tab, Color( 255, 0, 0, 255 ) )
table.insert( tab, "[Head Management] " )
table.insert( tab, Color( 255, 255, 255, 255 ) )
table.insert( tab, pl )
table.insert( tab, ": " )
table.insert( tab, msg )
elseif pl:IsUserGroup("superadmin") then
table.insert( tab, Color( 0, 255, 0, 255 ) )
table.insert( tab, "[Head Management] " )
table.insert( tab, Color( 255, 255, 255, 255 ) )
table.insert( tab, pl )
table.insert( tab, ": " )
table.insert( tab, msg )
elseif pl:IsUserGroup("admin") then
table.insert( tab, Color( 0, 255, 0, 255 ) )
table.insert( tab, "[Administrator] " )
table.insert( tab, Color( 255, 255, 255, 255 ) )
table.insert( tab, pl )
table.insert( tab, ": " )
table.insert( tab, msg )
elseif pl:IsUserGroup("leadmanagement") then
table.insert( tab, Color( 0, 255, 0, 255 ) )
table.insert( tab, "[Lead Management] " )
table.insert( tab, Color( 255, 255, 255, 255 ) )
table.insert( tab, pl )
table.insert( tab, ": " )
table.insert( tab, msg )
elseif pl:IsUserGroup("management") then
table.insert( tab, Color( 0, 35, 175, 255 ) )
table.insert( tab, "[Management] " )
table.insert( tab, Color( 255, 255, 255, 255 ) )
table.insert( tab, ply:Nick( ply ) )
table.insert( tab, ": " )
table.insert( tab, msg )
elseif pl:IsUserGroup("leadmoderator") then
table.insert( tab, Color( 0, 74, 175, 255 ) )
table.insert( tab, "[Lead Moderator] " )
table.insert( tab, Color( 255, 255, 255, 255 ) )
table.insert( tab, pl )
table.insert( tab, ": " )
table.insert( tab, msg )
elseif pl:IsUserGroup("moderator") then
table.insert( tab, Color( 0, 185, 35, 255 ) )
table.insert( tab, "[Moderator] " )
table.insert( tab, Color( 255, 255, 255, 255 ) )
table.insert( tab, pl )
table.insert( tab, ": " )
table.insert( tab, msg )
elseif pl:IsUserGroup("premium") then
table.insert( tab, Color( 255, 0, 175, 255 ) )
table.insert( tab, "[Premium] " )
table.insert( tab, Color( 255, 255, 255, 255 ) )
table.insert( tab, pl )
table.insert( tab, ": " )
table.insert( tab, msg )
elseif pl:IsUserGroup("trusted") then
table.insert( tab, Color( 255, 0, 175, 255 ) )
table.insert( tab, "[Trusted] " )
table.insert( tab, Color( 255, 255, 255, 255 ) )
table.insert( tab, pl )
table.insert( tab, ": " )
table.insert( tab, msg )
elseif pl:IsUserGroup("supporter") then
table.insert( tab, Color( 255, 0, 175, 255 ) )
table.insert( tab, "[Supporter] " )
table.insert( tab, Color( 255, 255, 255, 255 ) )
table.insert( tab, pl )
table.insert( tab, ": " )
table.insert( tab, msg )
else
table.insert( tab, Color( 86, 185, 80, 255 ) )
table.insert( tab, "[User] " )
table.insert( tab, Color( 255, 255, 255, 255 ) )
table.insert( tab, pl )
table.insert( tab, ": " )
table.insert( tab, msg )
end
chat.AddText( unpack(tab) )
return true
end
end
hook.Add("OnPlayerChat", "InsertTags", Insert)
The result is that it is saying "admin" and in the correct color but it completely gets rid of the name, how would I fix this?
Megiddo:
ply:Nick() for the player's name
easer7:
Yes but where and how would I add it? And thank you very much for responding =D
easer7:
I changes all the if/elses to look like this:
elseif pl:IsUserGroup("admin") then
table.insert( tab, Color( 0, 255, 0, 255 ) )
table.insert( tab, "[Administrator] " )
table.insert( tab, ply:Nick() )
table.insert( tab, Color( 255, 255, 255, 255 ) )
table.insert( tab, pl )
table.insert( tab, ": " )
table.insert( tab, msg )
But that didnt work either, what is wrong?
JamminR:
When speaking outright about code, we often use 'ply' as the 'player object'.
So when Megiddo stated ply:Nick(), you would actually need to use the variable of YOUR player object in your code, which is 'pl', not 'ply'.
So in your case, you'd need 'pl:Nick()'
Remove the original edit you did where you added ply:Nick(), and
I'm pretty sure you would not need your "table.insert( tab, pl )" parts, and instead replace those with table.insert( tab, pl:Nick() )
I think that would get you on your way, may have to adjust for insertion order after that.
Navigation
[0] Message Index
[#] Next page
Go to full version