Advertisement
MrSliff

Reactor remote control client fissionreactor

Jan 19th, 2025 (edited)
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.62 KB | Gaming | 0 0
  1. reactor = "fissionReactorLogicAdapter_0"
  2. state_fissionreactor_channel = 2
  3. control_channel = 3
  4.  
  5. debug = true
  6.  
  7. states = {
  8.     ["FissionReactor"] = {
  9.         ["state"] = false,
  10.         ["temperature"] = 0,
  11.         ["damage"]= 0,
  12.         ["coolant"]= 0,
  13.         ["fuel"]= 0,
  14.         ["waste"]= 0,
  15.         },
  16. }
  17.  
  18. control_reactors = {
  19.     ["BigReactor"] = false,
  20.     ["FissionReactor"] = false
  21. }
  22.  
  23. modem_reactor = peripheral.wrap("back")
  24. modem_wireless = peripheral.wrap("top")
  25. modem_wireless.open(control_channel)
  26.  
  27.  
  28.  
  29.  
  30. states["FissionReactor"]["state"] = modem_reactor.callRemote(reactor, "getStatus")
  31. print("Reactor state: ", states["FissionReactor"]["state"])
  32.    
  33. -- Send states to server
  34. -- print(("Sending to server: "), states)
  35. modem_wireless.transmit(state_fissionreactor_channel, 65535, states)  
  36.  
  37. local function handleMessages()
  38.     -- Receive control commands and handle reactor
  39.     local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
  40.     control_reactors = message
  41.     if debug == true then
  42.         print("Received control message")
  43.         print("FissionReactor: ", control_reactors["FissionReactor"])
  44.     end
  45. end
  46.  
  47. local function handleProgram()
  48.     states["FissionReactor"]["state"] = modem_reactor.callRemote(reactor, "getStatus")
  49.     states["FissionReactor"]["temperature"] = modem_reactor.callRemote(reactor, "getTemperature")
  50.     states["FissionReactor"]["damage"] = modem_reactor.callRemote(reactor, "getDamagePercent")
  51.     states["FissionReactor"]["coolant"] = modem_reactor.callRemote(reactor, "getCoolantFilledPercentage")
  52.     states["FissionReactor"]["fuel"] = modem_reactor.callRemote(reactor, "getFuelFilledPercentage")
  53.     states["FissionReactor"]["waste"] = modem_reactor.callRemote(reactor, "getWasteFilledPercentage")
  54.    
  55.     if debug == true then
  56.         print("Reactor state: ", states["FissionReactor"]["state"])
  57.     end
  58.    
  59.     -- Send states to server
  60.     -- print(("Sending to server: "), states)
  61.     modem_wireless.transmit(state_fissionreactor_channel, 65533, states)  
  62.     sleep(1)
  63.    
  64.     if control_reactors["FissionReactor"] == true then
  65.         if modem_reactor.callRemote(reactor, "getStatus") == false then
  66.             print("Turning on Reactor.")
  67.             modem_reactor.callRemote(reactor, "activate")
  68.         end
  69.     elseif control_reactors["FissionReactor"] == false then
  70.         if modem_reactor.callRemote(reactor, "getStatus") == true then
  71.             print("Turning off Reactor.")
  72.             modem_reactor.callRemote(reactor, "scram")
  73.         end
  74.     end
  75. end
  76.  
  77. ---------------------------------------------------------------------------------------
  78. while true do
  79.    
  80.     parallel.waitForAny(handleProgram,handleMessages)
  81.    
  82. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement