Restricting Chat Commands to Certain User Groups

I’m trying to figure out how I can have the user define his or her users groups they want to be able to access the chat commands to my addon in the config file. How could I do this? Below is what I think will work but I’m not sure.

The function



function HasPerms(ply)
	if not IsValid(ply) then return false end
	return (RAS.UserGroups[string.lower(ply:GetUserGroup())] or false)
end


The Config



RAS.UserGroups = {
	['owner'] 		= true,
	['superadmin'] 	= true,
	['admin'] 		= true,
	['moderator'] 	= true
}


If there’s no entry in the table it will return false regardless so you’re safe with that check.

Hell it all looks great. When you add the hook for the chat command, just call it and if true run. If you want you can also put the typical “you don’t have access to this command” is false

[editline]15th April 2016[/editline]

Kudos on not using table.HasValue as well, it runs slower.



function HasPerms(ply)
    if not IsValid(ply) then
        return false
    end
    return RAS.UserGroups[string.lower(ply:GetUserGroup())]
end


Should work already, no need to return “false” since it already returns nil/false when the usergroup is not in the table. make sure the table is accessable from the function.

[editline]15th April 2016[/editline]

Ninja’d damn! :v: