• Context menu / c-menu enabled only for certain ulx usergroups/jobs
    3 replies, posted
Good day to you wonderful people! I've been trying to disable the c-menu for everyone except some ulx usergroups or jobs. Been looking around other forums and such, sadly couldn't find much. I've found two codes, which are strictly only for either an admin or superadmin usergroup (both of them shown below - sorry for not putting them into the code format but whenever i did it screwed up all the spacing and such so it looked very weird) hook.Add("ContextMenuOpen", "AdminContext", function()     if not LocalPlayer():IsAdmin() then return false else return true end end) hook.Add("ContextMenuOpen", "SuperAdminContext", function()     if not LocalPlayer():IsSuperAdmin() then return false end end) So i tried making my own one, but sadly it didn't work. This is the code i used: hook.Add( "ContextMenuOpen", "ContextMenu", function( ply ) return ply:Team() == TEAM_STAFFONDUTY or ply:Team() == TEAM_EVENT or ply:Team() == TEAM_ENGCOM or ply:Team() == TEAM_ENGTRP or ply:SteamID() == "STEAM_0:1:00000001" or ply:IsUserGroup( "superadmin" ) end ) Whenever i try to open up the c-menu with this code a console error appears, no matter if i'm in a group or job that would allow it or not the following error appears: [ERROR] lua/autorun/client/cl_contextmenu.lua:2: attempt to index local 'ply' (a nil value)   1. fn - lua/autorun/client/cl_contextmenu.lua:2    2. Call - addons/ulib/lua/ulib/shared/hook.lua:109     3. Call - gamemodes/sandbox/gamemode/spawnmenu/contextmenu.lua:217      4. unknown - gamemodes/base/gamemode/cl_spawnmenu.lua:62       5. unknown - lua/includes/modules/concommand.lua:54 I would higly appreciate any kind of help, as you can see i'm not really good at coding, just trying my best. Also the file is named as cl_contextmenu.lua and i've put it under garrysmod/lua/autorun/client if that helps in any way. Sorry for the long post, hopefully someone can lend a helping hand. Thank you for reading and have a wonderful day!
hook.Add( "ContextMenuOpen", "ContextMenu", function() local ply = LocalPlayer() return ply:Team() == TEAM_STAFFONDUTY or ply:Team() == TEAM_EVENT or ply:Team() == TEAM_ENGCOM or ply:Team() == TEAM_ENGTRP or ply:SteamID() == "STEAM_0:1:00000001" or ply:IsUserGroup( "superadmin" ) end ) The hook does not pass a player as an argument. You need to use LocalPlayer() to get the client player object.
You can do it @marc0303's way, or you could do it using a table like so; local Whitelist_Context = {} Whitelist_Context[TEAM_STAFFONDUTY] = true Whitelist_Context[TEAM_EVENT] = true Whitelist_Context[TEAM_ENGCOM] = true Whitelist_Context[TEAM_ENGTRP] = true Whitelist_Context["STEAM_0:1:00000001"] = true -- example steamid Whitelist_Context["owner"] = true -- ulx group 'owner' hook.Add("ContextMenuOpen", "ContextMenu", function()     local ply = LocalPlayer()     return Whitelist_Context[ply:Team()] or Whitelist_Context[ply:SteamID()] or Whitelist_Context[ply:GetUserGroup()] or ply:IsSuperAdmin() end)
Thank you both very much! Tested it out, and now it works! Again, thank you both for taking your time and helping me out, very much appreciated! Have a wonderful day!
Sorry, you need to Log In to post a reply to this thread.