Advertisement
Punio

ReactorMonitor

Jan 1st, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.87 KB | None | 0 0
  1. rednet.open("back")
  2.  
  3. local fuelID      = 0
  4. local tempID      = 0
  5. local shieldID    = 0
  6. local energyID    = 0
  7.  
  8. local maxShield  = 7
  9. local maxEnergy  = 5
  10.  
  11. --- do not edit after this line ---
  12. local _exit = false
  13.  
  14. --if fuelID <= 0 or tempID <= 0 or shieldID <=0 or energyID <=0 then
  15. --  print("Bitte konfiguriere die Computer ID's")
  16. --   _exit = true
  17. --end
  18.  
  19. local fuel    = 0
  20. local temp    = 0
  21. local shield  = 0
  22. local energy  = 0
  23.  
  24. local monitorLeft  = peripheral.wrap("left")
  25. local monitorRight = peripheral.wrap("right")
  26. local monitorTop   = peripheral.wrap("top")
  27.  
  28. function receive()
  29.    while not _exit do
  30.       ID, msg = rednet.receive()
  31.      
  32.       if ID == tempID then
  33.          temp = msg
  34.       elseif ID == fuelID then
  35.          fuel = msg
  36.       elseif ID == shieldID then
  37.          shield = msg
  38.       elseif ID == energyID then
  39.          energy = msg
  40.       end
  41.       sleep(.1)
  42.    end
  43. end
  44.  
  45. function _print()
  46.    while not _exit do
  47.       monitorTop.clear()
  48.      
  49.       monitorTop.setCursorPos(1,1)
  50.       monitorTop.write("Fuel      : " .. tostring(math.floor((100/15)*fuel)) .. "%")
  51.    
  52.       monitorTop.setCursorPos(1,2)
  53.       monitorTop.write("Temperatur: " .. tostring(math.floor((100/15)*temp)) .. "%")
  54.      
  55.       monitorTop.setCursorPos(1,3)
  56.       monitorTop.write("Shield    : " .. tostring(math.floor((100/15)*shield)) .. "%")
  57.      
  58.       monitorTop.setCursorPos(1,4)
  59.       monitorTop.write("Energy    : " .. tostring(math.floor((100/15)*energy)) .. "%")
  60.    
  61.       monitorTop.setCursorPos(1,5)
  62.       monitorTop.write("-----------------------------")
  63.    
  64.       sleep(.1)
  65.    end
  66. end
  67.  
  68. function _color()
  69.    while not _exit do
  70.       monitorLeft.clear()
  71.       monitorRight.clear()
  72.  
  73.       monitorLeft.setCursorPos(1,2)
  74.       monitorRight.setCursorPos(1,2)
  75.  
  76.       if shield <= maxShield then
  77.          monitorLeft.setBackgroundColor(colors.red)
  78.       else
  79.          monitorLeft.setBackgroundColor(colors.lime)
  80.       end
  81.    
  82.       if energy <= maxEnergy then
  83.          monitorRight.setBackgroundColor(colors.red)
  84.       else
  85.          monitorRight.setBackgroundColor(colors.lime)
  86.       end
  87.      
  88.       monitorLeft.write("Shield")
  89.       monitorRight.write("Energy")
  90.      
  91.       monitorLeft.setCursorPos(1,3)
  92.       monitorRight.setCursorPos(1,3)
  93.      
  94.       monitorLeft.write(tostring(math.floor((100/15)*shield)).."%")
  95.       monitorRight.write(tostring(math.floor((100/15)*energy)).."%")
  96.      
  97.       sleep(.1)
  98.    end
  99. end
  100.  
  101. function _exitScript()
  102.    local event, key = os.pullEvent( "key" ) -- limit os.pullEvent to the 'key' event
  103.  
  104.    if key == keys.e then -- if the key pressed was 'e'
  105.       print("Script Stopped")
  106.       _exit = true
  107.    end
  108.    
  109.    return true
  110. end
  111.  
  112. print( "Press E to exit Script." )
  113.  
  114. while not _exit do
  115.    parallel.waitForAny(receive, _print, _color, _exitScript)
  116.    sleep(.1)
  117. end
  118.  
  119. rednet.close("back")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement