Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Enhanced Portals 3 elevator API.
- --To use this API, copy and run the startup script: http://pastebin.com/kKdbx3Ty
- --More details about physical structure etc. is also found in the header of the startup script.
- function elevator(buttontext)
- --Load floor location from disk
- local FloorFile = fs.open("disk/floor", "r")
- if FloorFile then
- ThisFloor = tonumber(FloorFile.readLine())
- print("This floor: "..ThisFloor)
- FloorFile.close()
- else
- print("No Floor File/disk found")
- return
- end
- os.setComputerLabel("Elevator"..ThisFloor)
- local buttoncolours={}
- for k=1, #buttontext do
- buttoncolours[k]=8192 --8192=green
- end
- buttoncolours[ThisFloor]=32 --32=lime
- local mouseWidth = 0
- local mouseHeight = 0
- monitor = peripheral.wrap("bottom")
- monitor.clear()
- monitor.setCursorPos(1,1)
- w,h=monitor.getSize()
- print(w)
- print(h)
- --Draw buttons
- for k=1, #buttontext do
- monitor.setBackgroundColour((buttoncolours[k]))
- monitor.setCursorPos(2,k*2)
- monitor.write(buttontext[k])
- monitor.setBackgroundColour((colours.black))
- end --for
- repeat
- event,p1,p2,p3 = os.pullEvent()
- if event=="monitor_touch" then
- mouseWidth = p2 -- sets mouseWidth
- mouseHeight = p3 -- and mouseHeight
- for k=1, #buttontext do
- if mouseWidth > 1 and mouseWidth < 18 and mouseHeight == k*2 and k~=ThisFloor then
- redstone.setOutput("top", true)
- sleep(1)
- redstone.setAnalogOutput("back", k)
- sleep(2)
- redstone.setOutput("top", false)
- redstone.setAnalogOutput("back", 0)
- end
- end
- end
- until event=="char" and p1==("x")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement