Suppenbiatch

Laser New

Jun 22nd, 2019
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.75 KB | None | 0 0
  1. function formateNumber(n) --http://richard.warburton.it
  2.     n = string.format("%.f", tostring(n))
  3.     local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$');
  4.     return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right;
  5. end
  6.  
  7. function round(num, idp)
  8.   local mult = 10^(idp or 0);
  9.   return math.floor(num * mult + 0.5) / mult;
  10. end
  11.  
  12. local lasers = {}
  13. local gates = {}
  14. local monitor = peripheral.wrap("monitor_0")
  15.  
  16. local i = 1
  17. local n = 1
  18. local LaserEnergy = 0
  19. local w, h = monitor.getSize()
  20.  
  21.  
  22. for i = 0, 5, 1 do
  23.     lasers[i] = peripheral.wrap("Laser Amplifier_" .. i)
  24. end
  25.  
  26. for i = 0, 5, 1 do
  27.     gates[i] = peripheral.wrap("flux_gate_" .. i)
  28.    
  29. end
  30.  
  31. for i = 0, 5, 1 do
  32.     gates[i].setOverrideEnabled(true)
  33. end
  34.  
  35. monitor.clear()
  36. monitor.setTextScale(.5)
  37.  
  38. while true do
  39.  
  40.     i = 0
  41.     n = 1
  42.     for _ in pairs(lasers) do
  43.         LaserEnergy = lasers[i].getEnergy()/2.5
  44.        
  45.         if LaserEnergy > 1600000000 then
  46.             gates[i].setFlowOverride(0)
  47.         else
  48.             gates[i].setFlowOverride(256000)
  49.         end
  50.        
  51.         monitor.setCursorPos(2,n)
  52.         monitor.setTextColor(colors.lime)
  53.         monitor.write("Laser " .. i+1 .. " charged with " .. formateNumber(LaserEnergy).. " RF")
  54.         monitor.setCursorPos(2,n+1)
  55.         monitor.write("Laser " .. i+1 .. " is " .. round((LaserEnergy/800000000)*100, 4) .. " % charged for one blast")
  56.         if LaserEnergy > 800000000 then
  57.             monitor.setCursorPos(2,n+3)
  58.             monitor.clearLine()
  59.             monitor.setTextColor(colors.lime)
  60.             monitor.write("Laser Impuls is ready.")
  61.         else
  62.             monitor.setCursorPos(2,n+3)
  63.             monitor.clearLine()
  64.             monitor.setTextColor(colors.red)
  65.             monitor.write("Laser Impuls is NOT ready.")
  66.         end
  67.        
  68.         i = i + 1
  69.         n = n + 6
  70.     end
  71.     sleep(0.2)
  72. end
Add Comment
Please, Sign In to add comment