Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- AirLock Control - Main PC (Touchscreen)
- version 1.1
- pastebin: F1zKxNT5
- ]]
- -- all IDs
- local screen1 = 14
- local screen2 = 12
- local door1 = 17
- local door2 = 18
- local screenMain = 15
- local dispenser = 19
- -- rednet messages
- local msgactivate = "activate"
- local msgopen = "open"
- local msgclose = "close"
- local msginuse = "inuse"
- local msgdone = "done"
- local msgreset = "reset"
- local msgdis = "dispense"
- -- switching variables
- local screenIn
- local screenOut
- local doorIn
- local doorOut
- local option
- -- setup
- rednet.open("back")
- term.setCursorBlink(false)
- -- screen write functions
- -- show waiting screen
- function screenwait()
- term.setBackgroundColor(colors.pink)
- term.clear()
- term.setTextColor(colors.black)
- term.setCursorPos(1,3)
- write("WAITING")
- term.setTextColor(colors.white)
- term.setCursorPos(2,5)
- write("open")
- term.setCursorPos(1,1)
- end
- -- show close button
- function screenclose()
- term.setBackgroundColor(colors.red)
- term.clear()
- term.setTextColor(colors.white)
- term.setCursorPos(2,3)
- write("CLOSE")
- term.setCursorPos(1,1)
- end
- -- indicator closing
- function indclose()
- term.setBackgroundColor(colors.red)
- term.setTextColor(colors.white)
- term.setCursorPos(1,5)
- write("closing")
- term.setCursorPos(1,1)
- end
- -- show heal button
- function screenheal()
- term.setBackgroundColor(colors.cyan)
- term.clear()
- term.setTextColor(colors.black)
- term.setCursorPos(2,2)
- write("HEAL?")
- term.setBackgroundColor(colors.green)
- term.setTextColor(colors.white)
- paintutils.drawFilledBox(1,4,3,5)
- term.setCursorPos(2,5)
- write("Y")
- term.setBackgroundColor(colors.red)
- paintutils.drawFilledBox(5,4,7,5)
- term.setCursorPos(6,5)
- write("N")
- term.setCursorPos(1,1)
- end
- -- indicator healing
- function indheal()
- term.setBackgroundColor(colors.cyan)
- term.clear()
- term.setTextColor(colors.black)
- term.setCursorPos(1,3)
- write("HEALING")
- term.setCursorPos(1,1)
- end
- -- show door choice
- function screendoors()
- term.setBackgroundColor(colors.brown)
- term.clear()
- term.setTextColor(colors.white)
- term.setCursorPos(2,1)
- write("WHICH")
- term.setCursorPos(2,2)
- write("DOOR?")
- term.setBackgroundColor(colors.lightGray)
- term.setTextColor(colors.black)
- paintutils.drawFilledBox(1,4,3,5)
- paintutils.drawFilledBox(5,4,7,5)
- term.setCursorPos(2,4)
- write("<")
- term.setCursorPos(6,4)
- write(">")
- term.setCursorPos(1,1)
- end
- -- show open button
- function screenopen()
- term.setBackgroundColor(colors.green)
- term.clear()
- term.setTextColor(colors.white)
- term.setCursorPos(2,3)
- write("OPEN")
- term.setCursorPos(1,1)
- end
- -- indicator opening
- function indopen()
- term.setBackgroundColor(colors.green)
- term.setTextColor(colors.white)
- term.setCursorPos(1,5)
- write("opening")
- term.setCursorPos(1,1)
- end
- -- clear screen
- function screenclear()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- end
- -- parallel functions
- -- touchscreen input
- function waitTouch()
- while true do
- local event, par, x, y = os.pullEvent()
- if event == "mouse_click" then
- if y>=1 and y<=5 then
- option = "touch"
- break
- end
- end
- end
- end
- -- rednet input
- function waitRednet()
- while true do
- local senderid, message = rednet.receive()
- if message == msgactivate then
- option = "rednet"
- if senderid == screen1 then
- screenIn = screen1
- screenOut = screen2
- doorIn = door1
- doorOut = door2
- elseif senderid == screen2 then
- screenIn = screen2
- screenOut = screen1
- doorIn = door2
- doorOut = door1
- end
- break
- end
- end
- end
- -- main program
- while true do
- screenclear()
- sleep(0.1)
- screenwait()
- parallel.waitForAny(waitTouch,waitRednet)
- if option == "touch" then
- -- open door options
- rednet.send(12,msginuse)
- sleep(0.1)
- rednet.send(14,msginuse)
- sleep(0.1)
- screendoors()
- while true do
- local event2, par2, x2, y2 = os.pullEvent()
- if event2 == "mouse_click" then
- if x2>=1 and x2<=3 and y2>=4 and y2<=5 then
- -- left door (1)
- rednet.send(17,msgopen)
- sleep(0.1)
- rednet.send(14,msgdone)
- sleep(0.1)
- break
- elseif x2>=5 and x2<=7 and y2>=4 and y2<=5 then
- -- right door (2)
- rednet.send(18,msgopen)
- sleep(0.1)
- rednet.send(12,msgdone)
- sleep(0.1)
- break
- end
- end
- end
- elseif option == "rednet" then
- -- start airlock
- if screenOut == 14 then
- rednet.send(14,msginuse)
- elseif screenOut == 12 then
- rednet.send(12,msginuse)
- end
- sleep(0.1)
- screenclose()
- while true do
- local event3, par3, x3, y3 = os.pullEvent()
- if event3 == "mouse_click" then
- if y3>=1 and y3<=5 then
- indclose()
- if doorIn == 17 then
- rednet.send(17,msgclose)
- elseif doorIn == 18 then
- rednet.send(18,msgclose)
- end
- sleep(0.1)
- if screenIn == 14 then
- rednet.send(14,msginuse)
- elseif screenIn == 12 then
- rednet.send(12,msginuse)
- end
- sleep(0.1)
- break
- end
- end
- end
- screenheal()
- while true do
- local event4, par4, x4, y4 = os.pullEvent()
- if event4 == "mouse_click" then
- if x4>=1 and x4<=3 and y4>=4 and y4<=5 then
- -- heal
- indheal()
- rednet.send(19,msgdis)
- sleep(0.1)
- break
- elseif x4>=5 and x4<=7 and y4>=4 and y4<=5 then
- -- don't heal
- break
- end
- end
- end
- screenopen()
- while true do
- local event5, par5, x5, y5 = os.pullEvent()
- if event5 == "mouse_click" then
- if y5>=1 and y5<=5 then
- indopen()
- if doorOut == 17 then
- rednet.send(17,msgopen)
- elseif doorOut == 18 then
- rednet.send(18,msgopen)
- end
- sleep(0.1)
- if screenOut == 14 then
- rednet.send(14,msgdone)
- elseif screenOut == 12 then
- rednet.send(12,msgdone)
- end
- sleep(0.1)
- break
- end
- end
- end
- else
- error("fbM-l.251: invalid option")
- end
- sleep(0.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement