DarkRP Combine Doors team restricting.

Okay,I have a script for opening a combine doors on maps like City17 and others. Classic sliding combine doors.
So, I need to make a whitelist for this doors, so only combines can open that doors using USE function(standing as E, as default).
I have a script, but it’s not working, I have no error’s, just no one can open doors with this script.
If someone can repair it, thanks you!
Gamemode DarkRP.

Script, in folder garrysmod/lua/autorun/server/combinedoors.lua:


local foo = {
timer.Simple(1, function()
   foo[1] = TEAM_HELIX
   foo[2] = TEAM_CMD_SEC
end)}
local tbl = {
    jobs = ["TEAM_HELIX"] = true,
    doors = {
        ["func_door"] = true,
        ["prop_door_rotating"] = true,
        ["prop_dynamic"] = true
    }
}

-- Jobs does not exist until the gamemode has loaded, so we're gonna do it in here.
hook.Add("InitPostEntity", "insertJobs", function()
    local jobs = {
        [TEAM_HELIX] = true,
    }

    table.Merge(tbl.jobs, jobs);
end);

hook.Add("PlayerUse", "openDoors", function(ply, ent)
    if (not IsValid(ply) or not IsValid(ent)) then return; end

    local tr = util.TraceLine({
        start = ply:GetPos(),
        endpos = ply:GetShootPos() + ply:GetAimVector() * 100,
        filter = ply
    });

    if (IsValid(tr.Entity) and tbl.doors[tr.Entity:GetClass()]) then
        if (tbl.jobs[ply:Team()]) then
            -- If the door is locked then it won't open, uncomment this to make the doors unlock and open
            -- tr.Entity:Fire("unlock");
            tr.Entity:Fire("open", "", .5);
        end
    end
end); 

Also, I have a clean door opening function, without whitelisting.
There it is:


function KeyPressedUse (ply, key) 
    if key == IN_USE then  
        local t = {}    
        t.start = ply:GetPos()    
        t.endpos = ply:GetShootPos() + ply:GetAimVector() * 100    
        t.filter = ply
        local trace = util.TraceLine(t)           
        if trace.Entity and trace.Entity:IsValid() and (trace.Entity:GetClass() == "func_door" or trace.Entity:GetClass() == "prop_door_rotating" or trace.Entity:GetClass() == "prop_dynamic") then
            trace.Entity:Fire("Open")
        end
    end
end
hook.Add( "KeyPress", "KeyPressedUse", KeyPressedUse  )

Sorry for my bad English!

Well… No answer.

If your getting errors post them, I doubt you’ll get any help otherwise.

There’s no errors. It’s just don’t work. When i’m making a team restricting with this codes, no one can open this door.

Edited a post, so it can be more informative.

What map and what door are you trying to open? If the door class is not listed in the table then it will not work.

What you have seems to be a edited script that I gave you?



local tbl = {
    jobs = {},
    doors = {
        ["func_door"] = true,
        ["prop_door_rotating"] = true,
        ["prop_dynamic"] = true
    }
}

-- Jobs does not exist until the gamemode has loaded, so we're gonna do it in here.
hook.Add("InitPostEntity", "insertJobs", function()
    -- ADD JOBS HERE, NOT IN THE TABLE ABOVE!
    local jobs = {
        [TEAM_HELIX] = true,
    }

    table.Merge(tbl.jobs, jobs);
end);

hook.Add("PlayerUse", "openDoors", function(ply, ent)
    if (not IsValid(ply) or not IsValid(ent)) then return; end

    local tr = util.TraceLine({
        start = ply:GetPos(),
        endpos = ply:GetShootPos() + ply:GetAimVector() * 100,
        filter = ply
    });

    if (IsValid(tr.Entity) and tbl.doors[tr.Entity:GetClass()]) then
        if (tbl.jobs[ply:Team()]) then
            -- If the door is locked then it won't open, uncomment this to make the doors unlock and open
            -- tr.Entity:Fire("unlock");
            tr.Entity:Fire("open", "", .5);
        end
    end
end);


Use this and make sure you are close enoguh, the door class is in the table and you are the right job! If you edited the script and save it while the server is running then the table is empty which will require you to restart the server to make it work again.

Now I put it into darkrpmodification/modules but it’s also doesn’t work.

Please read my post again, nowhere did i say you need to put it in darkrpmodifications

OK, I have a working solution, later I drop it into this thread and close it.