Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local floornum = 1
- local floordescription1 = "1 floor"
- local floordescription2 = "2 floor"
- local floordescription3 = "3 floor"
- local floordescription4 = "4 floor"
- local floordescription5 = "5 floor"
- local floordescription6 = "6 floor"
- local floordescription7 = "7 floor"
- local floordescription8 = "8 floor"
- local floordescription9 = "9 floor"
- mouseWidth = 0
- mouseHeight = 0
- monitor = peripheral.wrap("back")
- monitor.clear()
- monitor.setCursorPos(1,1)
- w,h=monitor.getSize()
- print(w)
- print(h)
- modem = peripheral.wrap("right")
- rednet.open("right")
- delay=math.random(10)
- sleep(delay)
- rednet.broadcast(floornum .. " active")
- local floor1available = 0
- local floor2available = 0
- local floor3available = 0
- local floor4available = 0
- local floor5available = 0
- local floor6available = 0
- local floor7available = 0
- local floor8available = 0
- local floor9available = 0
- --This sets cobblestone out
- rs.setOutput("bottom",true)
- function drawfloors()
- --BUTTON SELECTION
- monitor.setBackgroundColour((colours.lime))
- --button1
- if floor1available==1 then
- monitor.setCursorPos(1,2)
- monitor.write(floordescription1)
- end
- --button2
- if floor2available==1 then
- monitor.setCursorPos(1,4)
- monitor.write(floordescription2)
- end
- --button3
- if floor3available==1 then
- monitor.setCursorPos(1,6)
- monitor.write(floordescription3)
- end
- --button4
- if floor4available==1 then
- monitor.setCursorPos(1,8)
- monitor.write(floordescription4)
- end
- --button5
- if floor5available==1 then
- monitor.setCursorPos(1,10)
- monitor.write(floordescription5)
- end
- --button6
- if floor6available==1 then
- monitor.setCursorPos(1,12)
- monitor.write(floordescription6)
- end
- --button7
- if floor7available==1 then
- monitor.setCursorPos(1,14)
- monitor.write(floordescription7)
- end
- --button8
- if floor8available==1 then
- monitor.setCursorPos(1,16)
- monitor.write(floordescription8)
- end
- --button9
- if floor9available==1 then
- monitor.setCursorPos(1,18)
- monitor.write(floordescription9)
- end
- monitor.setBackgroundColour((colours.black))
- end
- function up()
- --set to go up
- rs.setOutput("bottom",false)
- sleep(0.5)
- rs.setOutput("left",true)
- sleep(2.5)
- rs.setOutput("left",false)
- sleep(0.5)
- rs.setOutput("bottom",true)
- end
- function down()
- --set to go down
- rs.setOutput("bottom",false)
- sleep(0.5)
- rs.setOutput("left",true)
- sleep(0.5)
- rs.setOutput("bottom",true)
- sleep(2.5)
- rs.setOutput("left",false)
- rs.setOutput("bottom",false)
- sleep(0.5)
- rs.setOutput("bottom",true)
- end
- function thru()
- --set to go down
- rs.setOutput("top",true)
- sleep(2.5)
- rs.setOutput("top",false)
- end
- function checkClickPosition()
- --button1
- if mouseWidth > 0 and mouseWidth < 18 and mouseHeight == 2 then
- local floor1=1
- if floornum == 1 then
- print("You are here")
- rednet.broadcast(floornum .. " active")
- end
- rednet.broadcast(floornum .. " 1")
- if floornum > floor1 then
- up()
- end
- if floornum < floor1 then
- down()
- end
- --button2
- elseif mouseWidth > 0 and mouseWidth < 18 and mouseHeight == 4 then
- local floor2=2
- if floornum == 2 then
- print("You are here")
- rednet.broadcast(floornum .. " active")
- end
- rednet.broadcast(floornum .. " 2")
- if floornum > floor2 then
- up()
- end
- if floornum < floor2 then
- down()
- end
- --button3
- elseif mouseWidth > 0 and mouseWidth < 18 and mouseHeight == 6 then
- local floor3=3
- if floornum == 3 then
- print("You are here")
- rednet.broadcast(floornum .. " active")
- end
- rednet.broadcast(floornum .. " 3")
- if floornum > floor3 then
- up()
- end
- if floornum < floor3 then
- down()
- end
- --button4
- elseif mouseWidth > 0 and mouseWidth < 18 and mouseHeight == 8 then
- local floor4=4
- if floornum == 4 then
- print("You are here")
- rednet.broadcast(floornum .. " active")
- end
- rednet.broadcast(floornum .. " 4")
- if floornum > floor4 then
- up()
- end
- if floornum < floor4 then
- down()
- end
- --button5
- elseif mouseWidth > 0 and mouseWidth < 18 and mouseHeight == 10 then
- local floor5=5
- if floornum == 5 then
- print("You are here")
- rednet.broadcast(floornum .. " active")
- end
- --from to broadcast
- rednet.broadcast(floornum .. " 5")
- if floornum > floor5 then
- up()
- end
- if floornum < floor5 then
- down()
- end
- --button6
- elseif mouseWidth > 0 and mouseWidth < 18 and mouseHeight == 12 then
- local floor6=6
- if floornum == 6 then
- print("You are here")
- rednet.broadcast(floornum .. " active")
- end
- rednet.broadcast(floornum .. " 6")
- if floornum > floor6 then
- up()
- end
- if floornum < floor6 then
- down()
- end
- --button7
- elseif mouseWidth > 0 and mouseWidth < 18 and mouseHeight == 14 then
- local floor7=7
- if floornum == 7 then
- print("You are here")
- rednet.broadcast(floornum .. " active")
- end
- rednet.broadcast(floornum .. " 7")
- if floornum > floor7 then
- up()
- end
- if floornum < floor7 then
- down()
- end
- --button8
- elseif mouseWidth > 0 and mouseWidth < 18 and mouseHeight == 16 then
- local floor8=8
- if floornum == 8 then
- print("You are here")
- rednet.broadcast(floornum .. " active")
- end
- rednet.broadcast(floornum .. " 8")
- if floornum > floor8 then
- up()
- end
- if floornum < floor8 then
- down()
- end
- --button9
- elseif mouseWidth > 0 and mouseWidth < 18 and mouseHeight == 18 then
- local floor9=9
- if floornum == 9 then
- print("You are here")
- rednet.broadcast(floornum .. " active")
- end
- rednet.broadcast(floornum .. " 9")
- if floornum > floor9 then
- up()
- end
- if floornum < floor9 then
- down()
- end
- end --endif
- end --end function
- function clickevent()
- if event=="monitor_touch" then
- mouseWidth = p2 -- sets mouseWidth
- mouseHeight = p3 -- and mouseHeight
- print("click at "..mouseWidth .. " X " ..mouseHeight)
- checkClickPosition() -- this runs our function
- end
- end
- function main()
- repeat
- drawfloors()
- event,p1,p2,p3 = os.pullEvent()
- parallel.waitForAny(clickevent)
- if event == "rednet_message" then
- print(p2)
- if p2 == "1 active" then
- floor1available=1
- end
- if p2 == "2 active" then
- floor2available=1
- end
- if p2 == "3 active" then
- floor3available=1
- end
- if p2 == "4 active" then
- floor4available=1
- end
- if p2 == "5 active" then
- floor5available=1
- end
- if p2 == "6 active" then
- floor6available=1
- end
- if p2 == "7 active" then
- floor7available=1
- end
- if p2 == "8 active" then
- floor8available=1
- end
- if p2 == "9 active" then
- floor9available=1
- end
- if p2 ~= "1 active" then
- if p2 ~= "2 active" then
- if p2 ~= "3 active" then
- if p2 ~= "4 active" then
- if p2 ~= "5 active" then
- if p2 ~= "6 active" then
- if p2 ~= "7 active" then
- if p2 ~= "8 active" then
- if p2 ~= "9 active" then
- --this splits to and from floor messages
- local fromfloor
- local tofloor
- --parses out message
- local tWords = {}
- for match in string.gmatch(p2, "[^ t]+") do
- table.insert( tWords, match )
- end
- --assigns to variables
- fromfloor=tWords[1]
- tofloor=tWords[2]
- print(fromfloor.. " to floor " .. tofloor)
- if tonumber(floornum) ~= tonumber(fromfloor) and tonumber(floornum) ~= tonumber(tofloor) then
- print("from floor")
- thru()
- end
- if tonumber(floornum) ~= tonumber(tofloor) and tonumber(floornum) ~= tonumber(fromfloor) then
- print("to floor")
- thru()
- end
- end
- end
- end
- end
- end
- end
- end
- end
- end
- end --end if for rednetmessages
- until event=="char" and p1==("x")
- end
- --start program
- main()
Advertisement
Add Comment
Please, Sign In to add comment