fi5hii

Untitled

May 11th, 2024
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. -- Load the required components
  2. local monitor = peripheral.find("monitor", function(name) return name == "monitor_2" end) -- Monitor peripheral named monitor_2
  3. local redstoneSide = "left" -- Define the side where the redstone is connected
  4. local redstoneTop = "top" -- Define the side where the redstone is connected
  5.  
  6. -- Function to display line 1 from create_target_1 on monitor_2
  7. function displayLine()
  8. -- Get the line 1 from create_target_1
  9. local line = peripheral.call("create_target_1", "getLine", 1)
  10.  
  11. -- Clear the monitor
  12. monitor.clear()
  13.  
  14. -- Set cursor position at (1,1)
  15. monitor.setCursorPos(1, 1)
  16.  
  17. -- Display the line on monitor
  18. monitor.write(line)
  19.  
  20. -- Display clickable text below the line
  21. monitor.setCursorPos(1, 3)
  22. monitor.setTextColor(colors.green) -- Set text color to green
  23. monitor.write("ON")
  24. monitor.setTextColor(colors.red) -- Set text color to red
  25. monitor.write(" OFF")
  26. monitor.setTextColor(colors.white)
  27.  
  28. -- Return the hitbox coordinates for ON and OFF texts
  29. return 1, 2, 5, 8 -- x1, x2, x3, x4
  30. end
  31.  
  32. -- Function to handle monitor touch events
  33. function handleTouch(x, y)
  34. local onX1, onX2, offX1, offX2 = displayLine()
  35.  
  36. -- Check if touch is within the clickable area for ON
  37. if y == 3 and x >= onX1 and x <= onX2 then
  38. -- Send a 5-second redstone pulse on the left side
  39. redstone.setOutput(redstoneSide, true)
  40. sleep(5)
  41. redstone.setOutput(redstoneSide, false)
  42. end
  43.  
  44. -- Check if touch is within the clickable area for OFF
  45. if y == 3 and x >= offX1 and x <= offX2 then
  46. -- Send a 5-second redstone pulse on the top side
  47. redstone.setOutput(redstoneTop, true)
  48. sleep(5)
  49. redstone.setOutput(redstoneTop, false)
  50. end
  51. end
  52.  
  53. -- Main function
  54. function main()
  55. while true do
  56. -- Wait for touch event
  57. local event, side, x, y = os.pullEvent("monitor_touch")
  58. handleTouch(x, y)
  59. end
  60. end
  61.  
  62. -- Run the main function
  63. main()
  64.  
Advertisement
Add Comment
Please, Sign In to add comment