Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local prot = "elev1"
- local floorNumber = 0
- local totalFloors = 9--Start counting at 0
- local launchCode = colors.magenta
- local cartDetectCode = colors.orange
- local elevatorCode = colors.white
- local RS_SIDE = "back"
- rednet.open("right")
- mon = peripheral.wrap("monitor_0")
- local sizeX,sizeY = mon.getSize()
- function isCartHere()
- return redstone.testBundledInput(RS_SIDE,cartDetectCode)
- end
- function releaseCart()
- redstone.setBundledOutput(RS_SIDE,launchCode)
- sleep(0.5)
- redstone.setBundledOutput(RS_SIDE,0)
- end
- function callCart()
- redstone.setBundledOutput(RS_SIDE,elevatorCode)
- rednet.broadcast("CALL",prot)
- end
- function goToFloor(f)
- if ((f <= totalFloors) and (f ~= floorNumber) and (isCartHere())) then
- rednet.broadcast("SEND "..f,prot)
- releaseCart()
- end
- end
- function update()
- local event,p1,p2,p3,p4,p5 = os.pullEvent()
- if (event == "monitor_touch") then
- local x = p2
- local y = p3
- if (x == sizeX) then
- if (not isCartHere()) then
- callCart()
- end
- elseif (x >= 4) then
- local f = (y*2)-1
- if (f <= totalFloors) then
- goToFloor(f)
- end
- else
- local f = (y*2)-2
- if (f <= totalFloors) then
- goToFloor(f)
- end
- end
- elseif ((event == "rednet_message") and (p3 == prot)) then
- local keywords = {}
- for i in string.gmatch(p2,"%S+") do
- table.insert(keywords,i)
- end
- if (keywords[1] == "CALL") then
- if (isCartHere()) then
- releaseCart()
- end
- elseif ((keywords[1] == "SEND") and (tonumber(keywords[2]) == floorNumber)) then
- redstone.setBundledOutput(RS_SIDE,elevatorCode)
- end
- elseif (event == "redstone") then
- if (isCartHere()) then
- --Cart Arrived
- redstone.setBundledOutput(RS_SIDE,0)
- end
- end
- end
- function display()
- mon.setBackgroundColor(colors.black)
- mon.clear()
- mon.setCursorPos(1,1)
- mon.setTextColor(colors.white)
- local c = colors.black
- for i=0,totalFloors do
- if ((i % 4 == 0) or ((i+1) % 4 == 0)) then
- c = colors.black
- else
- c = colors.gray
- end
- local x,y = mon.getCursorPos()
- if (x > sizeX-1) then
- mon.setCursorPos(1,y+1)
- end
- mon.setBackgroundColor(c)
- if (i == floorNumber) then
- mon.setTextColor(colors.lightGray)
- else
- mon.setTextColor(colors.white)
- end
- mon.write(" "..tostring(i).." ")
- end
- mon.setBackgroundColor(colors.white)
- for i=1,sizeY do
- mon.setCursorPos(sizeX,i)
- mon.write(" ")
- end
- mon.setTextColor(colors.blue)
- mon.setCursorPos(sizeX,1)
- mon.write("C")
- mon.setCursorPos(sizeX,2)
- mon.write("A")
- mon.setCursorPos(sizeX,3)
- mon.write("L")
- mon.setCursorPos(sizeX,4)
- mon.write("L")
- end
- display()
- while (true) do
- update()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement