The problem I'm facing is that when someone is in headmoderator their tag comes up as "Head Admin" and if they are in headadmin their tag comes up as "Admin", what am I doing wrong?
garrysmod\addons\darkrpmodification-master\lua\darkrp_modules\chatthing\cl_chatthing.lua
[CODE]
hook.Add("OnPlayerChat", "chat thing", function(ply, text, teamOnly, alive, prefixText, color1, color2)
if ply:IsSuperAdmin() then
chat.AddText(Color(255, 0, 0, 255), "[SuperAdmin] ", color1, prefixText, color2, ": "..text)
return true
end
if ply:IsAdmin() then
chat.AddText(Color(255, 0, 0, 255), "[Admin] ", color1, prefixText, color2, ": "..text)
return true
end
if ply:IsUserGroup("donator") then
chat.AddText(Color(255, 0, 191), "[Donator] ", color1, prefixText, color2, ": "..text)
return true
end
if ply:IsUserGroup("owner") then
chat.AddText(Color(127, 0, 95), "[Owner] ", color1, prefixText, color2, ": "..text)
return true
end
if ply:IsUserGroup("headadmin") then
chat.AddText(Color(0, 255, 63), "[Head Admin] ", color1, prefixText, color2, ": "..text)
return true
end
if ply:IsUserGroup("headmoderator") then
chat.AddText(Color(255, 93, 0), "[Head Moderator] ", color1, prefixText, color2, ": "..text)
return true
end
if ply:IsUserGroup("moderator") then
chat.AddText(Color(29, 0, 255), "[Mod] ", color1, prefixText, color2, ": "..text)
return true
end
if ply:IsUserGroup("trusted") then
chat.AddText(Color(255, 255, 0), "[Trusted] ", color1, prefixText, color2, ": "..text)
return true
end
if ply:GetNWString("usergroup") ~= "user" then
chat.AddText(Color(255, 0, 0, 255), "[" .. ply:GetNWString("usergroup") .. "] ", color1, ply:Nick(), color2, ": "..text)
return true
end
end)[/CODE]
Use elseif statements. Or better yet, put them into a table.
[QUOTE=code_gs;47288546]Use elseif statements. Or better yet, put them into a table.[/QUOTE]
I couldn't quite get it to work, it's only headadmin that doesn't work (turns up as "Admin" instead of "Head Admin")
[editline]9th March 2015[/editline]
Never mind, changed
if ply:IsAdmin() then
to
if ply:IsUserGroup("admin") then
A table is the most efficient way of doing this. It makes it easier to edit and change to your needs. Use a for loop with the table to gather the information.
[CODE]
RanksandTags = {}
RankandTags[1]={"superadmin", "[SuperAdmin]", Color(255, 0, 0, 255)}
RankandTags[2]={"admin", "[Admin]", Color(255, 0, 0, 255)}
RankandTags[3]={"donator", "[Donator]", Color(255, 0, 191)}
RankandTags[4]={"owner", "[Owner]", Color(127, 0, 95)}
RankandTags[5]={"headadmin", "[Head Admin]", Color(0, 255, 63)}
RankandTags[6]={"headmoderator", "[Head Moderator]", Color(255, 93, 0)}
RankandTags[7]={"moderator", "[Mod]", Color(29, 0, 255)}
RankandTags[8]={"trusted", "[Trusted]", Color(255, 255, 0)}
function ChatPrefixes(ply, message, teamchat, dead)
for k,v in pairs(RanksandTags) do
if ply:IsUserGroup(v[1]) then
chat.AddText(v[3], v[2], Color(255,255,255), ply:GetName()..":", message)
else
chat.AddText(Color(255,255,255), ply:GetName()..":", message)
end
hook.Add("OnPlayerChat", "ChatPrefixes", ChatPrefixes)[/CODE]
There may be some errors but this is the basic idea.
The point is to loop through the table and see if the player is the first argument in the table (v[1]).
After it detects that, it retrieves the third argument for the color (v[3]).
Then it gets the prefix name (v[2]).
And lastly prints the message.
Actually I will be nice but please learn from this
[lua]local ranks = {
developer = { "Developer", Color( 200, 0, 200 ) },
owner = { "Owner", Color( 252, 194, 0 ) },
superadmin = { "S. Admin", Color( 150, 0 ,255 ) },
admin = { "Admin", Color( 20, 180, 0 ) },
member = { "Member", Color( 0, 0, 255 ) },
user = { "Guest", Color( 255, 255, 255 ) },
}
local white = Color( 255, 255, 255 )
hook.Add( "OnPlayerChat", "Chat Tags", function( ply, txt, tonly )
local tab = {}
local rank = nil
if ply:IsPlayer() then
rank = ply:GetUserGroup()
end
if ranks[rank] != nil then
table.insert( tab, white )
table.insert( tab, "[" )
table.insert( tab, ranks[rank][2] )
table.insert( tab, ranks[rank][1] )
table.insert( tab, white )
table.insert( tab, "] " )
end
if !ply:IsPlayer() then
if !ply:Alive() then
table.insert( tab, Color( 255, 0, 0 ) )
table.insert( tab, "*DEAD* " )
end
if tonly then
table.insert( tab, Color( 0, 255, 0 ) )
table.insert( tab, "(TEAM) " )
end
table.insert( tab, team.GetColor( ply:Team() ) )
end
table.insert( tab, ply:Nick() )
table.insert( tab, white )
table.insert( tab, ": " )
table.insert( tab, str )
chat.AddText( unpack( tab ) )
return true
end )[/lua]
Set the ranks in the ranks table at the top, just put it in a clientside lua script. I'm not saying it will work with DarkRP because this is for stock gmod but you can hopefully use this to help you learn
I have a few examples too:
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/chat_tags/chat_tags_example.lua.html[/url]
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/chat_tags/simple_chat_tags_example_using_init_table.lua.html[/url]
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/chat_tags/simple_chat_tags_example_using_table_insert.lua.html[/url]
[ NOTE ] Remove .html to view / copy .Lua ...
Also, use color_white instead of re-defining it, not that it matters much but meh...
[QUOTE=ZombieWizzard;47291703]Actually I will be nice but please learn from this
[lua]local ranks = {
developer = { "Developer", Color( 200, 0, 200 ) },
owner = { "Owner", Color( 252, 194, 0 ) },
superadmin = { "S. Admin", Color( 150, 0 ,255 ) },
admin = { "Admin", Color( 20, 180, 0 ) },
member = { "Member", Color( 0, 0, 255 ) },
user = { "Guest", Color( 255, 255, 255 ) },
}
local white = Color( 255, 255, 255 )
hook.Add ("OnPlayerChat", "Chat Tags", function( ply, txt, tonly )
local rank = nil
if ply:IsPlayer() then
rank = ply:GetUserGroup()
end
if ranks[rank] != nil then
table.insert( tab, white )
table.insert( tab, "[" )
table.insert( tab, ranks[rank][2] )
table.insert( tab, ranks[rank][1] )
table.insert( tab, white )
table.insert( tab, "] " )
end
if !ply:IsPlayer() then
if !ply:Alive() then
table.insert( tab, Color( 255, 0, 0 ) )
table.insert( tab, "*DEAD* " )
end
if tonly then
table.insert( tab, Color( 0, 255, 0 ) )
table.insert( tab, "(TEAM) " )
end
table.insert( tab, team.GetColor( ply:Team() ) )
end
table.insert( tab, ply:Nick() )
table.insert( tab, white )
table.insert( tab, ": " )
table.insert( tab, str )
chat.AddText( unpack( tab ) )
return true
end )[/lua]
Set the ranks in the ranks table at the top, just put it in a clientside lua script. I'm not saying it will work with DarkRP because this is for stock gmod but you can hopefully use this to help you learn[/QUOTE]
Way to blow mine out of proportion. lol
You are much more experienced that me. But please learn from this like he said.
Sorry, you need to Log In to post a reply to this thread.