Advertisement
massacring

EnergyThreshold

May 26th, 2024 (edited)
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.77 KB | None | 0 0
  1. local MPL = require('MassaPeripheralLib')
  2.  
  3. local modem = MPL.getOnePeripheral("modem", function(name, peripheral)
  4.     return peripheral.isWireless()
  5. end)
  6. local channel = 4200
  7. local reciever = 4201
  8. modem.open(channel)
  9.  
  10. function detectEnergyWanted()
  11.     local port = peripheral.find("inductionPort")
  12.     if not port then error("No induction port connected.", 0) end
  13.     if port.getEnergyFilledPercentage() > 0.8 then return false end
  14.     return true
  15. end
  16.  
  17. while true do
  18.     sleep(5)
  19.     local message = ""
  20.     if detectEnergyWanted() then
  21.         message = "activate"
  22.     else
  23.         message = "SCRAM"
  24.     end
  25.     print(string.format("Transmitting '%s' to channel %d, from channel %d", message, reciever, channel))
  26.     modem.transmit(reciever, channel, message)
  27. end
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement