Permanently lock or remove special doors

So, I need a script that makes me able to remove or lock special doors. Like on rp_downtown_v2…now all doors are unlocked but I want the jail doors to be locked or removed. Is there a way to do? Maybe a serverside script with a command in console…for superadmins on assmod/ulx only.

**[Ents.FindInBox

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Ents.FindInBox)**

[lua]concommand.Add(“RemoveDoor”, function(ply, cmd, args)
if ply:IsSuperAdmin() then
local trace = ply:GetEyeTrace();
if trace.Entity and trace.Entity:IsValid() and trace.Entity:GetClass():find(“func_door”) then
trace.Entity:Remove()
end
end
end)[/lua]

[lua]concommand.Add(“LockDoor”, function(ply, cmd, args)
if ply:IsSuperAdmin() then
local trace = ply:GetEyeTrace();
if trace.Entity and trace.Entity:IsValid() and trace.Entity:GetClass():find(“func_door”) then
trace.Entity:Fire(“lock”)
end
end
end)[/lua]

Run those console commands while looking at the doors.

Will the doors still be locked/removed after mapchange? That would be awesome.

Try this.

[lua]local EditTbl = {}

local function SaveMapTable()
file.Write(“mapeditor.txt” , glon.encode(EditTbl))
end

local function LoadMapTable()
EditTbl = glon.decode(file.Read(“mapeditor.txt”)) or {}
for k , v in ipairs(ents.GetAll()) do
for a , b in pairs(EditTbl) do
if b.pos == v:GetPos() then
if b.lock then
v:Fire(“lock”)
elseif b.remove then
v:Remove()
end
end
end
end
end
hook.Add(“InitPostEntity” , “EditEnts” , LoadMapTable)

local function AddEntityToTable(pl , cmd , args)
if pl:IsSuperAdmin() then
local tr = pl:GetEyeTrace()
if tr.Entity and ValidEntity(tr.Entity) and string.find(tr.Entity:GetClass() , “door”) then
if string.lower(args[1]) == “lock” then
table.insert(EditTbl , {tr.Entity:GetPos() , lock = true})
tr.Entity:Fire(“lock”)
elseif string.lower(args[1]) == “remove” then
table.insert(EditTbl , {tr.Entity:GetPos() , remove = true})
tr.Entity:Remove()
end

	end
end

end
concommand.Add(“edit_ents” , AddEntityToTable)
[/lua]

Thanks |FlapJack| but it doesn’t work. I also tried to outcommend the if pl:IsSuperAdmin() to see if it even works for normal users but it doesn’t give any errors. And it creates the .txt!

He didn’t hook the LoadMapTable function. It should be hooked to InitPostEntity.

Completely forgot to hook it. I had to finish it up quickly - to go eat.

[editline]07:25PM[/editline]

Try now. Also, you need to add “lock” or “remove” as arguments to the command when you run it, depending on what you want to do with the door.

You should also make it lock or remove the entity when the edit_ents command is called so the map doesn’t have to be restarted for it to take effect.

Doesn’t work.

[lua]local EditTbl = {}

local function SaveMapTable()
file.Write(“mapeditor.txt” , glon.encode(EditTbl))
end

local function LoadMapTable()
EditTbl = glon.decode(file.Read(“mapeditor.txt”)) or {}
for k , v in ipairs(ents.GetAll()) do
for a , b in pairs(EditTbl) do
if b.pos == v:GetPos() then
if b.lock then
v:Fire(“lock”)
elseif b.remove then
v:Remove()
end
end
end
end
end
hook.Add(“InitPostEntity” , “EditEnts” , LoadMapTable)

local function AddEntityToTable(pl , cmd , args)
if pl:IsSuperAdmin() then
local tr = pl:GetEyeTrace()
if tr.Entity and ValidEntity(tr.Entity) and string.find(tr.Entity:GetClass() , “door”) then
if string.lower(args[1]) == “lock” then
table.insert(EditTbl , {tr.Entity:GetPos() , lock = true})
tr.Entity:Fire(“lock”)
elseif string.lower(args[1]) == “remove” then
table.insert(EditTbl , {tr.Entity:GetPos() , remove = true})
tr.Entity:Remove()
end

	end
end

end
concommand.Add(“edit_ents” , AddEntityToTable)[/lua]

Might cause problems removing the ent as soon as you insert its position into the table. Not too sure. If it is, just replace tr.Entity:Remove() with timer.Simple(0.5 , function(e) e:Remove() end , tr.Entity )

[editline]07:38PM[/editline]

What about it doesn’t work? Telling me to fix something without telling me what isn’t working doesn’t really help. I don’t have the time to test it myself.

There are no errors but it doesn’t lock/remove the door. The mapeditor.txt file gets created.

The content is:


1-1454139-142alock1-1454139-142aremove1-1454139-142alock1-1454139-142alock

Try this.

[lua]local EditTbl = {}

local function SaveMapTable()
file.Write(“mapeditor.txt” , glon.encode(EditTbl))
end

local function LoadMapTable()
EditTbl = glon.decode(file.Read(“mapeditor.txt”)) or {}
for k , v in ipairs(ents.GetAll()) do
for a , b in pairs(EditTbl) do
if b.pos == v:GetPos() then
if b.lock then
v:Fire(“lock”)
elseif b.remove then
v:Remove()
end
end
end
end
PrintTable(EditTbl)
end
hook.Add(“InitPostEntity” , “EditEnts” , LoadMapTable)

local function AddEntityToTable(pl , cmd , args)
if pl:IsSuperAdmin() then
local tr = pl:GetEyeTrace()
if tr.Entity and ValidEntity(tr.Entity) and string.find(tr.Entity:GetClass() , “door”) then
if string.lower(args[1]) == “lock” then
table.insert(EditTbl , {pos = tr.Entity:GetPos() , lock = true})
tr.Entity:Fire(“lock”)
elseif string.lower(args[1]) == “remove” then
table.insert(EditTbl , {pos = tr.Entity:GetPos() , remove = true})
tr.Entity:Remove()
end

	end
end

end
concommand.Add(“edit_ents” , AddEntityToTable)
[/lua]

[editline]07:45PM[/editline]

Should fix it.

I tried it. It directly locks/removes the door but when I reload the map the door is back unlocked.

Edit: The text file isn’t created.

Copy and paste the console output from the table. Added PrintTable in the loading file bit.

Oh, accidentally removed a bit of code while re-working it, then realised re-working was un-neccessary.

Fixed.

[lua]local EditTbl = {}

local function SaveMapTable()
file.Write(“mapeditor.txt” , glon.encode(EditTbl))
end

local function LoadMapTable()
EditTbl = glon.decode(file.Read(“mapeditor.txt”)) or {}
for k , v in ipairs(ents.GetAll()) do
for a , b in pairs(EditTbl) do
if b.pos == v:GetPos() then
if b.lock then
v:Fire(“lock”)
elseif b.remove then
v:Remove()
end
end
end
end
PrintTable(EditTbl)
end
hook.Add(“InitPostEntity” , “EditEnts” , LoadMapTable)

local function AddEntityToTable(pl , cmd , args)
if pl:IsSuperAdmin() then
local tr = pl:GetEyeTrace()
if tr.Entity and ValidEntity(tr.Entity) and string.find(tr.Entity:GetClass() , “door”) then
if string.lower(args[1]) == “lock” then
table.insert(EditTbl , {pos = tr.Entity:GetPos() , lock = true})
tr.Entity:Fire(“lock”)
elseif string.lower(args[1]) == “remove” then
table.insert(EditTbl , {pos = tr.Entity:GetPos() , remove = true})
tr.Entity:Remove()
end
SaveMapTable()
end
end
end
concommand.Add(“edit_ents” , AddEntityToTable)
[/lua]

Sorry, I can only administrate the server using FTP and TCadmin

Try the code in the above post. Hopefully is fixed.

When using the command it locks the door and creates the mapeditor.txt with the content:


alockapos-1454139-142

But when reloading map the door is unlocked again.

I really need to be able to see the table output to know what’s wrong. I honestly can’t see anything wrong with it.

[editline]08:20PM[/editline]

Try testing it on a local server. I can’t test it right now.

I tried it on a local server…but it says unknown command.