verifying usergroup with a table

Hey, so let’s say …



vip = {"trialmod", "moderator", "vip", "admin", "superadmin"}

// and I wanted it to work with 

TEAM_PRO = DarkRP.createJob("Pro Thief", {
    color = Color(0, 0, 0, 200),
    model = "models/player/arctic.mdl",
    description = [[a thief]],
    weapons = {"pro_lockpick"},
    command = "professional",
    max = 1,
    salary = 69,
    admin = 0,
    vote = false,
    hasLicense = false,
    category = "VIP",
    CustomCheckFailMsg = "This job is VIP only!",
    customCheck = function(ply) return ply:GetUserGroup() == vip end, // can i verify that the string is in the table?



The code doesn’t work. Can someone help me out please?

this line;



customCheck = function(ply) return ply:GetUserGroup() == vip end, // can i verify that the string is in the table?


considering this;



pyl:GetUserGroup() -- for example returns "trialmod"
vip -- returns {"trialmod","moderator","vip","admin","superadmin"}


is like saying;



"trialmod" == {"trialmod","moderator","vip","admin","superadmin"}


which will never be true, as one is a string and the other a table,

try using



table.HasValue(tbl,val)


like such;



customCheck = function(ply) return table.HasValue(vip,ply:GetUserGroup()) end --does the vip table contain the usergroup


I’ve heard you should use direct calling instead table.HasValue if its just for small things, for optimization?

Or you could do vip[ply:GetUserGroup()], if you have the ranks as keys. For example


vip = {
 ["superadmin"] = true,
 ["admin"] = true,
 ["vip"] = true
}

Try this, for optimization and re-usage purposes:


local AllowedGroups = {
   ["trialmod"] = true, 
   ["moderator"] = true, 
   ["vip"] = true, 
   ["admin"] = true, 
   ["superadmin"] = true
}

TEAM_PRO = DarkRP.createJob("Pro Thief", {
    color = Color(0, 0, 0, 200),
    model = "models/player/arctic.mdl",
    description = "A thief.",
    weapons = {"pro_lockpick"},
    command = "professional",
    max = 1,
    salary = 69,
    admin = 0,
    vote = false,
    hasLicense = false,
    category = "VIP",
    CustomCheckFailMsg = "This job is VIP only!",
    customCheck = function(ply) return AllowedGroups[ ply:GetNWString( "usergroup" ) ] end
}

Thank you. Your help is much appreciated.