temposabel

clicktest

Dec 19th, 2021 (edited)
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. function getmodems(mode)
  2. mode = mode or "default"
  3.  
  4. if mode == "default" then
  5. allp = peripheral.getNames()
  6. d = {}
  7. x = 0
  8. for i,value in ipairs(allp) do
  9. c = peripheral.getType(value)
  10. if c == "modem" then
  11. c = peripheral.wrap(value)
  12. x = x + 1
  13. d[x] = c
  14. end
  15. end
  16. d["a"] = x
  17. d["amount"] = x
  18. return d
  19. elseif mode == "sides" or mode =="s" then
  20. allp = peripheral.getNames()
  21. d = {}
  22. x = 0
  23. for i,value in ipairs(allp) do
  24. c = peripheral.getType(value)
  25. if c == "modem" then
  26. x = x + 1
  27. d[x] = value
  28. end
  29. end
  30. d["a"] = x
  31. d["amount"] = x
  32. return d
  33. end
  34. end
  35.  
  36. function getmsg()
  37. while true do
  38. d = {}
  39. event, side, frequency, replyFrequency, message, distance = os.pullEvent("modem_message")
  40. d["e"] = event
  41. d["s"] = side
  42. d["f"] = frequency
  43. d["rf"] = replyFrequency
  44. d["m"] = message
  45. d["d"] = distance
  46. return d
  47. end
  48. end
  49.  
  50. function transmitall(p,rp,message)
  51. modems = getmodems()
  52. print(modems["a"])
  53. if modems["a"] == 0 then else
  54. for modem = 1,modems["a"] do
  55. cm = modems[modem]
  56. cm.transmit(p,rp,message)
  57. end
  58. end
  59. end
  60.  
  61. function relay(p,rp,message,exclude)
  62. sides = getmodems("s")
  63. if modems["a"] == 0 then else
  64. for side = 1,modems["a"] do
  65. cs = sides[side]
  66. if cs == exclude then else
  67. cm.transmit(p,rp,message)
  68. end
  69. end
  70. end
  71. end
  72.  
  73. function cooldown (time)
  74.  
  75. for i = 1,time do
  76. term.clear()
  77. term.setCursorPos(5,3)
  78. print(time-i+1)
  79. sleep(1)
  80. end
  81. return 0
  82. end
  83. function createbutton(x,y,w,h,color,message)
  84.  
  85. d = {}
  86.  
  87. function d:init(x,y,w,h,color,message)
  88. self.x1 = x
  89. self.x2 = x+w
  90. self.y1 = y
  91. self.y2 = y+h
  92. self.color = color
  93. self.message = message
  94. end
  95.  
  96. function d:isclickon (x,y)
  97.  
  98. if self.x1 <= x and x <= self.x2 and self.y1 <= y and y <= self.y2 then
  99. return true
  100. else
  101. return false
  102. end
  103.  
  104.  
  105. end
  106.  
  107. function d:draw ()
  108. --print(self.x1)
  109. paintutils.drawFilledBox(self.x1,self.y1,self.x2,self.y2,self.color)
  110. term.setTextColor(colors.white)
  111. term.setCursorPos(self.x1+1,self.y1+1)
  112. print("Open")
  113. term.setBackgroundColor(colors.black)
  114. end
  115.  
  116. d:init(x,y,w,h,color,message)
  117. return d
  118. end
  119. term.redirect(peripheral.wrap("top"))
  120. moni = peripheral.wrap("top")
  121. moni.setTextScale(2)
  122.  
  123.  
  124. but1 = createbutton(2,2,6,2,colors.green,"open")
  125.  
  126.  
  127. while true do
  128. term.clear()
  129. but1:draw()
  130. local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  131. if but1:isclickon(xPos,yPos) then redstone.setAnalogOutput("right",1)
  132. cooldown(3)
  133. redstone.setAnalogOutput("right",0)
  134. end
  135.  
  136. --print(but1:isclickon(mx,my))
  137. --print(but2:isclickon(mx,my))
  138.  
  139.  
  140. end
  141.  
Add Comment
Please, Sign In to add comment