Advertisement
neonerz

monitor

Mar 25th, 2013
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.09 KB | None | 0 0
  1. --
  2. --Killing Floor Monitor by neonerZ v1.0
  3. --http://youtube.com/neonerz
  4. --
  5.  
  6. --Variables
  7. rednet.open("back")
  8. defaultMonColor=colors.black
  9. m = peripheral.wrap("front")
  10. m.clear()
  11. m.setBackgroundColor(defaultMonColor)
  12.  
  13.  --Draw a box on the monitor
  14.  function drawBox(xpos, ypos, height, width, title, bcolor, tcolor, tbcolor)
  15. --  if xpos == 1 then xpos=2 end
  16. --  if ypos == 1 then ypos=2 end
  17.     if ypos > height then height = height+ypos end
  18.     if xpos > width then rwidth = xpos+width -2 else rwidth = width end
  19.     for h = ypos,height+1 do
  20.         for i = xpos,rwidth+1 do
  21.             m.setCursorPos(i,h)
  22.             m.setBackgroundColor(bcolor)
  23.             m.write(" ")
  24.         end
  25.     end
  26.     titleCount = #title
  27.     titlePos = math.floor((width-titleCount)/2)+xpos
  28.     m.setBackgroundColor(tbcolor)
  29.     m.setTextColor(tcolor)
  30.     m.setCursorPos(titlePos,ypos)
  31.     m.write(title)
  32.     m.setBackgroundColor(defaultMonColor)
  33.     h=nil
  34.     i=nil
  35. end
  36.  
  37. --Draw text on the monitor
  38. function drawText(xpos,ypos,tcolor,bcolor,text)
  39.     m.setCursorPos(xpos,ypos)
  40.     m.setTextColor(tcolor)
  41.     m.setBackgroundColor(bcolor)
  42.     m.write(text)  
  43.     m.setBackgroundColor(defaultMonColor)
  44. end
  45.  
  46. --Save total amount of enchants
  47. function saveEnchantNum()
  48.     local num
  49.     local h
  50.     if fs.exists("enchantAmount") then
  51.         h = fs.open("enchantAmount","r")
  52.         num = h.readLine()
  53.         num = num+1
  54.         h.close()
  55.         h = fs.open("enchantAmount", "w")
  56.         h.write(tostring(num))
  57.         h.close()
  58.     else
  59.         h = fs.open("enchantAmount", "w")
  60.         h.write(1)
  61.         h.close()      
  62.     end
  63. end
  64.  
  65. --Read total amount of enchants
  66. function readEnchantNum()
  67.     if fs.exists("enchantAmount") then
  68.         local num
  69.         local h
  70.         h = fs.open("enchantAmount","r")
  71.         return h.readLine()
  72.     else
  73.         return 0
  74.     end
  75. end
  76.        
  77. --Build GUI
  78. drawBox(3,2,10,21,"Enchanting",colors.blue,colors.white,colors.black)
  79. drawBox(28,2,10,21,"Spawner  Info",colors.blue,colors.white,colors.black)
  80. drawBox(25,1,12,1,"",colors.lightGray,colors.white,colors.black)
  81. drawText(4,4,colors.white,colors.blue,"Level: 0")
  82. drawText(4,6,colors.white,colors.blue,"Total Enchants: "..readEnchantNum())
  83. drawText(4,10,colors.white,colors.blue,"waiting...")
  84.  
  85.  
  86. while true do
  87.     --Start waiting for rednet message
  88.     local event, senderID, message, distance = os.pullEvent("rednet_message")
  89.     message = textutils.unserialize(message)
  90.     --Display Level messages
  91.     if message.mode =="level" and message.name=="enchanter01" then
  92.         drawText(4,4,colors.white,colors.blue,"Level: "..message.message)
  93.         drawText(4,8,colors.red,colors.blue,"         ")
  94.     end
  95.      --Info messages
  96.     if message.mode =="info" and message.name=="enchanter01" then
  97.         drawBox(3,2,10,21,"Enchanting",colors.blue,colors.white,colors.black)
  98.         drawText(4,10,colors.white,colors.blue,message.message)
  99.         if message.message == "Book en route" then
  100.             saveEnchantNum()
  101.         end
  102.         drawText(4,6,colors.white,colors.blue,"Total Enchants: "..readEnchantNum())
  103.     end
  104.     --Error messages
  105.     if message.mode =="error" and message.name=="enchanter01" then
  106.         drawText(4,8,colors.red,colors.blue,message.message)
  107.     end
  108.        
  109.    
  110. --  print("Name: "..message.name)
  111. --  print("Mode: "..message.mode)
  112. --  print("Message: "..message.message)
  113. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement