Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- shell.run("clear")
- w, h = term.getSize()
- spawner_count = 6
- cables = {colors.white, colors.orange, colors.magenta, colors.yellow, colors.lime, colors.pink}
- sps = {}
- corx = {}
- cory = {}
- lents = {}
- function loadSpawners()
- if fs.exists("spawners") then
- file = fs.open("spawners", "r")
- for spr = 1, spawner_count do
- line = file.readLine()
- sps[spr] = tonumber(line)
- end
- file.close()
- else
- file = fs.open("spawners", "w")
- for spr = 1, spawner_count do
- file.writeLine("0")
- sps[spr] = 0
- end
- file.close()
- end
- end
- function pC(text, y, tc, bc, indb)
- if tc == "" then tc = colors.black end
- if bc == "" then bc = colors.black end
- term.setTextColor(tc)
- term.setBackgroundColor(bc)
- strl = math.floor(#text/2)
- pos = w/2-strl
- term.setCursorPos(pos, y)
- term.write(text)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- if indb == 1 then
- corx[#corx + 1] = pos
- cory[#cory + 1] = y
- lents[#lents + 1] = #text
- end
- end
- function iB(sx, sy, px, py, x, y)
- if x >= sx and x <= sx + px then
- if y >= sy and y <= sy + py then
- return true;
- else
- return false;
- end
- else
- return false;
- end
- end
- function draw()
- corx = {}
- cory = {}
- lents = {}
- shell.run("clear")
- pC("Spawner control panel", 1, colors.cyan, colors.black, 0)
- if(sps[1] == 1)then pC("Switch Enderman", 3, colors.white, colors.lime, 1) else pC("Switch Enderman", 3, colors.white, colors.red, 1) end
- if(sps[2] == 1)then pC("Switch Zombie", 5, colors.white, colors.lime, 1) else pC("Switch Zombie", 5, colors.white, colors.red, 1) end
- if(sps[3] == 1)then pC("Switch Skeleton", 7, colors.white, colors.lime, 1) else pC("Switch Skeleton", 7, colors.white, colors.red, 1) end
- if(sps[4] == 1)then pC("Switch Cows", 9, colors.white, colors.lime, 1) else pC("Switch Cows", 9, colors.white, colors.red, 1) end
- if(sps[5] == 1)then pC("Switch Pigs", 11, colors.white, colors.lime, 1) else pC("Switch Pigs", 11, colors.white, colors.red, 1) end
- if(sps[6] == 1)then pC("Switch Sheeps", 13, colors.white, colors.lime, 1) else pC("Switch Sheeps", 13, colors.white, colors.red, 1) end
- end
- function pulse(color, side)
- if side == 0 then side = "bottom" end
- redstone.setBundledOutput(side, color)
- sleep(0.3)
- redstone.setBundledOutput(side, 0)
- end
- function rewritefile()
- file = fs.open("spawners", "w")
- for spr = 1, spawner_count do
- file.writeLine(sps[spr])
- end
- file.close()
- end
- function switchy(ideys)
- pulse(cables[ideys], "bottom")
- if(sps[ideys] == 1)then sps[ideys] = 0 else sps[ideys] = 1 end
- rewritefile()
- end
- function checker(clickx, clicky)
- for checks = 1, #lents do
- if iB(corx[checks], cory[checks], lents[checks], 0, clickx, clicky) then switchy(checks) end
- end
- end
- loadSpawners()
- draw()
- while true do
- event, button, xPos, yPos = os.pullEvent()
- if event == "mouse_click" or event == "monitor_touch" then
- draw()
- checker(xPos, yPos)
- draw()
- end
- sleep(0.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement