• Print

Author Topic: Get users in group  (Read 4845 times)

0 Members and 1 Guest are viewing this topic.

Offline duckboy424

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
Get users in group
« on: October 20, 2016, 04:37:38 pm »
Hey, I'm trying to make it so that you can open up a menu and it has a list of all the players a user group called test. I would like to use DListView, if that is possible. Thanks for any type of assistance.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Get users in group
« Reply #1 on: October 20, 2016, 05:58:29 pm »
If you already know how to get them to show, I'm assuming you do by how you asked, but you could use
Code: Lua
  1. for k,v in pairs( player.GetAll() ) do
  2.     if v:GetUserGroup( "test" ) then
  3.         table.insert( someTable, v )
  4.     end
  5. end
  6.  

Just an example.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline duckboy424

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
Re: Get users in group
« Reply #2 on: October 20, 2016, 06:34:55 pm »
That's not what I was really looking for. I need to be able to get the names of all the players in a certain group and put it on a vgui menu. Players that aren't online as well, not just players that are on the server.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Get users in group
« Reply #3 on: October 20, 2016, 08:51:51 pm »
All group info is in the "ULib.ucl" table - You'd need to either cycle through or print table it to get the info, but I'm pretty sure it loads players in memory who aren't even connected.
Once you found the table key name, you could just cycle through it.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Get users in group
« Reply #4 on: October 21, 2016, 08:30:55 am »
Yeah sorry, it was late for me when I posted that, should've clarified to see what you meant. Like JamminR said, I know there is something that the default ulx motd uses that displays people who are in the user group even if they're not connected at the bottom, or something like that - sorry can't really remember - but you could probably use something like that. I'm not quite sure how ULib.ucl works, so I probably couldn't help there but it's probably the easiest way to do this.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Get users in group
« Reply #5 on: October 21, 2016, 02:46:20 pm »
More specifically, ULib.ucl.users has the info for each player you have stored using ULib.

(not real code, and I've not actually programmed in lua in years, so forgive me if my table-loop-fu is off, but you should get the general idea)
Code: [Select]
for i, kn in pairs(ULib.ucl.users) do
    testit = ULib.ucl.users[i]
    if lower(testit["group"]) == lower("<group you are looking for>")
        table.insert ( names, testit["name"] )
    end
end
-- now do vgui stuff with your table of "names"

« Last Edit: October 21, 2016, 02:48:21 pm by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Get users in group
« Reply #6 on: October 21, 2016, 03:43:04 pm »
So if that's how you would use it, Lua (or at least gLua) uses string.lower, instead of just "lower".
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

  • Print