ULX

Author Topic: "Grabbing" the ulib groups  (Read 2855 times)

0 Members and 1 Guest are viewing this topic.

Offline Bite That Apple

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 416
  • Apple Innovations 2010®
    • Fun 4 Everyone Gaming
"Grabbing" the ulib groups
« on: February 03, 2013, 08:08:03 PM »
Hi, I'm somewhat fairly new to lua, so sorry if what I'm asking makes me sound dumb, and or doesn't make sense..


Code: [Select]
local Tags =
{
--Group    --Tag     --Color
{"admin", "[ADMIN] ", Color(0, 0, 255, 255) },
{"superadmin", "[SUPERADMIN] ", Color(255, 0, 0, 255) },
{"owner", "[", Color(255, 255, 255, 255), "Owner", "] ", Color(255, 255, 255, 255) }
}

hook.Add("OnPlayerChat", "Tags", function(ply, strText)
for k,v in pairs(Tags) do
if ply:IsUserGroup(v[1]) then
local nickteamcolor = team.GetColor(ply:Team())
local nickteam = team.GetName(ply:Team())
chat.AddText(v[3], v[2], nickteamcolor, nickteam, v[6], v[5], nickteamcolor, ply:Nick(), color_white, ": ", Color(255, 255, 255, 255), strText)
return true
end
end
end )


You can assume what this going to do, but what to make it basically fully automatic so people don't have to add things to the {table} so it works properly, Anyways. I wanted to know the (or if one does exist) or a way so I can get this here -> ply:IsUserGroup(v[1]) to grab all ulib groups?

Any suggestions, help, tutorial, and or wiki would be much appreciated.



** also, sorry if this is in the incorrect section, if so please just move it :)**
« Last Edit: February 03, 2013, 08:15:25 PM by chaos13125 »
Quote from: John F. Kennedy 1963
A man may die, nations may rise and fall, but an idea lives on.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: "Grabbing" the ulib groups
« Reply #1 on: February 03, 2013, 08:15:36 PM »
The Ulib groups table is stored in ucl.groups (or, ULib.ucl.groups)
And please, though our forum 'allows' it, please, please, please shrink your signature image. :)
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Bite That Apple

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 416
  • Apple Innovations 2010®
    • Fun 4 Everyone Gaming
Re: "Grabbing" the ulib groups
« Reply #2 on: February 03, 2013, 08:24:47 PM »
I've changed my signature to something about 10x smaller now, I hope it's okay.

Anyways, thank you I'm going to mess around now see if I can get it to work and than get back to this if it worked or not. :)
Quote from: John F. Kennedy 1963
A man may die, nations may rise and fall, but an idea lives on.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: "Grabbing" the ulib groups
« Reply #3 on: February 03, 2013, 08:52:16 PM »
You'll need to parse the table of course. :) for pairs is your friend.
I'll leave that to you to figure out.

As for the signature, my easily distracted vision impaired eyes thank you!
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Bite That Apple

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 416
  • Apple Innovations 2010®
    • Fun 4 Everyone Gaming
Re: "Grabbing" the ulib groups
« Reply #4 on: February 04, 2013, 12:19:28 AM »
Didn't seem to understand what you all meant, but it is 4:19AM, so I shall go to bed and hopefully understand a bit more. I do thank you for your reply.
Quote from: John F. Kennedy 1963
A man may die, nations may rise and fall, but an idea lives on.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: "Grabbing" the ulib groups
« Reply #5 on: February 04, 2013, 07:42:50 AM »
You don't need to parse the ulib groups to do this. ULib automatically assigns groups to teams (or that might be ULX) either way, just try this...


Code: [Select]
function ChatTags(ply, strText)

chat.AddText(Color(0,0,0,255), "[", team.GetName(ply:Team()), "]", team.GetColor(ply:Team()), ply:Nick(), Color(255,255,255,255), ": ", strText)
        return true

end
hook.Add("OnPlayerChat", "Tags", ChatTags)

my only concern is that since you are intercepting chat and returning another value with true will this not break all other chat hooks?
nevermind. This is the client version not the serverside version. The above code should work fine for what you need.
« Last Edit: February 04, 2013, 07:47:32 AM by MrPresident »

Offline Bite That Apple

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 416
  • Apple Innovations 2010®
    • Fun 4 Everyone Gaming
Re: "Grabbing" the ulib groups
« Reply #6 on: February 04, 2013, 03:33:18 PM »
Thank you Mr. President.

Also, thank you as well JamminR. :)

Karma for both of you.
Quote from: John F. Kennedy 1963
A man may die, nations may rise and fall, but an idea lives on.