ULX

Author Topic: Is this how to properly restrict the spawn and context menus to certain ranks?  (Read 5737 times)

0 Members and 1 Guest are viewing this topic.

Offline VORTEXGaming

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
Code: [Select]
if SANDBOX:SpawnMenuOpen() then
function checkULX(ply)
    if table.HasValue({"owner", "dev", "superadmin"}, ply:GetNWString("usergroup")) then
        return true
else return false
    end
end

if GM:ContextMenuOpen() then
function checkULX(ply)
    if table.HasValue({"owner", "dev", "superadmin"}, ply:GetNWString("usergroup")) then
        return true
else return false
    end
end

Offline BlueNova

  • Full Member
  • ***
  • Posts: 113
  • Karma: 13
  • The most powerful force in the universe.
Do you mean the auto pop up motd menu?

Offline VORTEXGaming

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
Look at the title

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
In simplest answer, no, that is not correct.
SANDBOX:SpawnMenuOpen and GM:ContextMenuOpen are HOOKS.
You monitor for hooks using hook.Add

Add hook looks for the events you want, and then calls a function passing some information, usually the player that caused the event.
You could write functions to then check the player's group and return false if they were not a member of your groups you want.

You'd also likely want to check, the way you're currently checking, using ULib's GetUserGroup.
I'm not sure your GetNW string would work consistently or at all.
If you don't use ULib, unfortunately, GMod's closest check is Player:IsUserGroup. With that, you'd have to do a for loop through your table checking if player was part of the table.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Alpha Universe

  • Newbie
  • *
  • Posts: 11
  • Karma: 0
@JamminR What is the correct Code then?

An Error Has Occurred!

array_keys(): Argument #1 ($array) must be of type array, null given