Guest User

startup.lua

a guest
Aug 22nd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.58 KB | None | 0 0
  1. print("init")
  2. sleep(os.clock()<2 and 2 or 0)
  3. print("run")
  4.  
  5. local mobType = "Zombie"
  6.  
  7. settings.load("guestbook")
  8. local guestbook = settings.get("guestbook",{})
  9.  
  10. local p = peripheral.wrap("right")
  11.  
  12. local w,h = term.getSize()
  13.  
  14. local book = window.create(
  15.     term.current(),
  16.     1, 1,
  17.     w, h-4,
  18.     true
  19. )
  20.  
  21. local output = window.create(
  22.     term.current(),
  23.     1,h-4,
  24.     w,4,
  25.     true
  26. )
  27.  
  28. local function scan()
  29.     for i,mob in ipairs(p.sense()) do
  30.         if mob.name == mobType
  31.         and not guestbook[mob.id]
  32.         and mob.y == 0
  33.         and mob.x >= 1 and mob.x <= 2
  34.         and mob.z >= 1 and mob.z <= 2
  35.         then
  36.             local old = term.redirect(output)
  37.             term.setTextColor(colors.lightGray)
  38.             print("New mob", mob.name, mob.displayName)
  39.             print(mob.id)
  40.             term.redirect(old)
  41.             guestbook[mob.id] = string.format("day %s, at %s", os.day(), os.time())
  42.             settings.set("guestbook", guestbook)
  43.             settings.save("guestbook")
  44.         end
  45.     end
  46. end
  47.  
  48. local function display()
  49.     local old = term.redirect(book)
  50.     term.setBackgroundColor(colors.white)
  51.     term.setCursorPos(1,1)
  52.     term.clear()
  53.     for id,date in pairs(guestbook) do
  54.         term.setTextColor(colors.gray)
  55.         print(id)
  56.         term.setTextColor(colors.black)
  57.         print(date)
  58.         term.setTextColour(colors.lightGray)
  59.         print(" "..string.rep("-",w-2))
  60.     end
  61.     term.redirect(old)
  62. end
  63. repeat
  64.     scan()
  65.     display()
  66.     book.redraw()
  67.     output.redraw()
  68.     sleep(20)
  69. until false
Advertisement
Add Comment
Please, Sign In to add comment