Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. local function SaveMapTable()
  2. file.Write("mapeditor.txt" , util.TableToJSON(EditTbl))
  3. end
  4. local function LoadMapTable()
  5. if not file.Exists("mapeditor.txt", "DATA") then return end
  6.  
  7. EditTbl = util.JSONToTable(file.Read("mapeditor.txt", "DATA")) or {}
  8. for k, v in ipairs(ents.GetAll()) do
  9. for a, b in pairs(EditTbl) do
  10. if b.pos == v:GetPos() then
  11. if b.lock then
  12. v:Fire("lock")
  13. v.Dontunlock = true
  14. elseif b.remove then
  15. v:Remove()
  16. end
  17. end
  18. end
  19.  
  20. if not v.Dontunlock then
  21. v:Fire("unlock")
  22. end
  23. end
  24. PrintTable(EditTbl)
  25. end
  26. hook.Add("InitPostEntity", "EditEnts", LoadMapTable)
  27.  
  28. local function AddEntityToTable(pl, cmd, args)
  29. if pl:IsSuperAdmin() and args[1] then
  30. local tr = pl:GetEyeTrace()
  31. if tr.Entity and IsValid(tr.Entity) and string.find(tr.Entity:GetClass() , "door") then
  32. if string.lower(args[1]) == "lock" then
  33. table.insert(EditTbl , {pos = tr.Entity:GetPos() , lock = true})
  34. tr.Entity:Fire("lock")
  35. elseif string.lower(args[1]) == "remove"then
  36. table.insert(EditTbl , {pos = tr.Entity:GetPos() , remove = true})
  37. tr.Entity:Remove()
  38. elseif string.lower(args[1]) == "unlock" then
  39. table.remove(EditTbl, tr.Entity.GetPos())
  40. end
  41. SaveMapTable()
  42. end
  43. end
  44. end
  45. concommand.Add("edit_ents" , AddEntityToTable)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement