Advertisement
AdslHouba

Surveillance de mekanism (2/2) Computercraft

Oct 12th, 2016
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.02 KB | None | 0 0
  1. -- https://www.youtube.com/watch?v=8nNo0O05ZVA
  2. -- Explication de code
  3.  
  4. ecran=peripheral.wrap("back")
  5. modem=peripheral.wrap("top")
  6. chatbox=peripheral.wrap("front")
  7.  
  8.  
  9. aucuneNouvelle=false
  10.  
  11. chatbox.say('reboot',9999,false,'Surveillance reacteur')
  12.  
  13. myWindow = window.create(ecran,26,1,4,1)
  14. myWindow.setBackgroundColor(colors.black)
  15. --myWindow.setColor(colors.yellow)
  16.  
  17. dernierTemps=10
  18.  
  19. modem.open(1)
  20.  
  21. function actu()
  22.     while true do  
  23.         local event, modemSide, senderChannel,
  24.           replyChannel, message, senderDistance = os.pullEvent("modem_message")
  25.        
  26.        
  27.        
  28.         if message.input<message.output then
  29.             ecran.setBackgroundColor(colors.red)
  30.             pourc=-1*math.ceil(message.input/message.output*100)
  31.             chatbox.say('Probleme d\'energie',9999,false,'Surveillance reacteur')
  32.             aucuneNouvelle=false
  33.         else
  34.             ecran.setBackgroundColor(colors.green)
  35.             pourc=math.ceil(message.output/message.input*100)
  36.             if aucuneNouvelle then
  37.                 aucuneNouvelle=false
  38.                 chatbox.say('Retour ! '..pourc,9999,false,'Surveillance reacteur')
  39.             end
  40.         end
  41.        
  42.        
  43.        
  44.         ecran.clear()
  45.         ecran.setCursorPos(1,2)
  46.         ecran.write('Entrer :  '..math.ceil(message.input*4/1000)..'k RF/t')
  47.         ecran.setCursorPos(1,3)
  48.         ecran.write('Sortie :  '..math.ceil(message.output*4/1000)..'k RF/t '..pourc..'%')
  49.         ecran.setCursorPos(1,4)
  50.         ecran.write('Stockage :  '..math.ceil((message.energy*4)/1000000000)..'G RF '..math.ceil(message.energy/message.maxEnergy*100)..'%')
  51.         -- maxEnergy
  52.         dernierTemps=10
  53.         myWindow.clear()
  54.         myWindow.setCursorPos(2,1)
  55.         myWindow.write(dernierTemps)
  56.        
  57.     end
  58. end
  59. function timerC()
  60.     while true do
  61.         if dernierTemps>=0 then
  62.             myWindow.clear()
  63.             myWindow.setCursorPos(3,1)
  64.             myWindow.write(dernierTemps)   
  65.         elseif dernierTemps==-5 then
  66.             chatbox.say('AUCUNE NOUVELLE DU REACTEUR !',9999,false,'Surveillance reacteur')
  67.             chatbox.say('AUCUNE NOUVELLE DU REACTEUR !',9999,false,'Surveillance reacteur')
  68.             aucuneNouvelle=true
  69.         end
  70.         dernierTemps=dernierTemps-1
  71.         os.sleep(1)
  72.     end
  73. end
  74. parallel.waitForAll(timerC,actu)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement