Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- RedstoneControl - Client PC
- The client PCs connect to the main PCs and collect information from them.
- They also possess Advanced Monitors, so players can use them without opening a GUI
- 0 1234567
- +-------+
- 1| 4F |
- 2| 3F |
- 3| 2F |
- 4| 1F |
- 5| B1F |
- +-------+
- PING is given by the server, and updates the clock.
- Lift Control is handled by Advanced Monitors, player just clicks the floor he wants the lift to go to.
- Lift location is handled by messages recieved from ServerPC.
- --]]
- -- * * * VARIABLES * * *
- monSide = "right"
- rednetSide = "top"
- outputSide = "bottom"
- inputSide = "left"
- liftPos = 0
- PCPos = "B1F"
- -- * * * CODE * * *
- mon = peripheral.wrap(monSide)
- rednet.open(rednetSide)
- mon.setCursorPos(1,1) mon.write(" 4F ")
- mon.setCursorPos(1,2) mon.write(" 3F ")
- mon.setCursorPos(1,3) mon.write(" 2F ")
- mon.setCursorPos(1,4) mon.write(" 1F ")
- mon.setCursorPos(1,5) mon.write(" B1F ")
- function updateScreen()
- mon.setCursorPos(1,1)
- if liftPos == 4 then mon.setBackgroundColor(colors.green) else mon.setBackgroundColor(colors.black) end
- mon.write(" 4F ")
- mon.setCursorPos(1,2)
- if liftPos == 3 then mon.setBackgroundColor(colors.green) else mon.setBackgroundColor(colors.black) end
- mon.write(" 3F ")
- mon.setCursorPos(1,3)
- if liftPos == 2 then mon.setBackgroundColor(colors.green) else mon.setBackgroundColor(colors.black) end
- mon.write(" 2F ")
- mon.setCursorPos(1,4)
- if liftPos == 1 then mon.setBackgroundColor(colors.green) else mon.setBackgroundColor(colors.black) end
- mon.write(" 1F ")
- mon.setCursorPos(1,5)
- if liftPos == 0 then mon.setBackgroundColor(colors.green) else mon.setBackgroundColor(colors.black) end
- mon.write(" B1F ")
- end
- rednet.broadcast("[RedCTRL] sendMeLift !")
- updateScreen()
- while true do
- local events = {os.pullEvent()}
- if events[1] == "rednet_message" then
- if events[3] == "[RedCTRL] liftMoved B1F !" then
- liftPos = 0
- if PCPos == "B1F" then
- rs.setOutput(outputSide, true)
- else
- rs.setOutput(outputSide, false)
- end
- updateScreen()
- elseif events[3] == "[RedCTRL] liftMoved 1F !" then
- liftPos = 1
- if PCPos == "1F" then
- rs.setOutput(outputSide, true)
- else
- rs.setOutput(outputSide, false)
- end
- updateScreen()
- elseif events[3] == "[RedCTRL] liftMoved 2F !" then
- liftPos = 2
- if PCPos == "2F" then
- rs.setOutput(outputSide, true)
- else
- rs.setOutput(outputSide, false)
- end
- updateScreen()
- elseif events[3] == "[RedCTRL] liftMoved 3F !" then
- liftPos = 3
- if PCPos == "3F" then
- rs.setOutput(outputSide, true)
- else
- rs.setOutput(outputSide, false)
- end
- updateScreen()
- elseif events[3] == "[RedCTRL] liftMoved 4F !" then
- liftPos = 4
- if PCPos == "4F" then
- rs.setOutput(outputSide, true)
- else
- rs.setOutput(outputSide, false)
- end
- updateScreen()
- elseif events[3] == "[RedCTRL] liftMoving !" then
- liftPos = -1
- rs.setOutput(outputSide, false)
- updateScreen()
- end
- elseif events[1] == "monitor_touch" then -- Refer to Digilock for reference.
- if events[4] == 1 then
- rednet.broadcast("[RedCTRL] moveLift 4F !")
- elseif events[4] == 2 then
- rednet.broadcast("[RedCTRL] moveLift 3F !")
- elseif events[4] == 3 then
- rednet.broadcast("[RedCTRL] moveLift 2F !")
- elseif events[4] == 4 then
- rednet.broadcast("[RedCTRL] moveLift 1F !")
- elseif events[4] == 5 then
- rednet.broadcast("[RedCTRL] moveLift B1F !")
- end
- elseif events[1] == "redstone" then
- if rs.getInput(inputSide) == true then
- rednet.broadcast("[RedCTRL] moveLift "..PCPos.." !") -- Make the computer recall the lift if button pressed on inputSide.
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement