So I have a custom function that uses this
[lua]
if calling_ply:IsUserGroup( "Owner" ) then[/lua]
but I need it work with multiple groups like this
[lua]
if calling_ply:IsUserGroup( "Owner", "Head Admin", "Server Manager", "Helper", "admin", "superadmin" ) then[/lua]
But as you may know, it doesn't work. How do I make it so it checks the multiple groups?
[del]it accepts strings so i assume you could do some sort of array with it and take all of the strings from the array (idk, im probably explaining it badly and i suck at lua but i assume something like that could work)[/del]
no
use a table or, or
if calling_ply:IsUserGroup("owner" || calling_ply:IsUserGroup("admin") ) then
i recommend a table
Maybe you can use:
[lua]
ply:CheckGroup( <lowest group in your list here> )
[/lua]
For example if you have groups such as
Owner
Head Admin
Superadmin
Admin
...
Helper
then you will use ply:CheckGroup("Helper") and it will return true if the player is in Helper group or "above"
Otherwise, if you want to check for just groups in your list, then I would use a table, like this:
[lua]
local allowedGroups =
{
["Owner"] = true,
["Head Admin"] = true,
["Server Manager"] = true,
["Helper"] = true,
["admin"] = true,
["superadmin"] = true,
}
if allowedGroups[ ply:GetUserGroup() ] then -- player is in one of the allowed groups
[/lua]
[url]http://ulyssesmod.net/docs/files/lua/ulib/shared/sh_ucl-lua.html[/url]
[quote]The above wouldn't work[/quote] Oops, fixed :P
The above wouldn't work, because that's searching for the key of the usergroup where in the table the group is the value. To make it work you would need to use table.HasValue which is more resource intensive than my suggestion below.
Table Example:
[lua]
local ranks = {
Owner = true,
...
}
if ranks[calling_ply:GetUserGroup()] then
...
end
[/lua]
Thank you Jarva, works perfect. I really appreciate the help.
Last I checked, Ulysees didn't allow spaces in group names
Sorry, you need to Log In to post a reply to this thread.