How to add more than 1 team restriction.

Hi, I team restricted a command “/raid” for RP actions so only thiefs can use it, my dilemma is no matter what code I use i can’t make it so more than one team can use it, here the team restriction code


if CLIENT then
net.Receive("mugcall", function(len, CLIENT)
local mugcaller = net.ReadString()
local ply = LocalPlayer()
if ply:Team() ~= TEAM_BANDIT then
ply:ChatPrint("You cannot use this command")
elseif ply:IsAdmin() or ply:IsSuperAdmin() then
chat.AddText( Color(0,0,0), "[MUG] ",  Color(128,128,128), mugcaller..": ", Color(255,255,255), "Called A Mug!")
else
chat.AddText( Color(0,0,0), "[MUG] ",  Color(128,128,128), "Someone"..": ", Color(255,255,255), "Called A Mug!")
end
end)
end

Here is exactly what I need help with



if ply:Team() ~= TEAM_BANDIT then
ply:ChatPrint("You cannot use this command")
elseif ply:IsAdmin() or ply:IsSuperAdmin() then
chat.AddText( Color(0,0,0), "[MUG] ",  Color(128,128,128), mugcaller..": ", Color(255,255,255), "Called A Mug!")
else
chat.AddText( Color(0,0,0), "[MUG] ",  Color(128,128,128), "Someone"..": ", Color(255,255,255), "Called A Mug!")
end
end)
end

I need to be able to add another team to if ply:Team() ~= TEAM_BANDIT

Any help will be appreciated, thanks!

Should be able to add “or” to the if statement.
Or just make a table and compare their team to values inside of the table?

I tried the or and it breaks the code. it doesn’t return script error, but it returns the “You cannot use this command” no matter what job (TEAM) I am. I’ve tried it multiple ways first of which being


if ply:Team() ~= TEAM_BANDIT or if:Ply:Team() ~= TEAM_THIEF then
ply:ChatPrint("You cannot use this command")

Second if which being


if (ply:Team() ~= TEAM_BANDIT or if:Ply:Team() ~= TEAM_THIEF) then
ply:ChatPrint("You cannot use this command")

With both of these bits I cannot use the command at all no matter what TEAM I am, it returns with “You cannot use this command”

does that not error?

It doesn’t error, but then no matter what TEAM i join, I get the return “you cannot use this command”

You should be handling checks like this through the server not the client


if not (ply:Team() == TEAM_BANDIT or ply:Team() == TEAM_THIEF) then

This code,


if not (ply:Team() == TEAM_BANDIT or ply:Team() == TEAM_THIEF) then

doesn’t seem to work either. Tried with and without the parenthesis.



local allowedTeams = {
	TEAM_BANDIT,
	TEAM_THIEF,
	TEAM_WHATEVER
}

if CLIENT then -- wait what?
	net.Receive("mugcall", function(len, CLIENT) -- ._.
		local mugcaller = net.ReadString()
		local ply = LocalPlayer()
		if not mugcaller then return end -- why even bother?
		if table.HasValue(allowedTeams, ply:Team()) or ply:IsAdmin() or ply:IsSuperAdmin() then --Admin abuse levels rising
			chat.AddText( Color(0,0,0), "[MUG] ",  Color(128,128,128), mugcaller..": ", Color(255,255,255), "Called A Mug!")
		else
			chat.AddText( Color(255,0,0), "This job cannot mug!")
		end
	end) -- Someone remind me why a net message is needed for this?
end


[lua]local allowedTeams = {
TEAM_BANDIT = true,
TEAM_THIEF = true,
TEAM_WHATEVER
}
if CLIENT then
net.Receive(“mugcall”, function(len)
local mugcaller = net.ReadString()
local ply = LocalPlayer()

    if allowedTeams[ mugcaller ] or ply:IsAdmin() then -- Superadmins are admins too
        for i,v in pairs(player.GetAll()) do
            chat.AddText( Color(0,0,0), "[MUG] ", Color(128,128,128), mugcaller..": ", Color(255,255,255), "Called a mug!")
        end
    else
        chat.AddText( Color(255,0,0), "This job cannot mug!")
    end
 end)

end[/lua]

Better performance. Might not mean a lot in this case but for larger tables it would as instead of looping over an entire table all we’re doing here is looking at 1 specific point in the table. Just a good practice

Best solution, but… Why are you looping through all players on client-side? It doesnt make sense, but anyway, i think its good enough for scriptfodder :v:

(can someone ban Sir TE5T from ratings?)

OH FUCK, thought it was supposed to notify everyonse like /advert used to do. Just remove the for loop

Edit:
do not write code at 5 am

klaes, I sent you a PM let me know if you got it. or add me on steam so we can talk http://steamcommunity.com/id/SlyXPG/