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!