Combining two custom checks into one?

Hello, I am having this issue where I can’t for the love of me figure out who to easily combine these two custom checks without causing issues.
The two custom checks are listed below and I would appreciate if any of you could help me figure out a way to do it.

Thanks in advance.

customCheck = function(ply) return table.HasValue({“trooper”}, ply:GetNWString(“usergroup”)) end

customCheck = function( ply ) return table.HasValue( { “trooper” }, ply:GetSecondaryUserGroup() ) end

table.HasValue returns true or false, so we can just use the and operator to tell us if they are both true, otherwise it will be false.

For example:
[lua]–where x is true and y is true
function() return x and y end --returns true, because: true && true == true

–where x is false and y is true
function() return x and y end --return false, because false && true == false (if it was true && false, this would still be the same case)

–where x is false and y is false
function () return x and y end --return false, because false && false == false[/lua]

So if you have two functions (table.HasValue) that give you true or false, you should be able to figure out how to combine the two, similar to above.

Check out truth tables for more info on how that logic works.

You should convert the temp value table into a stored hashtable for efficiency, but this is how you’d combine it:


local tAllowedGroups = {
	trooper = true
}

-- In jobtable..
customCheck = function(pPlayer)
	return (tAllowedGroups[pPlayer:GetUserGroup()] or tAllowedGroups[pPlayer:GetSecondaryUserGroup()]) == true
end

This does look very helpful, however I have many different jobs with many different ulx groups assigned to them. There is a donation option for a second character but the owner wanted to switch over to using ulx groups rather than a whitelisting system for the jobs. I don’t believe the above would work properly with many different groups, for ex;

trooper
marksman
heavy

just for an example.

It will, tables can have any amount of values you want.

Even when its assigned to another job? Each ulx group is for different jobs, so how would that look?

You would create a new table every time and put it above your job table declaration. Ex.


local tAllowedGroups = {
	trooper = true
}

-- In first jobtable
customCheck = function(pPlayer)
	return (tAllowedGroups[pPlayer:GetUserGroup()] or tAllowedGroups[pPlayer:GetSecondaryUserGroup()]) == true
end

local tAllowedGroups = {
	somegroup = true,
	somegroup2 = true
}

-- In second jobtable
customCheck = function(pPlayer)
	return (tAllowedGroups[pPlayer:GetUserGroup()] or tAllowedGroups[pPlayer:GetSecondaryUserGroup()]) == true
end

Gotcha, I’ll send a reference of what I have in a moment

[editline]1st August 2017[/editline]


local tAllowedGroups = {
	trooper = true
        admin = true
}

TEAM_UNASSIGNED = DarkRP.createJob("Clone Trooper", {
    color = Color(126, 36, 130, 255),
    model = 
	{
		"models/reizer_cgi_p2/clone_trp/clone_trp.mdl",
		"models/reizer_cgi_p2/clone_snow/clone_snow.mdl",
	},
    description = [[Clone Trooper]],
    weapons = 
	{
		"tfa_swch_dc15a",
		"tfa_dc15s_ashura",
		"clone_card_c1",
	},
    command = "clonetrooper",
    max = 0,
    salary = 10,
    admin = 0,
    vote = false,
    hasLicense = false,
    candemote = false,
    category = "Unassigned",
	customCheck = function(pPlayer)
	return (tAllowedGroups[pPlayer:GetUserGroup()] or tAllowedGroups[pPlayer:GetSecondaryUserGroup()]) == true
end
})

local tAllowedGroups = {
	marksman = true,
	admin = true
}

TEAM_UNASSIGNED = DarkRP.createJob("Clone Marksman", {
    color = Color(126, 36, 130, 255),
    model = 
	{
		"models/reizer_cgi_p2/clone_trp/clone_trp.mdl",
		"models/reizer_cgi_p2/clone_snow/clone_snow.mdl",
	},
    description = [[Clone Marksman]],
    weapons = 
	{
		"tfa_sw_repsnip",
		"tfa_dc15s_ashura",
		"clone_card_c1",
	},
    command = "clonemarksman",
    max = 0,
    salary = 10,
    admin = 0,
    vote = false,
    hasLicense = false,
    candemote = false,
    category = "Unassigned",
	customCheck = function(pPlayer)
	return (tAllowedGroups[pPlayer:GetUserGroup()] or tAllowedGroups[pPlayer:GetSecondaryUserGroup()]) == true
end
})

You’re missing a comma in the first table.

oh haha, it was just an example but thank you