Tooki

PCS_Remote

Mar 22nd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.41 KB | None | 0 0
  1. DoorStatut = "Close"
  2. CacheStatut = "Close"
  3.  
  4. local modem = peripheral.wrap("top")
  5. local screenR = peripheral.wrap("right")
  6. local screenL = peripheral.wrap("left")
  7. screenR.setTextScale(0.5)
  8.  
  9. local r1_status = "off"
  10. local r2_status = "off"
  11.  
  12. modem.open(21)
  13.  
  14. function rsOn(VarColor)
  15.   rs.setBundledOutput("back",colors.combine(rs.getBundledOutput("back"),VarColor))
  16. end
  17. function rsOff(VarColor)
  18.   redstone.setBundledOutput("back",colors.subtract(rs.getBundledOutput("back"), VarColor))
  19. end
  20.  
  21. function OpenCache(RC)
  22.     Type = GetType(RC)
  23.     if Type == "ToOpen" then
  24.             rsOff(colors.pink)
  25.             CacheStatut = "Open"
  26.         elseif Type == "ToClose" then
  27.             rsOn(colors.pink)
  28.             CacheStatut = "Close"
  29.         elseif Type == "GetInfo" then
  30.             modem.transmit(RC, 21, CacheStatut)
  31.         end
  32. end
  33. function OpenDoor(RC)
  34.     Type = GetType(RC)
  35.     if Type == "ToOpen" then
  36.             DoorStatut = "Open"
  37.             sleep(1)
  38.             rsOff(colors.lightBlue)
  39.         elseif Type == "ToClose" then
  40.             DoorStatut = "Close"
  41.             sleep(1)
  42.             rsOn(colors.lightBlue)
  43.         elseif Type == "GetInfo" then
  44.             modem.transmit(RC, 21, DoorStatut)
  45.         end
  46. end
  47. function Reactor(Infos, RID)
  48.     RequestType = string.sub(Infos, 1, 1)
  49.     Request = string.sub(Infos, 3, __)
  50.  
  51.     if RequestType == "1" then
  52.         if RID == 1 then r1_status = Request
  53.         elseif RID == 2 then r2_status = Request end
  54.     elseif RequestType == "2" then
  55.     end
  56.     screenR.clear()
  57.     gui = {
  58.       [[+-------------+]],
  59.       [[|Reacteur 1 : |]],
  60.       [[| Status : ]]..r1_status..[[|]],
  61.       [[+-------------+]],
  62.       [[|Reacteur 2 : |]],
  63.       [[| Status : ]]..r2_status..[[|]],
  64.       [[+-------------+]],
  65.       [[|             |]],
  66.       [[|             |]],
  67.       [[+-------------+]],
  68.     }
  69.     for i = 1,10 do
  70.     screenR.setCursorPos(1, i)
  71.     screenR.write(gui[i])
  72.     end
  73.    
  74. end
  75. function GetType(RC)
  76.     if RC == 1 then
  77.         Type = "ToOpen"
  78.     elseif RC == 2 then
  79.         Type = "ToClose"
  80.     elseif RC == 3 then
  81.         Type = "GetInfo"
  82.     end
  83.     return Type
  84. end
  85. function Init()
  86.     rsOn(colors.pink)
  87.     rsOn(colors.lightBlue)
  88.     Lunch()
  89. end
  90. function Lunch()
  91.     while true do
  92.         local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  93.  
  94.         if message == "" then
  95.             elseif message == "OpenCache" then OpenCache(replyChannel)
  96.             elseif message == "OpenDoor" then OpenDoor(replyChannel)
  97.             elseif (string.sub(message, 1, 14) == "Reactor-Statut") then Reactor(string.sub(message, 16, __), replyChannel)
  98.         end
  99.     end
  100. end
  101.  
  102. Init()
Add Comment
Please, Sign In to add comment