Author Topic: [Solved] Listing group members  (Read 1499 times)

0 Members and 1 Guest are viewing this topic.

Offline Dragoboss

  • Newbie
  • *
  • Posts: 3
  • Karma: 1
[Solved] Listing group members
« on: February 12, 2015, 02:45:58 AM »
(I did in fact use the search function, with multiple keyword combinations, didn't find anything.
if there is in fact another similar topic then I am terribly sorry, but I couldn't find it).


I was wondering if there was a function or hook or anything in ULib or ULX that would allow me to allow me to list the names of the users of a defined group easily, without having to write a whole load of lines for it.
The reason for me to ask this, is because I have a custom in-game menu, replacing the motd, with multiple pages and shortcut buttons, on which I also display a list of the 'staff members' of my server.
Now. I am fine with updating it every time a change is made in my staff team, but it would be easier to have it done automatically if at all possible.

I have been messing around some of the existing ULib functions but have not been able to do this yet.
Would anyone here know an easy / effective way to do it?

Thanks in advance,
-Drago
« Last Edit: February 15, 2015, 03:20:30 AM by Dragoboss »

Offline Stickly Man!

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 1270
  • Karma: 164
  • What even IS software anymore?
    • XGUI
Re: Listing group members
« Reply #1 on: February 12, 2015, 08:57:48 AM »
I think you can get the data from the ULib.ucl.users table, but you'll have to iterate through it and check the group:

Code: [Select]
for _, ply in pairs(ULib.ucl.users) do
  if ply[group] == "staff" then
    -- This is a staff member! Use ply[name] to get their name.
  end
end

This information may not be available to regular users, if I'm remembering correctly. You may want to populate the list on the server then send it to clients when they connect. (Sorry, that may be a bit of code :( )

Hope this helps!
« Last Edit: February 12, 2015, 09:01:32 AM by Stickly Man! »
Join our Team Ulysses community discord! https://discord.gg/gR4Uye6

Offline Dragoboss

  • Newbie
  • *
  • Posts: 3
  • Karma: 1
Re: Listing group members
« Reply #2 on: February 15, 2015, 12:56:55 AM »
Alrighty. Thanks Stickly.
I have figured out you need quotes around the 'group' part within the brackets.
Yet I don't quite get it sent to the clients yet. Either way I can get the tables of users as I want them now.
I will figure out the sending sooner or later.

To those who need this, too, this is my current serverside-code to find and send the tables of users in group.
Code: [Select]
if (SERVER) then
hook.Add( "Initialize", "GetStaff", function()
util.AddNetworkString("sendAdmins")
util.AddNetworkString("sendMods")
local adminTable = {}
local moderatorTable = {}
for _,ply in pairs(ULib.ucl.users) do
if ply["group"] == "superadmin" or ply["group"] == "admin" then
table.insert(adminTable, 1, ply["name"])
elseif ply["group"] == "moderator" then
table.insert(moderatorTable, 1, ply["name"])
end
end
net.Start("sendAdmins")
net.WriteTable(adminTable)
for _,ply in pairs(player.GetAll()) do
net.Send(ply)
end
net.Start("sendMods")
net.WriteTable(moderatorTable)
for _,ply in pairs(player.GetAll()) do
net.Send(ply)
end
end)
end

I should probably change when it hooks and such....
Anyways, thanks again. Now I just have to hope I figure out how to properly send it and list it in my F1 interface :3

Offline Dragoboss

  • Newbie
  • *
  • Posts: 3
  • Karma: 1
[Solved] Listing group members
« Reply #3 on: February 15, 2015, 03:19:16 AM »
My final solution, thanks to Stickly Man for the initial answer.
Server-side autorun:
Code: [Select]
if (SERVER) then
local adminTable = {}
local moderatorTable = {}
hook.Add( "Initialize", "GetStaff", function()
util.AddNetworkString("sendAdmins")
util.AddNetworkString("sendMods")
for _,ply in pairs(ULib.ucl.users) do
if ply["group"] == "superadmin" or ply["group"] == "admin" then
table.insert(adminTable, 1, ply["name"])
elseif ply["group"] == "moderator" then
table.insert(moderatorTable, 1, ply["name"])
end
end
end)
hook.Add( "PlayerAuthed", "sendStaff", function()
print("StaffListing: 20 seconds delay")
timer.Simple( 20, function()
print("StaffListing: sending to clients")
net.Start("sendAdmins")
net.WriteTable(adminTable)
for _,ply in pairs(player.GetAll()) do
net.Send(ply)
end
net.Start("sendMods")
net.WriteTable(moderatorTable)
for _,ply in pairs(player.GetAll()) do
net.Send(ply)
end
end)
end)
end

Client-side autorun:
Code: [Select]
net.Receive("sendAdmins", function(len)
adminTable = net.ReadTable()
table.sort(adminTable)
end)
net.Receive("sendMods", function(len)
moderatorTable = net.ReadTable()
table.sort(moderatorTable)
end)

Client-side F1 Help Menu: (fonts, colors, etc, are for my custom F1 help screen, if you use this code you'd have to edit it to your needs).
Code: [Select]
draw.WordBox( 5, 22, 485, "  Admin   ", "sText", Color( 114, 30, 114 ), Color( 255, 255, 255 ) )
surface.SetTextColor( 0, 0, 0, 255 )
surface.SetFont( "sSmall" )
for i = 1, #adminTable do
surface.SetTextPos(22, 495 + (i*15))
surface.DrawText(adminTable[i])
end
draw.WordBox( 5, 578, 485, " Moderator", "sText", Color( 50, 45, 250 ), Color( 255, 255, 255 ) )
surface.SetTextColor( 0, 0, 0, 255 )
surface.SetFont( "sSmall" )
for i = 1, #moderatorTable do
surface.SetTextPos(578, 495 + (i*15))
surface.DrawText(moderatorTable[i])
end