Advertisement
k_goos

MobSpawnerServer

Feb 21st, 2013
52
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function clear()
  2. term.clear()
  3. term.setCursorPos(1,1)
  4. end
  5.  
  6. lock = false
  7.  
  8. local term = peripheral.wrap("right")
  9. tX, tY = term.getSize()
  10.  
  11. rednet.open("left")
  12. term.setTextScale(1.5)
  13. clear()
  14. local mob={}
  15. redout = {}
  16. sheep = false
  17.  
  18. function setTable(name, active, xmin, ymin, actiontype, action)
  19. --start, Weather it should be on or off when the program starts (true = on, false = off)
  20. --Modifyed by SuPeRMiNoR2
  21. mob[name] = {}
  22. mob[name]["action"] = action
  23. mob[name]["actiontype"] = actiontype
  24. mob[name]["active"] = active
  25. mob[name]["xmin"] = xmin
  26. mob[name]["ymin"] = ymin
  27. templen = xmin + #name - 1
  28. mob[name]["xmax"] = templen
  29. mob[name]["ymax"] = ymin
  30. end
  31.  
  32. function fillTable()
  33. setTable("Reboot", false, 35, 17, "other", "reboot")
  34. setTable("Steam Engines", true, 1, 3, "other", "steam")
  35. setTable("Lock", true, 1, 17, "other", "lock")
  36. setTable("Lights", true, 1, 1, "other", "lights")
  37. end
  38.  
  39. function fill(x,y,color,text)
  40. term.setBackgroundColor(color)
  41. term.setCursorPos(x,y)
  42. term.write(text)
  43. term.setBackgroundColor(colors.black)
  44. end
  45.  
  46. function screen()
  47. while true do
  48. term.clear()
  49. if lock == false then
  50. local y = 2
  51. local currColor
  52. for name,data in pairs(mob) do
  53. x = data["xmin"]
  54. y = data["ymin"]
  55. local on = data["active"]
  56. if on == true then currColor = colors.lime else currColor = colors.red end
  57. fill(x,y,currColor, name)
  58. end
  59. fill(36, 1, colors.lime, os.time())
  60. end
  61. if lock == true then
  62. fill(12, 9, colors.red, "Control Panel Locked")
  63. end
  64.  
  65. sleep(0.2)
  66. end
  67. end
  68.  
  69. function checkxy(x, y)
  70. for name, data in pairs(mob) do
  71. if y>=data["ymin"] and y <= data["ymax"] then
  72. if x>=data["xmin"] and x<= data["xmax"] then
  73. if lock == false then
  74. data["active"] = not data["active"]
  75. print(name..":"..tostring(x)..":"..tostring(y))
  76. end
  77. if lock == true then
  78. if name == "Lock" then
  79. data["active"] = not data["active"]
  80. end
  81. end
  82. end
  83. end
  84. end
  85. end
  86.  
  87. function doStuff()
  88. local wire = 0
  89. for name, data in pairs(mob) do
  90. if data["active"] == true then
  91. if data["actiontype"] == "other" then
  92. if data["action"] == "reboot" then
  93. os.reboot()
  94. end
  95. if data["action"] == "sheep" then
  96. sheep = true
  97. end
  98. if data["action"] == "steam" then
  99. rednet.broadcast("steam_on")
  100. end
  101. if data["action"] == "lock" then
  102. lock = true
  103. end
  104. if data["action"] == "lights" then
  105. rednet.broadcast("lights_on")
  106. end
  107. end
  108. end
  109. if data["active"] == false then
  110. if data["actiontype"] == "wire" then
  111. if data["inver"] == true then
  112. wire = colors.combine(wire, data["action"])
  113. end
  114. end
  115. if data["actiontype"] == "other" then
  116. if data["action"] == "sheep" then
  117. sheep = false
  118. end
  119. end
  120. if data["action"] == "steam" then
  121. rednet.broadcast("steam_off")
  122. end
  123. if data["action"] == "lock" then
  124. lock = false
  125. end
  126. if data["action"] == "lights" then
  127. rednet.broadcast("lights_off")
  128. end
  129. end
  130. end
  131. redstone.setBundledOutput("bottom", wire)
  132. end
  133.  
  134. function mainLoop()
  135. while true do
  136. local e,side,x,y = os.pullEvent("monitor_touch") --Get event
  137. print("Click: "..tostring(x)..":"..tostring(y))
  138. checkxy(x,y) --Check to see if click is on a button, and toggle state if it is
  139. doStuff() --Reads button state and does actions
  140. sleep(0.1)
  141. end
  142. end
  143.  
  144. function main()
  145. fillTable() --Populate data table
  146. sleep(2)
  147. doStuff() --Run once to start autostart things
  148. parallel.waitForAll(mainLoop, screen)
  149. end
  150.  
  151. main()
Advertisement
RAW Paste Data Copied
Advertisement