Tommo5261

getReactorCoreData

Nov 10th, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.40 KB | None | 0 0
  1. scanner = peripheral.wrap("top")
  2. meta = scanner.getBlockMeta(0, -1, -2)
  3. rednet.open("back")
  4. reactorString = textutils.serialise(meta)
  5.  
  6. function getReactorHeat()
  7.     ha = string.find(reactorString, "heat = %d", plain)
  8.     hb = ha + 12
  9.     hc = ha + 6
  10.  
  11.     hd = string.sub(reactorString, hc, hb)
  12.     he = string.gsub(hd, "[^%d]", "")
  13.     hf = tonumber(he)
  14.     return hf
  15. end
  16.  
  17. function getEUOutput()
  18.     ea = string.find(reactorString, "euOutput = %d", plain)
  19.     eb = ea + 16
  20.     ec = ea + 10
  21.  
  22.     ed = string.sub(reactorString, ec, eb)
  23.     ee = string.gsub(ed, "[^%d]", "")
  24.     ef = tonumber(ee)
  25.     return ef
  26. end
  27.  
  28. function getStatus()
  29.     sa = string.find(reactorString, "active =", plain)
  30.     sb = sa + 14
  31.     sc = sa + 8
  32.  
  33.     sd = string.sub(reactorString, sc, sb)
  34.     se = string.match(sd, "true")
  35.     se2 = string.match(sd, "false")
  36.  
  37.     if se == "true" then
  38.         return true
  39.     elseif se2 == "false" then
  40.         return false
  41.     else
  42.         return error("Reactor did not provide status")
  43.     end
  44. end
  45.  
  46.  
  47. while true do
  48.     meta = scanner.getBlockMeta(0, -1, -2)
  49.     reactorString = textutils.serialise(meta)
  50.     reactorTable = {getReactorHeat(), getEUOutput(), getStatus()}
  51.     reactorData = textutils.serialise(reactorTable)
  52.  
  53.     id,message = rednet.receive()
  54.     sleep(0.1)
  55.     if id == 37 and message == "send.data" then
  56.         rednet.send(37,reactorData)
  57.     end
  58. end
Add Comment
Please, Sign In to add comment