DrFair

SpawnerMonitor

May 12th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. monitorSide = "top"
  2. rednet.open("right")
  3. spawnerName = "ThaumcraftSpawner"
  4. spawnerData = {}
  5.  
  6. local Args = {...}
  7. if Args[1] == "update" then
  8. programName = shell.getRunningProgram()
  9. print("Updating.")
  10. fs.delete( programName )
  11. shell.run( "pastebin","get", "qkYQNK9V", programName )
  12. print("Finished updating.")
  13. error()
  14. end
  15.  
  16. if not fs.exists( "fui" ) then
  17. print( "Performing first time setup." )
  18. shell.run( "pastebin","get", "306Ns1qg", "fui" )
  19. print("Finished. Please run program again.")
  20. error()
  21. end
  22.  
  23. os.loadAPI("fui")
  24. fui.setMonitorSide( monitorSide )
  25. os.sleep(1)
  26. w,h = fui.getSize()
  27. w = w + 1
  28. h = h + 1
  29.  
  30. function drawScreen()
  31. fui.clear()
  32. fui.resetButtons()
  33. fui.drawOutline( "Thaumcraft trading", "By Fair", "white", "gray" )
  34. if active == true then
  35. fui.drawAlignButton( " ", "mid", "toggle", w - 6, 10, 2, h-3, "white", "red" )
  36. rs.setOutput( "bottom", false )
  37. else
  38. fui.drawAlignButton( " ", "mid", "toggle", w - 6, 10, 2, h-3, "white", "lime" )
  39. rs.setOutput( "bottom", true )
  40. end
  41. fui.drawAlignButton( " ", "mid", " ", w - 11, 1, 2, h-3, "white", "gray" )
  42. if pick == 1 then tColor = "lime" else tColor = "red" end
  43. fui.drawAlignButton( "K. Fragment", "mid", "1", 12, 15, 3, 3, "white", tColor )
  44. if pick == 2 then tColor = "lime" else tColor = "red" end
  45. fui.drawAlignButton( "Mana Beans", "mid", "2", 12, 15, 7, 3, "white", tColor )
  46. if pick == 3 then tColor = "lime" else tColor = "red" end
  47. fui.drawAlignButton( "Nitor", "mid", "3", 30, 15, 3, 3, "white", tColor )
  48. if pick == 4 then tColor = "lime" else tColor = "red" end
  49. fui.drawAlignButton( "Alumentum", "mid", "4", 30, 15, 7, 3, "white", tColor )
  50. end
  51.  
  52. drawScreen()
  53.  
  54. while true do
  55. fui.submitEvents()
  56. lastEvent = fui.getEvents()
  57. if lastEvent[1] == "rednet_message" then
  58. if textutils.unserialize(lastEvent[3])[1] == "spawner" then
  59. data = textutils.unserialize(lastEvent[3])
  60. if data[2] == spawnerName then
  61. spawnerData = textutils.unserialize( data[3] )
  62. active = spawnerData["getActive"]
  63. pick = spawnerData["getPick"]
  64. drawScreen()
  65. end
  66. end
  67. end
  68. if fui.buttonPressed("toggle") then
  69. msg = { [1]=spawnerName, [2]="setActive", [3]=not active }
  70. rednet.broadcast( textutils.serialize(msg) )
  71. active = not active
  72. drawScreen()
  73. end
  74. for i=1,4 do
  75. if fui.buttonPressed( ""..i ) then
  76. msg = { [1]=spawnerName, [2]="setPick", [3]=i }
  77. rednet.broadcast( textutils.serialize(msg) )
  78. pick = i
  79. drawScreen()
  80. end
  81. end
  82. end
Advertisement
Add Comment
Please, Sign In to add comment