Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local monitor = peripheral.find("monitor")
- local rside = "back"
- local w, h
- if monitor then
- monitor.setTextScale(0.5)
- w, h = monitor.getSize()
- end
- local function CenterPrint(text, y)
- monitor.setCursorPos((w - #text) / 2 + 1, y)
- monitor.write(text)
- end
- local atPos = math.floor(h / 2)
- local itPos = math.floor(h / 2) + 1
- function SetActive(active)
- local file = fs.open("altproto-spawnerstate", "w")
- file.write(tostring(not not active))
- file.close()
- redstone.setOutput(rside, not active)
- if monitor then
- monitor.setTextColor(colors.white)
- if active then
- monitor.setBackgroundColor(colors.green)
- monitor.clear()
- CenterPrint("Active", atPos)
- else
- monitor.setBackgroundColor(colors.red)
- monitor.clear()
- CenterPrint("Inactive", atPos)
- end
- monitor.setTextColor(colors.lightGray)
- CenterPrint("Right click", itPos)
- CenterPrint("to toggle", itPos + 1)
- end
- end
- local active = false
- local file = fs.open("altproto-spawnerstate", "r")
- if file then
- active = file.readAll() == "true"
- file.close()
- end
- OnMessage(function(id, recipient, sender, data)
- SetActive(data)
- end, "SETSPAWNER")
- OnEvent(function(event, side)
- if not monitor and peripheral.getType(side) == "monitor" then
- monitor = peripheral.wrap(side)
- monitor.setTextScale(0.5)
- w, h = monitor.getSize()
- Log("Monitor attached")
- end
- end, "peripheral")
- OnEvent(function(event, side)
- if monitor and peripheral.getType(side) == "monitor" then
- monitor = nil
- Log("Monitor detached")
- end
- end, "peripheral_detach")
- SetActive(active)
- OnEvent(function(event, side, x, y)
- active = not active
- SetActive(active)
- end, "monitor_touch")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement