Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function SaveMapTable()
- file.Write("mapeditor.txt" , util.TableToJSON(EditTbl))
- end
- local function LoadMapTable()
- if not file.Exists("mapeditor.txt", "DATA") then return end
- EditTbl = util.JSONToTable(file.Read("mapeditor.txt", "DATA")) 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")
- v.Dontunlock = true
- elseif b.remove then
- v:Remove()
- end
- end
- end
- if not v.Dontunlock then
- v:Fire("unlock")
- end
- end
- PrintTable(EditTbl)
- end
- hook.Add("InitPostEntity", "EditEnts", LoadMapTable)
- local function AddEntityToTable(pl, cmd, args)
- if pl:IsSuperAdmin() and args[1] then
- local tr = pl:GetEyeTrace()
- if tr.Entity and IsValid(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()
- elseif string.lower(args[1]) == "unlock" then
- table.remove(EditTbl, tr.Entity.GetPos())
- end
- SaveMapTable()
- end
- end
- end
- concommand.Add("edit_ents" , AddEntityToTable)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement