Advertisement
Guest User

test.lua

a guest
Oct 19th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.55 KB | None | 0 0
  1. local c = require("component")
  2. local e = require("event")
  3. local t = require("term")
  4. local com = c.computer
  5. local m = c.modem
  6. local gpu = c.gpu
  7. local port = 123
  8. local w, h = gpu.getResolution()
  9.  
  10. m.open(port)
  11. function msg(_, _,adr, _, _, message)
  12.   if message == "off" then
  13.     running = false
  14.     event.ignore("modem_message", msg)
  15.     m.send(adr,port,"Reactor control offline!")
  16.     com.beep(1200,0.1)
  17.     term.clear()
  18.     os.exit()
  19.   end
  20. end
  21. event.listen("modem_message", msg)
  22. running = true
  23.  
  24. if component.isAvailable("br_reactor") then
  25.   while running == true do
  26.  
  27.     t.clear()
  28.     local r = c.br_reactor
  29.     local power = r.getEnergyStored()
  30.     local powerP = power / 10000000 * 100
  31.     local fuel = r.getFuelAmount()
  32.     local fuelMax = r.getFuelAmountMax()
  33.     local fuelP = fuel / fuelMax *100
  34.     local status = "status :"
  35.  
  36.     if powerP >= 90 then
  37.       r.setActive(false)
  38.       status = status.."Power levels OK!"
  39.     elseif powerP <= 10 then
  40.       r.setActive(true)
  41.       status = status.."Power levels LOW"
  42.     end
  43.  
  44.     if fuelP <= 5 then
  45.       status = status.." | Fuel levels CRITICAL"
  46.     elseif fuelP <= 20 then
  47.       status = status.." | Fuel levels LOW"
  48.     elseif fuelP > 20 then
  49.       status = status.." | Fuel levels OK!"
  50.     end
  51.  
  52.     gpu.set(w/2 - (string.len(status) /2 ),h/2,status)
  53.     gpu.set(w/2 - 2, h/2+1, "Energy: "..math.floor(powerP).."%")
  54.     gpu.set(w/2 - 2, h/2+2, "Fuel: "..math.floor(fuelP).."%")
  55.  
  56.     os.sleep(3)
  57.  
  58.   end
  59. else
  60.  
  61.   t.clear()
  62.   local message = "[NO REACTOR CONNECTED]"
  63.   gpu.set(w/2 - (string.len(message) /2 ),h/2,message)
  64.   os.exit()
  65.  
  66. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement