Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Look throughout the code for comments like this. They explain what to do to change things.
- --What side the monitor will be on (change this if needed)
- modem = peripheral.find("modem") or error("No modem attached", 0)
- m = peripheral.find("monitor") or error("No monitor attached", 0)
- --button on/off color
- bactive = colors.cyan
- binactive=colors.gray
- --text on/off color
- tactive=colors.white
- tinactive=colors.black
- --Background color
- bgcolor = colors.black
- buttons = {}
- function newButton(id,xmin,xmax,ymin,ymax,text,func)
- buttons[id] = {}
- buttons[id]["xmin"] = xmin
- buttons[id]["xmax"] = xmax
- buttons[id]["ymin"] = ymin
- buttons[id]["ymax"] = ymax
- buttons[id]["active"] = false
- buttons[id]["text"] = text
- buttons[id]["func"] = func
- end
- ---------------------------------------------------------------------------------
- function printButton(id)
- ymin = buttons[id]["ymin"]
- ymax = buttons[id]["ymax"]
- xmin = buttons[id]["xmin"]
- xmax = buttons[id]["xmax"]
- text = buttons[id]["text"]
- ia = buttons[id]["active"]
- width = xmax - xmin
- height = ymax - ymin
- if ia then m.setBackgroundColor(bactive) m.setTextColor(tactive)
- else m.setBackgroundColor(binactive) m.setTextColor(tinactive)
- end
- for j = ymin,ymax do
- m.setCursorPos(xmin,j)
- for i = xmin,xmax do
- m.write(" ")
- end
- end
- m.setCursorPos(xmin + width / 2 - #text / 2 + 1,ymin + height / 2)
- m.write(text)
- m.setBackgroundColor(bgcolor)
- end
- ----------------------------------------------------------------------------------
- function refreshButtons()
- for i = 1,#buttons do
- printButton(i)
- end
- end
- function checkxy( x,y )
- for i = 1, #buttons do
- if y >= buttons[i]["ymin"] and y <= buttons[i]["ymax"] then
- if x >= buttons[i]["xmin"] and x <= buttons[i]["xmax"] then
- buttons[i]["active"] = not buttons[i]["active"]
- clicked = i
- if buttons[i]["func"] ~= nil then
- buttons[i]["func"]()
- end
- end
- end
- end
- end
- bool1 = false
- bool2 = false
- bool3 = false
- rs.setBundledOutput("back",0)
- --White is pigman, Orange is witch, purple is wither skele (Bundled cable)
- function villager()
- if bool1 then
- bool1 = not bool1
- modem.transmit(7, 7, "RDC")
- end
- end
- function znkkiller()
- current = rs.getBundledOutput("back")
- bool2 = not bool2
- if bool2 then
- rednet.broadcast("znkkilleron")
- else
- rednet.broadcast("znkkilleroff")
- end
- end
- function microsoftkiller()
- current = rs.getBundledOutput("back")
- bool3 = not bool3
- if bool3 then
- rednet.broadcast("microsoftkilleron")
- else
- rednet.broadcast("microsoftkilleroff")
- end
- end
- function ancientknight()
- current = rs.getBundledOutput("back")
- bool3 = not bool3
- if bool3 then
- rednet.broadcast("ancienton")
- else
- rednet.broadcast("ancientoff")
- end
- end
- --You can add more buttons and also change the size of them. The format is startingx,startingy,endingx,endingy,text,function
- --The buttons
- newButton(1, 2,24,2,6,"Villager",villager)
- newButton(2, 26,48,2,6,"ZNK Killer",znkkiller)
- newButton(3, 26,48,7,11,"Microsoft Killer",microsoftkiller)
- newButton(4, 2,24,7,11,"Ancient Knight",ancientknight)
- ------------------------------------------------
- m.clear()
- refreshButtons()
- --main loop
- while true do
- e,side,x,y = os.pullEvent("monitor_touch")
- checkxy(x,y)
- refreshButtons()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement