Advertisement
Ezteyh

screen button final rr

Aug 5th, 2022
1,294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.42 KB | None | 0 0
  1. peripheral.find("modem",rednet.open)
  2. local monitor = peripheral.find("monitor")
  3. peripheral.wrap("monitor")
  4. monitor.setTextScale(1)
  5. monitor.clear()
  6.  
  7. local defaultBackgroundColor = colors.black
  8. local defaultTextColor = colors.white
  9.  
  10. local backgroundColorNormal = colors.blue
  11. local backgroundColorPressed = colors.red
  12.  
  13. local textColorNormal = colors.white
  14. local textColorPressed = colors.yellow
  15.  
  16. local width = 3
  17. local height = 1.75
  18. local startColumn = {2,6,9}
  19. local startRow = {3,5,7, 3,5,7}
  20. local row = 2
  21. local column = 2
  22.  
  23. local tlabel = {"1","2","3","4","5","6"}
  24. local label = "1"
  25. local label0 = "0"
  26.  
  27. local x, y, z = gps.locate(5)
  28. local turtleID = 23
  29.  
  30. local speaker = peripheral.find("speaker")
  31.  
  32. function resetScreen()
  33.     monitor.setBackgroundColor(defaultBackgroundColor)
  34.     monitor.setTextColor(defaultTextColor)
  35. end
  36.  
  37. --init
  38. function init()
  39.     resetScreen()
  40.     monitor.setTextScale(1.5)
  41.     monitor.clear()
  42. end
  43.  
  44. --button background
  45. function displayButtonBackground()
  46.     monitor.setBackgroundColor(backgroundColorNormal)
  47.     for roww = row, row + height - 1 do
  48.         monitor.setCursorPos(column, row)
  49.         monitor.write(string.rep(" ", width))
  50.     end
  51. end
  52.  
  53. --display label
  54. function displayLabel()
  55.     monitor.setTextColor(textColorNormal)
  56.     displayButtonBackground()
  57.     monitor.setCursorPos(column + math.floor((width - #label)/2), row + math.floor(height/2))
  58.     monitor.write(label)
  59. end
  60.  
  61. function displayLabel0()
  62.     monitor.setTextColor(textColorNormal)
  63.     monitor.setCursorPos(6, 1)
  64.     monitor.setBackgroundColor(backgroundColorNormal)
  65.     monitor.write(string.rep(" ", width))
  66.     monitor.setCursorPos(6 + math.floor((width - #label0)/2), 1 + math.floor(height/2))
  67.     monitor.write(label0)
  68. end
  69.  
  70. function etage0()
  71.     if y == 62 then
  72.         rednet.send(turtleID, "button062")
  73.     elseif y == 52 then
  74.         rednet.send(turtleID, "button052")
  75.     elseif y == 42 then
  76.         rednet.send(turtleID, "button042")
  77.     elseif y == 32 then
  78.         rednet.send(turtleID, "button032")
  79.     elseif y == 22 then
  80.         rednet.send(turtleID, "button022")
  81.     elseif y == 12 then
  82.         rednet.send(turtleID, "button012")
  83.     end
  84.     rickroll()
  85. end
  86.  
  87. function etage1()
  88.     if y == 72 then
  89.         rednet.send(turtleID, "button172")
  90.     elseif y == 52 then
  91.         rednet.send(turtleID, "button152")
  92.     elseif y == 42 then
  93.         rednet.send(turtleID, "button142")
  94.     elseif y == 32 then
  95.         rednet.send(turtleID, "button132")
  96.     elseif y == 22 then
  97.         rednet.send(turtleID, "button122")
  98.     elseif y == 12 then
  99.         rednet.send(turtleID, "button112")
  100.     end
  101.     rickroll()
  102. end
  103.  
  104. function etage2()
  105.     if y == 72 then
  106.         rednet.send(turtleID, "button272")
  107.     elseif y == 62 then
  108.         rednet.send(turtleID, "button262")
  109.     elseif y == 42 then
  110.         rednet.send(turtleID, "button242")
  111.     elseif y == 32 then
  112.         rednet.send(turtleID, "button232")
  113.     elseif y == 22 then
  114.         rednet.send(turtleID, "button222")
  115.     elseif y == 12 then
  116.         rednet.send(turtleID, "button212")
  117.     end
  118.     rickroll()
  119. end
  120.  
  121. function etage3()
  122.     if y == 72 then
  123.         rednet.send(turtleID, "button372")
  124.     elseif y == 62 then
  125.         rednet.send(turtleID, "button362")
  126.     elseif y == 52 then
  127.         rednet.send(turtleID, "button352")
  128.     elseif y == 32 then
  129.         rednet.send(turtleID, "button332")
  130.     elseif y == 22 then
  131.         rednet.send(turtleID, "button322")
  132.     elseif y == 12 then
  133.         rednet.send(turtleID, "button312")
  134.     end
  135.     rickroll()
  136. end
  137.  
  138. function etage4()
  139.     if y == 72 then
  140.         rednet.send(turtleID, "button472")
  141.     elseif y == 62 then
  142.         rednet.send(turtleID, "button462")
  143.     elseif y == 52 then
  144.         rednet.send(turtleID, "button452")
  145.     elseif y == 42 then
  146.         rednet.send(turtleID, "button442")
  147.     elseif y == 22 then
  148.         rednet.send(turtleID, "button422")
  149.     elseif y == 12 then
  150.         rednet.send(turtleID, "button412")
  151.     end
  152.     rickroll()
  153. end
  154.  
  155. function etage5()
  156.     if y == 72 then
  157.         rednet.send(turtleID, "button572")
  158.     elseif y == 62 then
  159.         rednet.send(turtleID, "button562")
  160.     elseif y == 52 then
  161.         rednet.send(turtleID, "button552")
  162.     elseif y == 42 then
  163.         rednet.send(turtleID, "button542")
  164.     elseif y == 32 then
  165.         rednet.send(turtleID, "button532")
  166.     elseif y == 12 then
  167.         rednet.send(turtleID, "button512")
  168.     end
  169.     rickroll()
  170. end
  171.  
  172. function etage6()
  173.     if y == 72 then
  174.         rednet.send(turtleID, "button672")
  175.     elseif y == 62 then
  176.         rednet.send(turtleID, "button662")
  177.     elseif y == 52 then
  178.         rednet.send(turtleID, "button652")
  179.     elseif y == 42 then
  180.         rednet.send(turtleID, "button642")
  181.     elseif y == 32 then
  182.         rednet.send(turtleID, "button632")
  183.     elseif y == 22 then
  184.         rednet.send(turtleID, "button622")
  185.     end
  186.     rickroll()
  187. end
  188.  
  189. function rickroll()
  190.     speaker.playNote("flute", 0.5, 5)
  191.     sleep(0.2)
  192.     speaker.playNote("flute", 0.5, 7)
  193.     sleep(0.2)
  194.     speaker.playNote("flute", 0.5, 10)
  195.     sleep(0.2)
  196.     speaker.playNote("flute", 0.5, 7)
  197.     sleep(0.2)
  198.     speaker.playNote("flute", 0.5, 14)
  199.     sleep(0.3)
  200.     speaker.playNote("flute", 0.5, 14)
  201.     sleep(0.3)
  202.     speaker.playNote("flute", 0.5, 12)
  203.    
  204.     sleep(0.6)
  205.    
  206.     speaker.playNote("flute", 0.5, 5)
  207.     sleep(0.2)
  208.     speaker.playNote("flute", 0.5, 7)
  209.     sleep(0.2)
  210.     speaker.playNote("flute", 0.5, 10)
  211.     sleep(0.2)
  212.     speaker.playNote("flute", 0.5, 7)
  213.     sleep(0.2)
  214.     speaker.playNote("flute", 0.5, 12)
  215.     sleep(0.3)
  216.     speaker.playNote("flute", 0.5, 12)
  217.     sleep(0.3)
  218.     speaker.playNote("flute", 0.5, 10)
  219.     sleep(0.1)
  220.     speaker.playNote("flute", 0.5, 9)
  221.     sleep(0.1)
  222.     speaker.playNote("flute", 0.5, 7)
  223. end
  224.  
  225. init()
  226. for i = 1, 3, 1 do
  227.     column = startColumn[1]
  228.     row = startRow[i]
  229.     label = tlabel[i]
  230.     displayLabel()
  231. end
  232. for i = 4, 6, 1 do
  233.     column = startColumn[3]
  234.     row = startRow[i]
  235.     label = tlabel[i]
  236.     displayLabel()
  237. end
  238. displayLabel0()
  239.  
  240. while (1) do
  241.     local event, button, cx, cy, message, senderId, distance = {os.pullEvent()}
  242.        
  243.         if event[1] == "rednet_message" then
  244.  
  245.             if event[3] == "call0" then
  246.                 etage0()
  247.             end
  248.            
  249.             if event[3] == "call10" then
  250.                 etage1()
  251.             end
  252.  
  253.             if event[3] == "call20" then
  254.                 etage2()
  255.             end
  256.  
  257.             if event[3] == "call30" then
  258.                 etage3()
  259.             end
  260.  
  261.             if event[3] == "call40" then
  262.                 etage4()
  263.             end
  264.            
  265.             if event[3] == "call50" then
  266.                 etage5()
  267.             end
  268.  
  269.             if event[3] == "call60" then
  270.                 etage6()
  271.             end
  272.  
  273.         elseif event[1] == "monitor_touch" then
  274.  
  275.             --Etage 1
  276.             if y ~= 62 and event[3] >= startColumn[1] and event[3] < (startColumn[1] + width) and event[4] >= startRow[1] and event[4] < (startRow[1] + 1) then
  277.                 etage1()
  278.             end
  279.  
  280.             --Etage 2
  281.             if y ~= 52 and event[3] >= startColumn[1] and event[3] < (startColumn[1] + width) and event[4] >= startRow[2] and event[4] < (startRow[2] + 1) then
  282.                 etage2()
  283.             end
  284.  
  285.             --Etage 3
  286.             if y ~= 42 and event[3] >= startColumn[1] and event[3] < (startColumn[1] + width) and event[4] >= startRow[3] and event[4] < (startRow[3] + 1) then
  287.                 etage3()
  288.             end
  289.  
  290.             --Etage 4
  291.             if y ~= 32 and event[3] >= startColumn[3] and event[3] < (startColumn[3] + width) and event[4] >= startRow[1] and event[4] < (startRow[1] + 1) then
  292.                 etage4()
  293.             end
  294.  
  295.             --Etage 5
  296.             if y ~= 22 and event[3] >= startColumn[3] and event[3] < (startColumn[3] + width) and event[4] >= startRow[2] and event[4] < (startRow[2] + 1) then
  297.                 etage5()
  298.             end
  299.  
  300.             --Etage 6
  301.             if y ~= 12 and event[3] >= startColumn[3] and event[3] < (startColumn[3] + width) and event[4] >= startRow[3] and event[4] < (startRow[3] + 1) then
  302.                 etage6()
  303.             end
  304.  
  305.             --Etage 0
  306.             if y ~= 72 and event[3] >= startColumn[2] and event[3] < (startColumn[2] + width) and event[4] >= 1 and event[4] < (2) then
  307.                 etage0()
  308.             end
  309.         end
  310. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement