SHOW:
|
|
- or go back to the newest paste.
| 1 | - | --[[ |
| 1 | + | local basenet;do local function b()local c,d=http.get"https://pastebin.com/raw/QnFKq9pE"if not c then return false,d end;local e=c.readAll()local f,d=load(e)if not f then return false,d end;return pcall(f)end;for g=0,8 do local h,i=b()if not h then printError(i)sleep(math.pow(2,g))else basenet=i;break end end end |
| 2 | - | local basenet |
| 2 | + | |
| 3 | - | local function try() |
| 3 | + | local low_threshold = settings.get "basenet.low_threshold" or 0.75 |
| 4 | - | local h, e = http.get "https://pastebin.com/raw/QnFKq9pE" |
| 4 | + | local cell = peripheral.wrap(settings.get "basenet.cell" or error "cell name required") |
| 5 | - | if not h then return false, e end |
| 5 | + | |
| 6 | - | local x = h.readAll() |
| 6 | + | local delay = 0.2 |
| 7 | - | local f, e = load(x) |
| 7 | + | local delay_ticks = delay / 0.05 |
| 8 | - | if not f then return false, e end |
| 8 | + | local last |
| 9 | - | return pcall(f) |
| 9 | + | basenet.interval(function() |
| 10 | - | end |
| 10 | + | local energy = cell.getEnergyStored() |
| 11 | - | for i = 0, 8 do |
| 11 | + | local diff |
| 12 | - | local ok, res = try() |
| 12 | + | if cell.getAverageChangePerTick then |
| 13 | - | if not ok then printError(res) sleep(math.pow(2, i)) |
| 13 | + | diff = cell.getAverageChangePerTick() |
| 14 | - | else basenet = res break end |
| 14 | + | else |
| 15 | - | end |
| 15 | + | if last then |
| 16 | - | ]] |
| 16 | + | diff = (energy - last) / delay_ticks |
| 17 | end | |
| 18 | - | local basenet;do local function b()local c,d=http.get"https://pastebin.com/raw/QnFKq9pE"if not c then return false,d end;local e=c.readAll()local f,d=load(e)if not f then return false,d end;return pcall(f)end;for g=0,8 do local h,i=b()if not h then printError(i)sleep(math.pow(2,g))else basenet=i;break end end end |
| 18 | + | last = energy |
| 19 | end | |
| 20 | local level = energy / (cell.getMaxEnergyStored or cell.getEnergyCapacity)() | |
| 21 | print("IO", diff, "LEVEL", level, "ENERGY", energy)
| |
| 22 | basenet.update { level = level, io = diff, low = level < low_threshold }
| |
| 23 | end, delay) | |
| 24 | ||
| 25 | basenet.run() |