Advertisement
NeonJ

RedstoneCONTROL - Client PC [WIP]

Jan 15th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.89 KB | None | 0 0
  1. --[[
  2.  
  3. RedstoneControl - Client PC
  4.  
  5. The client PCs connect to the main PCs and collect information from them.
  6. They also possess Advanced Monitors, so players can use them without opening a GUI
  7.  
  8. 0 1234567
  9.  +-------+
  10. 1|  4F   |
  11. 2|  3F   |
  12. 3|  2F   |
  13. 4|  1F   |
  14. 5|  B1F  |
  15.  +-------+
  16.  
  17. PING is given by the server, and updates the clock.
  18. Lift Control is handled by Advanced Monitors, player just clicks the floor he wants the lift to go to.
  19. Lift location is handled by messages recieved from ServerPC.
  20.  
  21. --]]
  22.  
  23. -- * * * VARIABLES * * *
  24.  
  25. monSide = "right"
  26. rednetSide = "top"
  27. outputSide = "bottom"
  28. inputSide = "left"
  29.  
  30. liftPos = 0
  31.  
  32. PCPos = "B1F"
  33.  
  34. -- * * * CODE * * *
  35.  
  36. mon = peripheral.wrap(monSide)
  37. rednet.open(rednetSide)
  38.  
  39. mon.setCursorPos(1,1)   mon.write(" 4F    ")
  40. mon.setCursorPos(1,2)   mon.write(" 3F    ")
  41. mon.setCursorPos(1,3)   mon.write(" 2F    ")
  42. mon.setCursorPos(1,4)   mon.write(" 1F    ")
  43. mon.setCursorPos(1,5)   mon.write(" B1F   ")
  44.  
  45. function updateScreen()
  46.   mon.setCursorPos(1,1)
  47.   if liftPos == 4 then mon.setBackgroundColor(colors.green) else mon.setBackgroundColor(colors.black) end
  48.   mon.write("  4F   ")
  49.   mon.setCursorPos(1,2)
  50.   if liftPos == 3 then mon.setBackgroundColor(colors.green) else mon.setBackgroundColor(colors.black) end
  51.   mon.write("  3F   ")
  52.   mon.setCursorPos(1,3)
  53.   if liftPos == 2 then mon.setBackgroundColor(colors.green) else mon.setBackgroundColor(colors.black) end
  54.   mon.write("  2F   ")
  55.   mon.setCursorPos(1,4)
  56.   if liftPos == 1 then mon.setBackgroundColor(colors.green) else mon.setBackgroundColor(colors.black) end
  57.   mon.write("  1F   ")
  58.   mon.setCursorPos(1,5)
  59.   if liftPos == 0 then mon.setBackgroundColor(colors.green) else mon.setBackgroundColor(colors.black) end
  60.   mon.write("  B1F   ")
  61. end
  62.  
  63. rednet.broadcast("[RedCTRL] sendMeLift !")
  64. updateScreen()
  65.  
  66. while true do
  67.   local events = {os.pullEvent()}
  68.   if events[1] == "rednet_message" then
  69.     if events[3] == "[RedCTRL] liftMoved B1F !" then
  70.       liftPos = 0
  71.       if PCPos == "B1F" then
  72.         rs.setOutput(outputSide, true)
  73.       else
  74.         rs.setOutput(outputSide, false)
  75.       end
  76.       updateScreen()
  77.     elseif events[3] == "[RedCTRL] liftMoved 1F !" then
  78.       liftPos = 1
  79.       if PCPos == "1F" then
  80.         rs.setOutput(outputSide, true)
  81.       else
  82.         rs.setOutput(outputSide, false)
  83.       end
  84.       updateScreen()
  85.     elseif events[3] == "[RedCTRL] liftMoved 2F !" then
  86.       liftPos = 2
  87.       if PCPos == "2F" then
  88.         rs.setOutput(outputSide, true)
  89.       else
  90.         rs.setOutput(outputSide, false)
  91.       end
  92.       updateScreen()
  93.     elseif events[3] == "[RedCTRL] liftMoved 3F !" then
  94.       liftPos = 3
  95.       if PCPos == "3F" then
  96.         rs.setOutput(outputSide, true)
  97.       else
  98.         rs.setOutput(outputSide, false)
  99.       end
  100.       updateScreen()
  101.     elseif events[3] == "[RedCTRL] liftMoved 4F !" then
  102.       liftPos = 4
  103.       if PCPos == "4F" then
  104.         rs.setOutput(outputSide, true)
  105.       else
  106.         rs.setOutput(outputSide, false)
  107.       end
  108.       updateScreen()
  109.     elseif events[3] == "[RedCTRL] liftMoving !" then
  110.       liftPos = -1
  111.       rs.setOutput(outputSide, false)
  112.       updateScreen()
  113.     end
  114.   elseif events[1] == "monitor_touch" then -- Refer to Digilock for reference.
  115.     if events[4] == 1 then
  116.       rednet.broadcast("[RedCTRL] moveLift 4F !")
  117.     elseif events[4] == 2 then
  118.       rednet.broadcast("[RedCTRL] moveLift 3F !")
  119.     elseif events[4] == 3 then
  120.       rednet.broadcast("[RedCTRL] moveLift 2F !")
  121.     elseif events[4] == 4 then
  122.       rednet.broadcast("[RedCTRL] moveLift 1F !")
  123.     elseif events[4] == 5 then
  124.       rednet.broadcast("[RedCTRL] moveLift B1F !")
  125.     end
  126.   elseif events[1] == "redstone" then
  127.     if rs.getInput(inputSide) == true then
  128.       rednet.broadcast("[RedCTRL] moveLift "..PCPos.." !")  -- Make the computer recall the lift if button pressed on inputSide.
  129.     end
  130.   end
  131. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement