Advertisement
AdslHouba

Big Reactor 1/3 pour turbine

Mar 19th, 2015
694
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.53 KB | None | 0 0
  1. -- Video : https://youtu.be/mG_4e6uEOy0
  2.  
  3. -- le script va afficher sur un ecran double si actif, vitesse rotor, prod RF et buffer
  4. -- il va egalement envoyer sur le channel id les infos et ecoute le channel id+50 pour on/off
  5.  
  6. -- id unique pour channel wifi
  7. local id=3
  8. local donne={}
  9. -- cote turbine
  10. local turbine=peripheral.wrap("back")
  11. -- cote double ecran
  12. local ecran=peripheral.wrap("top")
  13. -- cote modem
  14. local modem=peripheral.wrap("right")
  15.  
  16. -- function pour transformer 9876543 en 9 876 543
  17. function number_format(n)
  18.   local test=mille(n)
  19.   if test.Mille==0 then
  20.     return math.floor(n)
  21.   else
  22.     test.Mille=mille(test.Mille)
  23.     if test.Mille.Mille==0 then
  24.       return test.Mille.Cent.." "..cent(test.Cent)
  25.     else
  26.       return test.Mille.Mille.." "..cent(test.Mille.Cent).." "..cent(test.Cent)
  27.     end
  28.   end
  29. end
  30. -- function pour etre sur d'avoir trois chiffre (99 devient 099, 9 devient 009)
  31. function cent(n)
  32.   n=math.floor(n)
  33.   if n>99 then
  34.     return n
  35.    elseif n>9 then
  36.     return "0"..n
  37.    else
  38.     return "00"..n
  39.    end
  40. end
  41. -- creer un objet avec les centaine d'un cote les millier de l'autre
  42. function mille(n)
  43.   if n<1000 then
  44.     return {Mille=0,Cent=n}
  45.   else
  46.     return {Mille=math.floor(n/1000),Cent=n%1000}
  47.   end
  48. end
  49. -- lance l'actu du contenu
  50. function actu()
  51.   while true do
  52.     actu2()
  53.     os.sleep(1)
  54.   end
  55. end
  56. -- actualise l'ecran et envoi les infos
  57. function actu2()
  58.     donne["active"]=turbine.getActive()
  59.     donne["buff"]=turbine.getEnergyStored()
  60.     donne["speed"]=turbine.getRotorSpeed()
  61.     donne["prod"]=turbine.getEnergyProducedLastTick()
  62.     donne["id"]=id
  63.     donne["type"]="turbine"
  64.  
  65.     modem.transmit(id,id+50,textutils.serialize(donne))
  66.  
  67.     ecran.clear()
  68.    
  69.     ecran.setCursorPos(1,1)
  70.     if donne["active"] then
  71.     ecran.setBackgroundColor(colors.green)
  72.     ecran.write("Active")
  73.     else
  74.     ecran.setBackgroundColor(colors.red)
  75.     ecran.write("Desactive")
  76.     end
  77.    
  78.     ecran.setCursorPos(1,2)
  79.     ecran.write("Rotor  : "..number_format(donne["speed"]))
  80.     ecran.setCursorPos(1,3)
  81.     ecran.write("Prod   : "..number_format(donne["prod"]))
  82.     ecran.setCursorPos(1,4)
  83.     ecran.write("Buffer : "..number_format(donne["buff"]))
  84. end
  85. -- ecoute pour on/off
  86. modem.open(50+id)
  87. function ecoute()
  88.   while true do
  89.     local e, m, sc, rc, msg, sd = os.pullEvent("modem_message")
  90.    
  91.     if turbine.getActive() then
  92.       turbine.setActive(false)
  93.     else
  94.       turbine.setActive(true)
  95.     end
  96.     actu2()
  97.    
  98.   end
  99. end
  100. parallel.waitForAll(actu,ecoute)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement