Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- monitorSide = "top"
- modemSide = "right"
- slaveID = 111
- m = peripheral.wrap(monitorSide)
- rednet.open(modemSide)
- m.setBackgroundColor(colors.black)
- m.clear()
- tArgs = { ... }
- if #tArgs == 2 then
- redstone = tArgs[1]
- spawner = tArgs[2]
- else
- redstone = "Off"
- spawner = "Empty"
- end
- function screen(pos_x, pos_y, color, msg)
- m.setCursorPos(pos_x, pos_y)
- m.setBackgroundColor(color)
- m.write(msg)
- end
- function save() --saving position
- file = fs.open("startup", "w") --open startup in writemode
- file.write('shell.run("monitor", \''..redstone..'\', \''..spawner..'\')')
- file.close()
- end
- screen(2,2,colors.black,"Spawner Control")
- function full()
- spawner = "Full"
- save()
- screen(2,6,colors.green,"Full")
- screen(13,6,colors.black,"Empty")
- end
- function empty()
- spawner = "Empty"
- save()
- screen(2,6,colors.black,"Full")
- screen(13,6,colors.red,"Empty")
- end
- function on()
- redstone = "On"
- save()
- screen(2,4,colors.green,"On")
- screen(13,4,colors.black,"Off")
- end
- function off()
- redstone = "Off"
- save()
- screen(2,4,colors.black,"On")
- screen(13,4,colors.red,"Off")
- end
- function noResponse()
- screen(2,2,colors.red,"spawner is not responding")
- error()
- end
- function wrong()
- screen(2,2,colors.red,"error, manual intervention required")
- end
- if #tArgs == 2 then
- if redstone == "On" then
- on()
- else
- off()
- end
- if spawner == "Full" then
- full()
- else
- empty()
- end
- else
- off()
- empty()
- end
- function main()
- xPos, yPos = 0, 0
- _, side, xPos, yPos = os.pullEvent("monitor_touch")
- print("x= "..xPos.."y= "..yPos)
- if 2 <= xPos and xPos <= 3 and yPos == 4 then --on = 2,4
- rednet.send(slaveID, "On")
- print("sending on")
- id, msg, distance = rednet.receive(5)
- if id == nil then
- noResponse()
- elseif id == slaveID and msg == "On done" then
- on()
- end
- elseif 13 <= xPos and xPos <= 15 and yPos == 4 then --off = 13,4
- rednet.send(slaveID, "Off")
- print("sending off")
- id, msg, distance = rednet.receive(5)
- if id == nil then
- noResponse()
- elseif id == slaveID and msg == "Off done" then
- off()
- end
- elseif 2 <= xPos and xPos <= 5 and yPos == 6 then --full = 2,6
- rednet.send(slaveID, "Full")
- print("sending full")
- id, msg, distance = rednet.receive(5)
- if id == nil then
- noResponse()
- elseif id == slaveID and msg == "Full done" then
- full()
- end
- elseif 13 <= xPos and xPos <= 17 and yPos == 6 then --empty = 13,6
- rednet.send(slaveID, "Empty")
- print("sending empty")
- id, msg, distance = rednet.receive(5)
- if id == nil then
- noResponse()
- elseif id == slaveID and msg == "Empty done" then
- empty()
- end
- end
- end
- while true do
- main()
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment