Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Elevator Floor Selection
- Written by TheShadow989
- ]]--
- -- Reference Images used to build: https://imgur.com/a/laqDQ9x
- --[[
- Directional Cable Colors
- upCable = Used to move the frame elevator up.
- downCable = Used to move the frame elevator down.
- ]]--
- local upCable = colors.white -- Cable color for the elevator to go up
- local downCable = colors.black -- Cable color for the elevator to go down
- --[[
- Current Computer Index
- Set this value to the floorOptions index of the current floor that the computer is on.
- Without this value the 'Call' button will not work correctly.
- ]]--
- local currentComputerIndex = 1
- --[[
- Floor Options Array
- NOTE: This array is going to be the same on every computer, only change the 'Current Computer Index' value above for each computer.
- ID = Floor array index (Must be in numerical order)
- floorName = Custom floor name (examples: FL1, GRD, Floor 1, F1, 1)
- floorCable = Cable color that is used to track where the elevator is.
- doorCable = Cable color that is used to open and close the elevator doors (Not required)
- ]]--
- local floorOptions =
- {
- [1] = {floorName=" 1 ", floorCable=colors.yellow, doorCable=colors.orange},
- [2] = {floorName=" 2 ", floorCable=colors.magenta, doorCable=colors.purple},
- [3] = {floorName=" 3 ", floorCable=colors.lightBlue, doorCable=colors.blue},
- [4] = {floorName=" 4 ", floorCable=colors.lime, doorCable=colors.green},
- [5] = {floorName=" 5 ", floorCable=colors.pink, doorCable=colors.red},
- [6] = {floorName=" 6 ", floorCable=colors.lightGray, doorCable=colors.gray},
- [7] = {floorName=" 7 ", floorCable=colors.cyan, doorCable=colors.brown},
- }
- -- Working Variables (DO NOT CHANGE)
- local sides = {"top", "bottom", "left", "right", "front", "back"} -- Used the find the monitor side.
- local mon = "" -- Monitor
- local currentFloorIndex = 1 -- The floor that the elevator is on. This value will change as the elevator moves.
- local targetFloorIndex = -1 -- The target floor from the selection menu.
- local positionReset = true; -- If elevator is between floors on logout (server close). When player logs back in the elevator will go up a floor until a floor cable is triggered. Only happens once on program startup.
- --Find Monitor Side
- for i=1, #sides do
- if peripheral.isPresent(sides[i]) then
- if peripheral.getType(sides[i]) == "monitor" then
- mon = peripheral.wrap(sides[i])
- end
- end
- end
- --Reset Program
- term.clear()
- mon.clear()
- redstone.setBundledOutput("top", 0)
- while true do
- os.queueEvent("fakeEvent")
- os.pullEvent()
- for index, data in pairs(floorOptions) do
- if redstone.testBundledInput("top", data.floorCable) then
- positionReset = false
- end
- end
- if positionReset then
- redstone.setBundledOutput("top", colors.combine(redstone.getBundledOutput("top"), upCable))
- else
- break
- end
- end
- --------------------------------------------------------------------------
- -- Center Monitor Text Function
- --------------------------------------------------------------------------
- local function centerMonitorText(text, xcor, ycor)
- mon.setCursorPos(xcor,ycor)
- local x,y = mon.getSize()
- local x2,y2 = mon.getCursorPos()
- if x == 7 or x == 29 or x == 39 then
- mon.setCursorPos(math.ceil((x / 2) - (text:len() / 2)) + 1, y2)
- else
- mon.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
- end
- mon.write(text)
- end
- --------------------------------------------------------------------------
- -- Draw Current Floor Menu Function
- --------------------------------------------------------------------------
- local function drawCurrentFloorMenu(index)
- mon.clear()
- mon.setCursorPos(0,0)
- mon.setBackgroundColor(colors.black)
- local x, y = mon.getSize()
- mon.setTextScale(1)
- mon.setCursorPos(1,1)
- mon.write("--------------------------------------------------------------------------------------------------------")
- mon.setCursorPos(x/2-(#floorOptions[index].floorName / 2) + 1, 3)
- mon.write(floorOptions[index].floorName)
- mon.setCursorPos(1,5)
- mon.write("--------------------------------------------------------------------------------------------------------")
- end
- --------------------------------------------------------------------------
- -- Draw Call Elevator Menu Function
- --------------------------------------------------------------------------
- local function drawCallMenu()
- mon.setBackgroundColor(colors.gray)
- centerMonitorText(" ", 2, 8)
- centerMonitorText("Call ", 2, 9)
- centerMonitorText(" ", 2, 10)
- mon.setBackgroundColor(colors.black)
- end
- --------------------------------------------------------------------------
- -- Draw Selection Menu Function
- --------------------------------------------------------------------------
- local function drawSelectMenu()
- local x, y = mon.getSize()
- for index, data in pairs(floorOptions) do
- mon.setCursorPos(x/2-(#data.floorName / 2) + 1, 5 + index)
- mon.setBackgroundColor(colors.gray)
- mon.write(data.floorName)
- mon.setBackgroundColor(colors.black)
- end
- end
- --------------------------------------------------------------------------
- -- Check Elevator Location
- --------------------------------------------------------------------------
- local function checkElevatorLocation()
- for index, data in pairs(floorOptions) do
- if redstone.testBundledInput("top", data.floorCable) then
- currentFloorIndex = index
- if not(redstone.testBundledInput("top", upCable) or redstone.testBundledInput("top", downCable)) then
- redstone.setBundledOutput("top", colors.subtract(redstone.getBundledOutput("top"), data.doorCable))
- end
- else
- redstone.setBundledOutput("top", colors.combine(redstone.getBundledOutput("top"), data.doorCable))
- end
- end
- drawCurrentFloorMenu(currentFloorIndex)
- if not(redstone.testBundledInput("top", upCable) or redstone.testBundledInput("top", downCable)) then
- if redstone.getInput("front") then
- drawSelectMenu()
- else
- drawCallMenu()
- end
- else
- centerMonitorText("Please", 0, 8)
- centerMonitorText("Wait..", 0, 9)
- mon.setBackgroundColor(colors.black)
- end
- -- Display up arrow if elevator going up
- if redstone.testBundledInput("top", upCable) then
- centerMonitorText("^", 0, 2)
- end
- -- Display down arrow if elevator going down
- if redstone.testBundledInput("top", downCable) then
- centerMonitorText("v", 0, 4)
- end
- end
- --------------------------------------------------------------------------
- -- Check Click Function
- --------------------------------------------------------------------------
- local function checkClick(x,y)
- if redstone.getInput("front") then
- for index, data in pairs(floorOptions) do
- if y == index + 5 then
- targetFloorIndex = index
- print(index)
- os.sleep(2)
- end
- end
- else
- targetFloorIndex = currentComputerIndex
- end
- return false
- end
- checkElevatorLocation()
- --------------------------------------------------------------------------
- -- PROGRAM LOOP
- --------------------------------------------------------------------------
- while true do
- local e = {os.pullEvent()}
- --Check Elevator Location
- checkElevatorLocation()
- if not(redstone.testBundledInput("top", upCable) or redstone.testBundledInput("top", downCable)) then
- if e[1] == "monitor_touch" then
- checkClick(e[3], e[4])
- end
- end
- if targetFloorIndex ~= -1 and currentFloorIndex ~= targetFloorIndex then
- if currentFloorIndex < targetFloorIndex then -- Down
- print("Going Down" .. " curIndex: " .. currentFloorIndex .. " tarIndex: " .. targetFloorIndex)
- redstone.setBundledOutput("top", colors.combine(redstone.getBundledOutput("top"), downCable))
- elseif currentFloorIndex > targetFloorIndex then -- Up
- print("Going Up" .. " curIndex: " .. currentFloorIndex .. " tarIndex: " .. targetFloorIndex)
- redstone.setBundledOutput("top", colors.combine(redstone.getBundledOutput("top"), upCable))
- end
- else -- Stop Elevator
- print("Stopping" .. " curIndex: " .. currentFloorIndex .. " tarIndex: " .. targetFloorIndex)
- targetFloorIndex = -1
- redstone.setBundledOutput("top", colors.subtract(redstone.getBundledOutput("top"), downCable))
- redstone.setBundledOutput("top", colors.subtract(redstone.getBundledOutput("top"), upCable))
- end
- end
Add Comment
Please, Sign In to add comment