Advertisement
taoshi

nuccontrol.lua

Sep 9th, 2022 (edited)
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.31 KB | Source Code | 0 0
  1. --написано Zardar (dc Taoshi)-------
  2. local max_rod_depth = 10 --максимальная глубина стержней
  3. local eu_low = 2.0e9 --цифра перед е = к-во энергии в лярдах
  4. local eu_high = 6.0e9
  5. local pause = 0.4 -- длина паузы
  6. ---------------------------------------
  7. local computer = require('computer')
  8. local component = require('component')
  9. local fs = require('filesystem')
  10. local unicode = require('unicode')
  11. local gpu = require('component').gpu
  12. local term = require('term')
  13. local os = require('os')
  14. local pullSignal = computer.pullSignal
  15.  
  16. local events = {component_removed='removed',
  17.     component_added='added'
  18.     --touch='touch',
  19.     --drag='touch',
  20.     --drop='touch',
  21.     --key_up='keyUp'
  22. }
  23. local iter,tps = 0, 0
  24. local current_rods_lvl = max_rod_depth
  25. local eu_in, eu_out, ener, tps = '','','',''
  26. local time = computer.uptime()
  27. local t = time
  28. local actions,reactor = {},{}
  29. local lapotronka=require('component').impact_lsc
  30. for f in pairs(component.list('impact_reactor'))
  31.   do reactor[#reactor+1]=component.proxy(f) end
  32. -------------------------------------
  33. local function rods(n)
  34.     for f in pairs (reactor) do
  35.         reactor[f].setLevelRods(n)
  36.     end
  37.    
  38.   return true
  39. end
  40.  
  41. -------------------------------------
  42. local function time()
  43.   local f=io.open('/tmp/f','w')
  44.   f:write('how are you doing?')
  45.   f:close()
  46.   return(fs.lastModified('/tmp/f'))
  47. end
  48.  
  49. local function digital(n)
  50.   local text=''
  51.   for f in string.gmatch(n,'%d') do text=text..f end
  52.   return text
  53. end
  54. --------------------------------------
  55. --function computer.pullSignal(...)
  56.     --local e = {pullSignal(...)}
  57.     --    if events[e[1]] then
  58.        --     return actions[events[e[1]]](e)
  59.     --    end
  60.   --  return true --table.unpack(e)
  61. --end
  62. -------------------------------------------
  63. events.component_removed=function(e)
  64.    
  65.  return true
  66. end
  67.  
  68. events.component_added=function(e)
  69.  
  70.   return true
  71. end
  72.  
  73.  
  74.  
  75.  
  76.  
  77. -------------------------------------------
  78. function setRods()
  79.   local info=lapotronka.getSensorInformation()
  80.   local text,eu,eu_in,eu_out='','','',''
  81.   text=digital(info[2])
  82.   eu=tonumber(text)
  83.   eu_in=digital(info[6])
  84.   eu_out=digital(info[8])
  85.   if eu<eu_low then if current_rods_lvl < max_rod_depth then rods(max_rod_depth) current_rods_lvl=max_rod_depth end end-- Если мало то стержни на Макс погружение
  86.   if eu>eu_high then if current_rods_lvl > 1 then rods(1) current_rods_lvl=1 end end-- Если больше то стержни на 10%
  87.   ener=tostring(math.floor(eu/1000000))..'M  '
  88.   gpu.fill(3,2,27,9,' ')
  89.  
  90.   gpu.set(4,7,'ХРАНИТСЯ:')
  91.   gpu.set(16,7,ener)
  92.   gpu.set(4,9,'EU IN:')
  93.   gpu.set(16,9,eu_in)
  94.   gpu.set(4,11,'EU OUT:')
  95.   gpu.set(16,11,eu_out)
  96.   gpu.set(4,5,'ПОГРУЖЕНИЕ:')
  97.   gpu.set(16,5,tostring(current_rods_lvl)..'0%')
  98.   gpu.set(4,3,"TPS: "..tostring(tps))
  99.  end
  100.  
  101.  
  102. -----------------------------
  103. term.clear()
  104. gpu.setBackground(0x333333)
  105. gpu.setForeground(0x11ee11)
  106. --gpu.fill(1,1,33,11,' ')
  107. while true do setRods()
  108.  
  109.  
  110.  
  111. iter=iter+1
  112. if iter == 5 then inner=time() end
  113. os.sleep(pause)
  114. if iter == 5 then outer=time() end
  115. if iter == 5 then tps = string.sub(20000 * pause / (outer - inner),1,5) end
  116. if iter == 5 then iter = 0 end
  117. end
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement