Reputation: 13
In Garry's Mod I'm trying to make it so only certain user groups could use context menu. But it only works either for vip or superadmin user groups. Not for both. Could anyone tell me what might be wrong?
hook.Add("ContextMenuOpen", "SuperAdminContext", function()
if not LocalPlayer():IsSuperAdmin() or LocalPlayer():IsUserGroup("vip") then return false end end)
Upvotes: 1
Views: 112
Reputation: 2244
Your condition is combining wrong. The code hides the menu if the user is not a superadmin — so far so good — or if the user is a vip — which is quite wrong on both counts. Instead, one of two approaches: either make sure that 1) for all possible groups to show, the user is not in them (using and
to ensure all conditions apply), or 2) none of the possible groups to show applies (using or
and parentheses to group). Examples of each:
if not LocalPlayer():IsSuperAdmin() and not LocalPlayer():IsUserGroup("vip") then
if not (LocalPlayer():IsSuperAdmin() or LocalPlayer():IsUserGroup("vip")) then
Negation with Boolean logic is notoriously tricky, but it almost always boils down to a question of carefully considering the details.
Truth tables can help. Here's the truth table for our desired composite condition:
IsSuperAdmin() IsUserGroup("vip") Result (hide menu)
False False True
True False False
False True False
True True False
This looks exactly like the standard truth table for or
, except that the last column is precisely inverted. That's a good sign that approach 2 is a good match.
Upvotes: 1