Author Topic: Tags  (Read 5699 times)

0 Members and 1 Guest are viewing this topic.

Offline easer7

  • Newbie
  • *
  • Posts: 24
  • Karma: 1
Tags
« on: January 03, 2013, 08:44:35 PM »
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?

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Tags
« Reply #1 on: January 04, 2013, 03:01:57 AM »
ply:Nick() for the player's name
Experiencing God's grace one day at a time.

Offline easer7

  • Newbie
  • *
  • Posts: 24
  • Karma: 1
Re: Tags
« Reply #2 on: January 04, 2013, 12:30:46 PM »
Yes but where and how would I add it? And thank you very much for responding =D

Offline easer7

  • Newbie
  • *
  • Posts: 24
  • Karma: 1
Re: Tags
« Reply #3 on: January 04, 2013, 03:14:03 PM »
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?

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Tags
« Reply #4 on: January 04, 2013, 04:13:42 PM »
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.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline easer7

  • Newbie
  • *
  • Posts: 24
  • Karma: 1
Re: Tags
« Reply #5 on: January 05, 2013, 11:43:00 AM »
Thank you! You deserve a medal =3

Offline easer7

  • Newbie
  • *
  • Posts: 24
  • Karma: 1
Re: Tags
« Reply #6 on: January 05, 2013, 01:44:23 PM »
How do I make it so that the names are not the color of the tag though?

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Tags
« Reply #7 on: January 05, 2013, 04:57:39 PM »
Research/figure out if there's a way to turn color off/default, and set that command after the tag.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Tags
« Reply #8 on: January 05, 2013, 08:38:03 PM »
Insert the color you want before the player's name.
Experiencing God's grace one day at a time.

Offline easer7

  • Newbie
  • *
  • Posts: 24
  • Karma: 1
Re: Tags
« Reply #9 on: January 07, 2013, 04:50:41 PM »
Well I don't want it to be a certain color, I just want it to be the default.  So how would I add these tags in their specific colors, without affecting the colors of the names?

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Tags
« Reply #10 on: January 07, 2013, 05:48:50 PM »
Default color is approximately Color(150,200,255)
Experiencing God's grace one day at a time.

Offline easer7

  • Newbie
  • *
  • Posts: 24
  • Karma: 1
Re: Tags
« Reply #11 on: January 07, 2013, 06:12:23 PM »
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.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Tags
« Reply #12 on: January 07, 2013, 06:31:17 PM »
It's could be their team color.
Experiencing God's grace one day at a time.

Offline easer7

  • Newbie
  • *
  • Posts: 24
  • Karma: 1
Re: Tags
« Reply #13 on: January 07, 2013, 07:18:44 PM »
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.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Tags
« Reply #14 on: January 07, 2013, 08:57:58 PM »
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: [Select]
table.insert( tab, jobcolor .. pl:Name() .. ": " .. msg )
rather than
Code: [Select]
table.insert( tab, msg )
table.insert( tab, ": ")
table.insert( tab, pl:Nick() )
table.insert( tab, jobcolor )

Again, below is example, untested. 98% guaranteed not to work out of the box.
Code: [Select]
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)
« Last Edit: January 07, 2013, 09:02:57 PM by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming