Advertisement
Guest User

test.lua

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