SHOW:
|
|
- or go back to the newest paste.
| 1 | --Look throughout the code for comments like this. They explain what to do to change things. | |
| 2 | ||
| 3 | --What side the monitor will be on (change this if needed) | |
| 4 | - | side = "right" |
| 4 | + | modem = peripheral.find("modem") or error("No modem attached", 0)
|
| 5 | - | args = {...}
|
| 5 | + | m = peripheral.find("monitor") or error("No monitor attached", 0)
|
| 6 | - | rednet.open("top")
|
| 6 | + | |
| 7 | - | message = args[1] |
| 7 | + | |
| 8 | --button on/off color | |
| 9 | bactive = colors.cyan | |
| 10 | - | m = peripheral.wrap(side) |
| 10 | + | |
| 11 | --text on/off color | |
| 12 | tactive=colors.white | |
| 13 | tinactive=colors.black | |
| 14 | --Background color | |
| 15 | bgcolor = colors.black | |
| 16 | ||
| 17 | ||
| 18 | buttons = {}
| |
| 19 | ||
| 20 | ||
| 21 | ||
| 22 | function newButton(id,xmin,xmax,ymin,ymax,text,func) | |
| 23 | buttons[id] = {}
| |
| 24 | buttons[id]["xmin"] = xmin | |
| 25 | buttons[id]["xmax"] = xmax | |
| 26 | buttons[id]["ymin"] = ymin | |
| 27 | buttons[id]["ymax"] = ymax | |
| 28 | buttons[id]["active"] = false | |
| 29 | buttons[id]["text"] = text | |
| 30 | buttons[id]["func"] = func | |
| 31 | ||
| 32 | end | |
| 33 | --------------------------------------------------------------------------------- | |
| 34 | function printButton(id) | |
| 35 | ymin = buttons[id]["ymin"] | |
| 36 | ymax = buttons[id]["ymax"] | |
| 37 | xmin = buttons[id]["xmin"] | |
| 38 | xmax = buttons[id]["xmax"] | |
| 39 | text = buttons[id]["text"] | |
| 40 | ia = buttons[id]["active"] | |
| 41 | ||
| 42 | ||
| 43 | ||
| 44 | width = xmax - xmin | |
| 45 | height = ymax - ymin | |
| 46 | ||
| 47 | if ia then m.setBackgroundColor(bactive) m.setTextColor(tactive) | |
| 48 | else m.setBackgroundColor(binactive) m.setTextColor(tinactive) | |
| 49 | ||
| 50 | end | |
| 51 | ||
| 52 | for j = ymin,ymax do | |
| 53 | - | else m.setBackgroundColor(binactive) m.setTextColor(tinactive) end |
| 53 | + | |
| 54 | for i = xmin,xmax do | |
| 55 | ||
| 56 | m.write(" ")
| |
| 57 | ||
| 58 | end | |
| 59 | ||
| 60 | end | |
| 61 | ||
| 62 | ||
| 63 | m.setCursorPos(xmin + width / 2 - #text / 2 + 1,ymin + height / 2) | |
| 64 | ||
| 65 | m.write(text) | |
| 66 | m.setBackgroundColor(bgcolor) | |
| 67 | ||
| 68 | end | |
| 69 | ---------------------------------------------------------------------------------- | |
| 70 | function refreshButtons() | |
| 71 | for i = 1,#buttons do | |
| 72 | printButton(i) | |
| 73 | end | |
| 74 | end | |
| 75 | function checkxy( x,y ) | |
| 76 | for i = 1, #buttons do | |
| 77 | if y >= buttons[i]["ymin"] and y <= buttons[i]["ymax"] then | |
| 78 | if x >= buttons[i]["xmin"] and x <= buttons[i]["xmax"] then | |
| 79 | ||
| 80 | ||
| 81 | buttons[i]["active"] = not buttons[i]["active"] | |
| 82 | clicked = i | |
| 83 | if buttons[i]["func"] ~= nil then | |
| 84 | ||
| 85 | buttons[i]["func"]() | |
| 86 | ||
| 87 | ||
| 88 | end | |
| 89 | end | |
| 90 | end | |
| 91 | end | |
| 92 | end | |
| 93 | ||
| 94 | ||
| 95 | bool1 = false | |
| 96 | bool2 = false | |
| 97 | bool3 = false | |
| 98 | rs.setBundledOutput("back",0)
| |
| 99 | ||
| 100 | ||
| 101 | ||
| 102 | ||
| 103 | --White is pigman, Orange is witch, purple is wither skele (Bundled cable) | |
| 104 | ||
| 105 | ||
| 106 | function villager() | |
| 107 | ||
| 108 | if bool1 then | |
| 109 | bool1 = not bool1 | |
| 110 | modem.transmit(7, 7, "RDC") | |
| 111 | end | |
| 112 | end | |
| 113 | ||
| 114 | function znkkiller() | |
| 115 | current = rs.getBundledOutput("back")
| |
| 116 | bool2 = not bool2 | |
| 117 | - | rednet.broadcast("lon")
|
| 117 | + | |
| 118 | rednet.broadcast("znkkilleron")
| |
| 119 | - | rednet.broadcast("loff")
|
| 119 | + | |
| 120 | rednet.broadcast("znkkilleroff")
| |
| 121 | end | |
| 122 | end | |
| 123 | ||
| 124 | function microsoftkiller() | |
| 125 | current = rs.getBundledOutput("back")
| |
| 126 | bool3 = not bool3 | |
| 127 | if bool3 then | |
| 128 | rednet.broadcast("microsoftkilleron")
| |
| 129 | else | |
| 130 | rednet.broadcast("microsoftkilleroff")
| |
| 131 | end | |
| 132 | end | |
| 133 | ||
| 134 | function ancientknight() | |
| 135 | current = rs.getBundledOutput("back")
| |
| 136 | bool3 = not bool3 | |
| 137 | if bool3 then | |
| 138 | rednet.broadcast("ancienton")
| |
| 139 | else | |
| 140 | rednet.broadcast("ancientoff")
| |
| 141 | end | |
| 142 | end | |
| 143 | ||
| 144 | ||
| 145 | --You can add more buttons and also change the size of them. The format is startingx,startingy,endingx,endingy,text,function | |
| 146 | ||
| 147 | --The buttons | |
| 148 | newButton(1, 2,24,2,6,"Villager",villager) | |
| 149 | newButton(2, 26,48,2,6,"ZNK Killer",znkkiller) | |
| 150 | newButton(3, 26,48,7,11,"Microsoft Killer",microsoftkiller) | |
| 151 | newButton(4, 2,24,7,11,"Ancient Knight",ancientknight) | |
| 152 | ------------------------------------------------ | |
| 153 | ||
| 154 | ||
| 155 | ||
| 156 | m.clear() | |
| 157 | refreshButtons() | |
| 158 | ||
| 159 | ||
| 160 | --main loop | |
| 161 | while true do | |
| 162 | e,side,x,y = os.pullEvent("monitor_touch")
| |
| 163 | checkxy(x,y) | |
| 164 | ||
| 165 | refreshButtons() | |
| 166 | end | |
| 167 |