Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local state
- local mon = peripheral.wrap("top")
- mon.setTextScale(1)
- mon.setTextColor(colors.white)
- local button={}
- mon.setBackgroundColor(colors.black)
- function setTable(name, func, xmin, xmax, ymin, ymax)
- button[name] = {}
- button[name]["func"] = func
- button[name]["active"] = false
- button[name]["xmin"] = xmin
- button[name]["ymin"] = ymin
- button[name]["xmax"] = xmax
- button[name]["ymax"] = ymax
- end
- function caveSpider()
- for name, data in pairs(button) do
- if data["active"] == true then
- rednet.open("left")
- rednet.send(31,"spawner")
- rednet.close("left")
- --sleep(1)
- end
- if data["active"] == false then
- rednet.open("left")
- rednet.send(31,"spawner")
- rednet.close("left")
- end
- end
- end
- function skeleton()
- --print("Doing Function")
- for name, data in pairs(button) do
- if data["active"] == true then
- rednet.open("bottom")
- rednet.send(33, "spawner")
- rednet.close("bottom")
- end
- if data["active"] == false then
- rednet.open("bottom")
- rednet.send(33,"spawner")
- rednet.close("bottom")
- end
- end
- end
- function blaze()
- for name, data in pairs(button) do
- if data["active"] == true then
- rednet.open("bottom")
- rednet.send(34, "spawner")
- rednet.close("bottom")
- --sleep(1)
- end
- if data["active"] == false then
- rednet.open("bottom")
- rednet.send(34,"spawner")
- rednet.close("bottom")
- --sleep(1)
- end
- end
- end
- function zombie()
- for name, data in pairs(button) do
- if data["active"] == true then
- rednet.open("bottom")
- rednet.send(35, "spawner")
- rednet.close("bottom")
- --sleep(1)
- end
- if data["active"] == false then
- rednet.open("bottom")
- rednet.send(35,"spawner")
- rednet.close("bottom")
- --sleep(1)
- end
- end
- end
- function witch()
- for name, data in pairs(button) do
- if data["active"] == true then
- rednet.open("bottom")
- rednet.send(36, "spawner")
- rednet.close("bottom")
- --sleep(1)
- end
- if data["active"] == false then
- rednet.open("bottom")
- rednet.send(36,"spawner")
- rednet.close("bottom")
- --sleep(1)
- end
- end
- end
- function miner()
- for name, data in pairs(button) do
- if data["active"] == true then
- rednet.open("bottom")
- rednet.send(50, "spawner")
- rednet.close("bottom")
- --sleep(1)
- end
- if data["active"] == false then
- rednet.open("bottom")
- rednet.send(50,"spawner")
- rednet.close("bottom")
- --sleep(1)
- end
- end
- end
- function funcName()
- print("You clicked buttonText")
- end
- function fillTable()
- setTable("Cave Spider", caveSpider, 5, 20, 4, 8)
- setTable("Skeleton-Disabled", skeleton, 23, 38, 4, 8)
- setTable("Blaze", blaze, 41 ,56, 4,8)
- setTable("Zombie", zombie, 5 ,20 , 11, 15)
- setTable("Witch", witch, 23, 38, 11, 15)
- -- setTable("Miner", miner, 41, 56, 11, 15)
- -- setTable("TEST2", test2, 5, 20, 18, 22)
- -- setTable("TEST3", test3, 23, 38, 18, 22)
- -- setTable("TEST4", test4, 41, 56, 18, 22)
- -- setTable("TEST5", test5, 5, 20, 25, 29)
- -- setTable("TEsT6", test6, 23, 38, 25, 29)
- -- setTable("VEXMATE", VEX, 41, 56, 25, 29)
- end
- function fill(text, color, bData)
- mon.setBackgroundColor(color)
- local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
- local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
- for j = bData["ymin"], bData["ymax"] do
- mon.setCursorPos(bData["xmin"], j)
- if j == yspot then
- for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
- if k == xspot then
- mon.write(text)
- else
- mon.write(" ")
- end
- end
- else
- for i = bData["xmin"], bData["xmax"] do
- mon.write(" ")
- end
- end
- end
- mon.setBackgroundColor(colors.black)
- end
- function screen()
- local currColor
- for name,data in pairs(button) do
- local on = data["active"]
- if on == true then currColor = colors.lime else currColor = colors.red end
- fill(name, currColor, data)
- end
- end
- function checkxy(x, y)
- for name, data in pairs(button) do
- if y>=data["ymin"] and y <= data["ymax"] then
- if x>=data["xmin"] and x<= data["xmax"] then
- data["func"]()
- data["active"] = not data["active"]
- --print(name)
- end
- end
- end
- end
- function heading(text)
- w, h = mon.getSize()
- mon.setCursorPos((w-string.len(text))/2+1, 1)
- mon.write(text)
- end
- fillTable()
- while true do
- mon.clear()
- heading("Spawn Station Control")
- screen()
- local e,side,x,y = os.pullEvent("monitor_touch")
- --print(x..":"..y)
- checkxy(x,y)
- sleep(.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement