Advertisement
MrSliff

Reactor remote control server

Jan 19th, 2025 (edited)
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.46 KB | Gaming | 0 0
  1. monitor = peripheral.wrap("monitor_1")
  2. state_home_channel = 1
  3. state_fissionreactor_channel = 2
  4. control_channel = 3
  5.  
  6. control_reactors = {
  7.     ["BigReactor"] = false,
  8.     ["FissionReactor"] = false
  9. }
  10.  
  11. home_states = {
  12.     ["BigReactor"] = {
  13.         ["state"] = false
  14.         },
  15.     ["Capacitor"] = {
  16.         ["charge"] = 0
  17.         },  
  18. }
  19.  
  20. fissionreactor_states = {
  21.     ["FissionReactor"] = {
  22.         ["state"] = false,
  23.         ["temperature"] = 0,
  24.         ["damage"]= 0,
  25.         ["coolant"]= 0,
  26.         ["fuel"]= 0,
  27.         ["waste"]= 0,
  28.         },
  29. }
  30.    
  31.  
  32. modem_wireless = peripheral.wrap("top")
  33.  
  34. monitor.clear()
  35. monitor.setCursorPos(1, 1)
  36. monitor.clearLine()
  37. monitor.setTextColour(colors.orange)   
  38. monitor.write("Reactor Control Server")
  39.  
  40. while true do
  41.  
  42.     -- Get Data from Network
  43.  
  44.     modem_wireless.open(state_home_channel)
  45.     local event, side, channel, replyChannel, home_states, distance = os.pullEvent("modem_message")
  46.  
  47.     charge = home_states["Capacitor"]["charge"]
  48.     print("Capacitor Charge: ", charge)
  49.     BigReactor_state = home_states["BigReactor"]["state"]
  50.     print("BigReactor state: ", BigReactor_state)
  51.  
  52.     modem_wireless.close(state_home_channel)
  53.     modem_wireless.open(state_fissionreactor_channel)
  54.    
  55.     local event, side, channel, replyChannel, fissionreactor_states, distance = os.pullEvent("modem_message")
  56.     FissionReactor_state = fissionreactor_states["FissionReactor"]["state"]
  57.  
  58.     modem_wireless.close(state_fissionreactor_channel)
  59.     ----------------------------------------------
  60.  
  61.     -- Handle Reactors
  62.    
  63.     if charge <= 10 then
  64.         if BigReactor_state == false then
  65.             print("Turning on BigReactor")
  66.             control_reactors["BigReactor"] = true
  67.         end
  68.         if FissionReactor_state == false then
  69.             control_reactors["FissionReactor"] = true
  70.         end
  71.     elseif charge >= 95 then
  72.         if BigReactor_state == true then
  73.             print("Turning off BigReactor")
  74.             control_reactors["BigReactor"] = false
  75.         end
  76.         if FissionReactor_state == true then
  77.             control_reactors["FissionReactor"] = false
  78.         end
  79.     end
  80.  
  81.     modem_wireless.transmit(control_channel, 65534, control_reactors)  
  82.  
  83.     ----------------------------------------------
  84.  
  85.     -- Handle Monitor
  86.     monitor.setCursorPos(1, 2)
  87.     monitor.clearLine()
  88.     print(("Capacitor Charge: %d%%"):format(charge))
  89.     if charge > 70 then
  90.         monitor.setTextColour(colors.green)
  91.     elseif charge < 25 then
  92.         monitor.setTextColour(colors.red)  
  93.     else
  94.         monitor.setTextColour(colors.yellow)   
  95.     end
  96.     monitor.write(("Capacitor Charge: %d%%"):format(charge))
  97.     monitor.setCursorPos(1, 3)
  98.     monitor.clearLine()
  99.     if BigReactor_state == true then
  100.         monitor.setTextColour(colors.green)
  101.         print("Big Reactor: ", BigReactor_state)
  102.         monitor.write("Big Reactor running")
  103.         monitor.setTextColour(colors.white)
  104.     elseif BigReactor_state == false then
  105.         monitor.setTextColour(colors.red)  
  106.         print("Big Reactor: ", BigReactor_state)
  107.         monitor.write("Big Reactor not running")
  108.         monitor.setTextColour(colors.white)
  109.     end
  110.     monitor.setCursorPos(1, 4)
  111.     monitor.clearLine()
  112.     if FissionReactor_state == true then
  113.         monitor.setTextColour(colors.green)
  114.         print("Fission Reactor: ", FissionReactor_state)
  115.         monitor.write("Fission Reactor running")
  116.         monitor.setTextColour(colors.white)
  117.     elseif FissionReactor_state == false then
  118.         monitor.setTextColour(colors.red)  
  119.         print("Fission Reactor: ", FissionReactor_state)
  120.         monitor.write("Fission Reactor not running")
  121.         monitor.setTextColour(colors.white)
  122.     end
  123.     --------------------------------------------
  124.  
  125.     sleep(1)
  126. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement