Advertisement
rhn

Elevator Touchscreen v2

rhn
Aug 13th, 2014
603
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.68 KB | None | 0 0
  1. --Enhanced Portals 3 elevator API.
  2. --To use this API, copy and run the startup script: http://pastebin.com/kKdbx3Ty
  3. --More details about physical structure etc. is also found in the header of the startup script.
  4.  
  5. function elevator(buttontext)
  6.     --Load floor location from disk
  7.     local FloorFile = fs.open("disk/floor", "r")
  8.  
  9.  
  10.     if FloorFile then
  11.         ThisFloor = tonumber(FloorFile.readLine())
  12.         print("This floor: "..ThisFloor)
  13.         FloorFile.close()
  14.     else
  15.         print("No Floor File/disk found")
  16.         return
  17.     end
  18.  
  19.     os.setComputerLabel("Elevator"..ThisFloor)
  20.  
  21.     local buttoncolours={}
  22.     for k=1, #buttontext do
  23.         buttoncolours[k]=8192 --8192=green
  24.     end
  25.     buttoncolours[ThisFloor]=32 --32=lime
  26.  
  27.     local mouseWidth = 0
  28.     local mouseHeight = 0
  29.  
  30.     monitor = peripheral.wrap("bottom")
  31.  
  32.     monitor.clear()
  33.     monitor.setCursorPos(1,1)
  34.     w,h=monitor.getSize()
  35.     print(w)
  36.     print(h)
  37.  
  38.     --Draw buttons
  39.     for k=1, #buttontext do
  40.  
  41.         monitor.setBackgroundColour((buttoncolours[k]))
  42.         monitor.setCursorPos(2,k*2)
  43.         monitor.write(buttontext[k])
  44.         monitor.setBackgroundColour((colours.black))
  45.     end --for
  46.  
  47.     repeat
  48.             event,p1,p2,p3 = os.pullEvent()
  49.                     if event=="monitor_touch" then
  50.                             mouseWidth = p2 -- sets mouseWidth
  51.                             mouseHeight = p3 -- and mouseHeight
  52.                 for k=1, #buttontext do
  53.                     if mouseWidth > 1 and mouseWidth < 18 and mouseHeight == k*2 and k~=ThisFloor then
  54.                         redstone.setOutput("top", true)
  55.                         sleep(1)
  56.                         redstone.setAnalogOutput("back", k)
  57.                         sleep(2)
  58.                         redstone.setOutput("top", false)
  59.                         redstone.setAnalogOutput("back", 0)
  60.                     end
  61.                 end
  62.                     end
  63.     until event=="char" and p1==("x")
  64. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement