Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Define some constants for the elevator - make editing for other elevators easier
- -- Optionally give names to some floors. If a name is specified, it will be matched against this list to be converted to a floor number.
- floorNames =
- {lobby = 1, ground = 1, cafe = 7,
- penthouse = 19, basement = 0,
- cloudcafe = 7, library = 3,
- storage = 2, cave = -13}
- -- The highest floor number the elevator can travel to.
- highFloor = 19
- -- The lowest floor number to which the elevator can travel. Not required to be 1 - 1 usually represents a ground floor, and there can be basements and sub-basements as well.
- lowFloor = -13
- -- The floor it is assumed the turtle is on if it can move no further down. This can be lower, but not higher, than lowFloor.
- shaftBottom = -13
- -- Floors which cannot be chosen as elevator destinations. Attempting to take an elevator to such a floor from within will fail. Attempting to call the elevator to the floor from outside will still succeed.
- invalidFloors =
- {6, 8, 18, -10, -11, -12}
- -- Use the above list as a blacklist instead of a blacklist.
- blacklistFloors = true
- -- The distance in blocks an elevator must travel from one floor to be on the next.
- floorDistance = 6
- -- Do lighting?
- doLighting = false
- -- These functions are for moving.
- function u(m)
- n = m or 1
- for a = 1, n do
- if turtle.detectUp() then
- return false
- end
- if doLighting then rs.setOutput("front", false) end
- while not turtle.up() do end
- if doLighting then rs.setOutput("front", true) end
- end
- return true
- end
- function d(m)
- n = m or 1
- for a = 1, n do
- if turtle.detectDown() then
- return false
- end
- if doLighting then rs.setOutput("front", false) end
- while not turtle.down() do end
- if doLighting then rs.setOutput("front", true) end
- end
- return true
- end
- currFloor = 0
- callToFloor = 0
- function startup()
- if doLighting then rs.setOutput("front", true)
- else rs.setOutput("front", false) end
- rednet.open("right")
- rednet.broadcast("TO " .. shaftBottom)
- rs.setOutput("left", true)
- while d() do end
- currFloor = shaftBottom
- callToFloor = currFloor
- rednet.broadcast("AT " .. currFloor)
- run = true
- while run do
- callToFloor = -32768
- rs.setOutput("back", true)
- parallel.waitForAny(acceptCall, queryFloor)
- rs.setOutput("back", false)
- if callToFloor ~= -32768 then
- travelToFloor(callToFloor)
- else
- run = false
- end
- end
- end
- acceptCall = function()
- sleep(10)
- waitingForCall = true
- while waitingForCall do
- sender, message, distance = rednet.receive()
- if string.sub(message, 1, 5) == "CALL " then
- callToFloor = tonumber(string.sub(message, 6))
- if callToFloor ~= nil then waitingForCall = false
- else callToFloor = currFloor end
- end
- end
- end
- queryFloor = function()
- invalidInput = true
- while invalidInput do
- print("Enter the floor to which to travel: ")
- query = io.read():lower()
- if tonumber(query) == nil then query = floorNames[query]
- else query = tonumber(query) end
- if query ~= nil then
- query = math.floor(query)
- if query >= lowFloor and query <= highFloor then
- invalidFloor = false
- for a = 1, #invalidFloors do
- if query == invalidFloors[a] then invalidFloor = true end
- end
- invalidInput = (invalidFloor and blacklistFloors) or (not invalidFloor and not blacklistFloors)
- end
- end
- if invalidInput then print("I'm sorry but that is not a valid floor. Please try again.") end
- end
- callToFloor = query
- end
- function travelToFloor(destination)
- print("Traveling to floor " .. destination)
- sleep(0.1)
- rednet.broadcast("TO " .. destination)
- while currFloor ~= destination do
- if currFloor > destination then travelOneFloor(false)
- else travelOneFloor(true) end
- end
- end
- function travelOneFloor(up)
- if up then
- u(floorDistance)
- currFloor = currFloor + 1
- else
- d(floorDistance)
- currFloor = currFloor - 1
- end
- rednet.broadcast("AT " .. currFloor)
- end
- startup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement