Advertisement
jaypar

WillNameLater

Aug 17th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.96 KB | None | 0 0
  1. react = peripheral.wrap("BigReactors-Reactor")
  2. modem = peripheral.wrap("modem")
  3.  
  4. if not modem.isOpen(1297) then
  5.     modem.open(1297)
  6. end
  7.  
  8.  
  9. function ReactorPower()
  10.     powerMax = react.getEnergyCapacity() * 0.9
  11.     powerMin = react.getEnergyCapacity() * 0.1
  12.     while true do
  13.         power = react.getEnergyStored()
  14.         if power >= powerMax then
  15.             onoff(false)
  16.         end
  17.         if power <= powerMin then
  18.             onoff(true)
  19.         end
  20.         sleep(0.1)
  21.     end
  22. end
  23.  
  24. function ReactorPowerState(onoff)
  25.     react.setActive(onoff)
  26. end
  27.  
  28. function Listen()
  29.     while true do
  30.         local _, _, _, replyChan, m, _ = os.pullEvent("modem_message")
  31.        
  32.         if (string.find(m, string.char(12, 97)) then
  33.             local formattedMessage = string.sub(m, 3)
  34.             print(m .. " turned into " .. formattedMessage)
  35.         else
  36.             Reply("This is not the modem you are looking for!", replyChan)
  37.         end
  38.     end
  39. end
  40.  
  41. function Reply(msg, replyChannel)
  42.     modem.transmit(replyChannel, 1297, msg)
  43. end
  44.  
  45. parallel.waitForAll(ReactorPower, Listen)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement