Advertisement
Guest User

startup.lua

a guest
Feb 21st, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.28 KB | None | 0 0
  1. os.loadAPI("bigfont.lua")
  2.  
  3. local text = nil
  4.  
  5. if not fs.exists("text.txt") then
  6.     printError("Must create text.txt")
  7. else
  8.     local textFile = fs.open("text.txt", "r")
  9.     text = {}
  10.     for line in textFile.readLine do
  11.         table.insert(text, line)
  12.     end
  13.     textFile.close()
  14. end
  15.  
  16. local function draw(name)
  17.     local mon = peripheral.wrap(name)
  18.  
  19.     mon.setTextScale(1)
  20.     local w, h = mon.getSize()
  21.  
  22.     mon.setBackgroundColour(colours.green)
  23.     mon.setTextColour(colours.white)
  24.     mon.clear()
  25.  
  26.     if text then
  27.         bigfont.writeOn(mon, 1, text[2])
  28.  
  29.         mon.setCursorPos(math.floor((w - (#text[2] * 3)) / 2) - #(text[1]), math.floor(h / 2) + 1)
  30.         mon.write(text[1])
  31.  
  32.         mon.setCursorPos(math.floor((w - (#text[2] * 3)) / 2) + (#text[2] * 3) + 2, math.floor(h / 2) + 1)
  33.         mon.write(text[3])
  34.     else
  35.         bigfont.writeOn(mon, 1, "New Street", nil, 1)
  36.  
  37.         local hint1 = "Help name this street!"
  38.         local hint2 = "Send name + coordinates to Yemmel#2747!"
  39.  
  40.         mon.setCursorPos(math.floor((w - #hint1) / 2) + 1, math.floor(h / 2) + 2)
  41.         mon.write(hint1)
  42.  
  43.         mon.setCursorPos(math.floor((w - #hint2) / 2) + 1, math.floor(h / 2) + 3)
  44.         mon.write(hint2)
  45.     end
  46. end
  47.  
  48. peripheral.find("monitor", draw)
  49. while true do
  50.     local _, name = os.pullEvent("peripheral")
  51.     if peripheral.getType(name) == "monitor" then draw(name) end
  52. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement