Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getmodems(mode)
- mode = mode or "default"
- if mode == "default" then
- allp = peripheral.getNames()
- d = {}
- x = 0
- for i,value in ipairs(allp) do
- c = peripheral.getType(value)
- if c == "modem" then
- c = peripheral.wrap(value)
- x = x + 1
- d[x] = c
- end
- end
- d["a"] = x
- d["amount"] = x
- return d
- elseif mode == "sides" or mode =="s" then
- allp = peripheral.getNames()
- d = {}
- x = 0
- for i,value in ipairs(allp) do
- c = peripheral.getType(value)
- if c == "modem" then
- x = x + 1
- d[x] = value
- end
- end
- d["a"] = x
- d["amount"] = x
- return d
- end
- end
- function getmsg()
- while true do
- d = {}
- event, side, frequency, replyFrequency, message, distance = os.pullEvent("modem_message")
- d["e"] = event
- d["s"] = side
- d["f"] = frequency
- d["rf"] = replyFrequency
- d["m"] = message
- d["d"] = distance
- return d
- end
- end
- function transmitall(p,rp,message)
- modems = getmodems()
- print(modems["a"])
- if modems["a"] == 0 then else
- for modem = 1,modems["a"] do
- cm = modems[modem]
- cm.transmit(p,rp,message)
- end
- end
- end
- function relay(p,rp,message,exclude)
- sides = getmodems("s")
- if modems["a"] == 0 then else
- for side = 1,modems["a"] do
- cs = sides[side]
- if cs == exclude then else
- cm.transmit(p,rp,message)
- end
- end
- end
- end
- function cooldown (time)
- for i = 1,time do
- term.clear()
- term.setCursorPos(5,3)
- print(time-i+1)
- sleep(1)
- end
- return 0
- end
- function createbutton(x,y,w,h,color,message)
- d = {}
- function d:init(x,y,w,h,color,message)
- self.x1 = x
- self.x2 = x+w
- self.y1 = y
- self.y2 = y+h
- self.color = color
- self.message = message
- end
- function d:isclickon (x,y)
- if self.x1 <= x and x <= self.x2 and self.y1 <= y and y <= self.y2 then
- return true
- else
- return false
- end
- end
- function d:draw ()
- --print(self.x1)
- paintutils.drawFilledBox(self.x1,self.y1,self.x2,self.y2,self.color)
- term.setTextColor(colors.white)
- term.setCursorPos(self.x1+1,self.y1+1)
- print("Open")
- term.setBackgroundColor(colors.black)
- end
- d:init(x,y,w,h,color,message)
- return d
- end
- term.redirect(peripheral.wrap("top"))
- moni = peripheral.wrap("top")
- moni.setTextScale(2)
- but1 = createbutton(2,2,6,2,colors.green,"open")
- while true do
- term.clear()
- but1:draw()
- local event, side, xPos, yPos = os.pullEvent("monitor_touch")
- if but1:isclickon(xPos,yPos) then redstone.setAnalogOutput("right",1)
- cooldown(3)
- redstone.setAnalogOutput("right",0)
- end
- --print(but1:isclickon(mx,my))
- --print(but2:isclickon(mx,my))
- end
Add Comment
Please, Sign In to add comment