Advertisement
meuced

BigScreen

Sep 3rd, 2014
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.25 KB | None | 0 0
  1. --sleep(30)
  2.  
  3. --Device detection
  4. isError=0
  5.  
  6. function detectDevice(DeviceName)
  7. DeviceSide="none"
  8. for k,v in pairs(redstone.getSides()) do
  9.  if peripheral.getType(v)==DeviceName then
  10.    DeviceSide = v
  11.    break
  12.  end
  13. end
  14.   return(DeviceSide)
  15. end
  16.  
  17. cell="none"
  18. monitor={}
  19. local peripheralList = peripheral.getNames()
  20. local lastEnergy, lastEnergy2, lastEnergyMax, lastEnergyMax2 = 0, 0, 0, 0
  21.  
  22. MonitorSide=detectDevice("monitor")
  23.  
  24. if MonitorSide~="none" then
  25.    --monitor=peripheral.wrap(MonitorSide)
  26.    --print ("Monitor on the " .. MonitorSide .. " connected.")
  27.    imax=0
  28.     for Index = 1, #peripheralList do
  29.             if string.find(peripheralList[Index], "monitor") then
  30.                             imax=imax+1
  31.                     monitor[imax]=peripheral.wrap(peripheralList[Index])
  32.                     print ("Monitor on wired modem: "..peripheralList[Index].." connected.")
  33.             end
  34.     end --for
  35. else
  36.  
  37. if monitor == "none" then
  38.         print ("Warning - No Monitor attached, continuing without.")
  39. end
  40. end
  41.  
  42. modem = peripheral.wrap("bottom")
  43.  
  44. while true do
  45.         --print("je rente dans while")
  46.         modem.open(200)
  47.         local event, modemSide, senderChannel, replyChannel, text, senderDistance = os.pullEvent("modem_message")
  48.         local msg = textutils.unserialize(text)
  49.         for i=1, imax do
  50.             --monitor[i].write("Hello World !")
  51.             local xmax, ymax = monitor[i].getSize()
  52.             monitor[i].setBackgroundColor(colors.black)
  53.             monitor[i].clear()
  54.             monitor[i].setCursorPos(2,2)
  55.             monitor[i].setTextScale(2)
  56.             local longueur = xmax - 4
  57.  
  58. -- energie pour CapaPrinc :
  59.  
  60. if msg["energy"] ~= nil then
  61.     lastEnergy=msg["energy"]
  62.     lastEnergyMax=msg["maxenergy"]
  63. end
  64.  
  65.   if lastEnergy <= lastEnergyMax/3 then
  66.     monitor[i].setBackgroundColor(colors.red)
  67.   elseif (lastEnergy > lastEnergyMax/3) and (lastEnergy <= lastEnergyMax/3*2) then
  68.     monitor[i].setBackgroundColor(colors.orange)
  69.     else
  70.       monitor[i].setBackgroundColor(colors.green)
  71.   end
  72.   local ispace = math.floor(longueur*lastEnergy/lastEnergyMax)+1
  73.   for ii=1, ispace do
  74.     monitor[i].write(" ")
  75.   end
  76.   monitor[i].setCursorPos(2,4)
  77.                 monitor[i].setTextColor(colors.green)
  78.   monitor[i].setBackgroundColor(colors.black)
  79.                 monitor[i].write(tostring(lastEnergy).." RF")
  80.  
  81.  
  82. --write(msg["energy"])
  83. --print("Msg recu dans boucle for")
  84.  
  85.  
  86.  
  87. -- energie pour CapaPlantations
  88.  
  89. if msg["energy2"] ~= nil then
  90.     lastEnergy2=msg["energy2"]
  91.     lastEnergyMax2=msg["maxenergy2"]
  92. end
  93.  
  94.  
  95.   monitor[i].setCursorPos(2,8)
  96.   if lastEnergy2 <= lastEnergyMax2/3 then
  97.     monitor[i].setBackgroundColor(colors.red)
  98.   elseif (lastEnergy2 > lastEnergyMax2/3) and (lastEnergy2 <= lastEnergyMax2/3*2) then
  99.     monitor[i].setBackgroundColor(colors.orange)
  100.     else
  101.       monitor[i].setBackgroundColor(colors.green)
  102.   end
  103.   local ispace = math.floor(longueur*lastEnergy2/lastEnergyMax2)+1
  104.   for ii=1, ispace do
  105.     monitor[i].write(" ")
  106.   end
  107.   monitor[i].setCursorPos(2,10)
  108.                 monitor[i].setTextColor(colors.green)
  109.   monitor[i].setBackgroundColor(colors.black)
  110.                 monitor[i].write(tostring(lastEnergy2).." RF")
  111.  
  112. -- moniteur suivant
  113.  
  114.                 i=i+1
  115.         end
  116.         modem.close(200)
  117. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement