Get a table of available commands for current rank in ULX?
7 replies, posted
How do I get the available commands for a ULX rank in LUA? I need to get a table of the available commands to a players current rank.
-snip- Sorry I read it wrong. I don't know :/
[QUOTE=Handsome Matt;43388782]I hope you appreciate this, I just had to try and navigate through ULX/ULIB source code for this. Because nothing is consistent in that mess of an admin mod try looping either of these: [I]ulx.cmdsByCategory or ULib.sayCmds[/I].
The actual command table is localized and has no method to expose it so.. I hate ULX.[/QUOTE]
Agreed with every point there. This is a function I wrote a long time ago and didn't comment at all, after a lot of swearing at ULX, when I finished it it felt wonderful. I'm pretty sure you give it a player and it gives you a list of commands they have access to...
[lua]
local function PrepareSayCmdTable(ply)
ply = IsValid(ply) and ply or nil
local canQuery = ply and true or false
local t = {}
local i = ULib.sayCmds
for cmd,props in pairs(i) do
local v = {}
v.chatcmd = cmd
v.concmd = props.__cmd
v.access = props.access
v.plyAllowed = true
if canQuery then
v.plyAllowed = ULib.ucl.query(ply,v.access)
end
table.insert(t,v)
end
return t
end
[/lua]
You can easily do it by directly going to the group table and pulling the data. Here's what I just whipped up which does exactly what you need:
[CODE]
concommand.Add("printgroupaccess", function()
for k, v in pairs(ULib.ucl.groups['admin']['allow']) do
print(v)
end
end)
[/CODE]
[QUOTE=Dongahh;43389295]You can easily do it by directly going to the group table and pulling the data. Here's what I just whipped up which does exactly what you need:
[CODE]
concommand.Add("printgroupaccess", function()
for k, v in pairs(ULib.ucl.groups['admin']['allow']) do
print(v)
end
end)
[/CODE][/QUOTE]
Does that get commands that are allowed by inheritance as well?
[QUOTE=wh1t3rabbit;43389398]Does that get commands that are allowed by inheritance as well?[/QUOTE]
I'm not sure too be honest. I'll give it a test now, if it doesn't you can just go through the inheritance and add to the table you're making. I'll post back with results in a few minutes.
[editline]3rd January 2014[/editline]
Well, you're right it doesn't grab inherited commands. I did a check for inheritance and if it was, it would grab the inherited groups commands but if that group inherits commands it doesn't grab them.
Tl;dr: your way works, mine doesn't.
[QUOTE=Handsome Matt;43388782]I hope you appreciate this, I just had to try and navigate through ULX/ULIB source code for this. Because nothing is consistent in that mess of an admin mod try looping either of these: [I]ulx.cmdsByCategory or ULib.sayCmds[/I].
The actual command table is localized and has no method to expose it so.. I hate ULX.[/QUOTE]
Perfect! Thanks :D
Sorry, you need to Log In to post a reply to this thread.