Advertisement
AdslHouba

Big Reactor 2/3 pour reacteur

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