Advertisement
MrSliff

Reactor remote control client home

Jan 19th, 2025 (edited)
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.24 KB | Gaming | 0 0
  1. reactor = "BigReactors-Reactor_1"
  2. capacitor = "enderio:advanced_capacitor_bank_1"
  3. state_home_channel = 1
  4. control_channel = 3
  5.  
  6. states = {
  7.     ["BigReactor"] = {
  8.         ["state"] = false
  9.         },
  10.     ["Capacitor"] = {
  11.         ["charge"] = 0
  12.         }, 
  13. }
  14.  
  15. control_reactors = {
  16.     ["BigReactor"] = false,
  17.     ["FissionReactor"] = false
  18. }
  19.  
  20. modem_reactor = peripheral.wrap("left")
  21. modem_capacitor = peripheral.wrap("right")
  22. modem_wireless = peripheral.wrap("back")
  23. modem_wireless.open(control_channel)
  24.  
  25. capacity = modem_capacitor.callRemote(capacitor, "getEnergyCapacity")
  26. print("Battery Capacity: ", capacity)
  27.  
  28. states["BigReactor"]["state"] = modem_reactor.callRemote(reactor, "getActive")
  29.     print("Reactor state: ", states["BigReactor"]["state"])
  30.     states["Capacitor"]["charge"] = (modem_capacitor.callRemote(capacitor, "getEnergy")/capacity)*100
  31.     print("Capacitor charge: ", states["Capacitor"]["charge"])
  32.    
  33.     -- Send states to server
  34.     -- print(("Sending to server: "), states)
  35.     modem_wireless.transmit(state_home_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.     print("Received control message")
  42.     print("BigReactor: ", control_reactors["BigReactor"])
  43. end
  44.  
  45. local function handleProgram()
  46.     states["BigReactor"]["state"] = modem_reactor.callRemote(reactor, "getActive")
  47.     print("Reactor state: ", states["BigReactor"]["state"])
  48.     states["Capacitor"]["charge"] = (modem_capacitor.callRemote(capacitor, "getEnergy")/capacity)*100
  49.     print("Capacitor charge: ", states["Capacitor"]["charge"])
  50.    
  51.     -- Send states to server
  52.     -- print(("Sending to server: "), states)
  53.     modem_wireless.transmit(state_home_channel, 65535, states) 
  54.     sleep(1)
  55.    
  56.     if control_reactors["BigReactor"] == true then
  57.         print("Turning on Reactor.")
  58.         modem_reactor.callRemote(reactor, "setActive", true)
  59.     elseif control_reactors["BigReactor"] == false then
  60.         print("Turning off Reactor.")
  61.         modem_reactor.callRemote(reactor, "setActive", false)
  62.     end
  63. end
  64.  
  65. ---------------------------------------------------------------------------------------
  66. while true do
  67.    
  68.     parallel.waitForAny(handleProgram,handleMessages)
  69.    
  70. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement