Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --sleep(30)
- --Device detection
- isError=0
- function detectDevice(DeviceName)
- DeviceSide="none"
- for k,v in pairs(redstone.getSides()) do
- if peripheral.getType(v)==DeviceName then
- DeviceSide = v
- break
- end
- end
- return(DeviceSide)
- end
- cell="none"
- monitor={}
- local peripheralList = peripheral.getNames()
- local lastEnergy, lastEnergy2, lastEnergyMax, lastEnergyMax2 = 0, 0, 0, 0
- MonitorSide=detectDevice("monitor")
- if MonitorSide~="none" then
- --monitor=peripheral.wrap(MonitorSide)
- --print ("Monitor on the " .. MonitorSide .. " connected.")
- imax=0
- for Index = 1, #peripheralList do
- if string.find(peripheralList[Index], "monitor") then
- imax=imax+1
- monitor[imax]=peripheral.wrap(peripheralList[Index])
- print ("Monitor on wired modem: "..peripheralList[Index].." connected.")
- end
- end --for
- else
- if monitor == "none" then
- print ("Warning - No Monitor attached, continuing without.")
- end
- end
- modem = peripheral.wrap("bottom")
- while true do
- --print("je rente dans while")
- modem.open(200)
- local event, modemSide, senderChannel, replyChannel, text, senderDistance = os.pullEvent("modem_message")
- local msg = textutils.unserialize(text)
- for i=1, imax do
- --monitor[i].write("Hello World !")
- local xmax, ymax = monitor[i].getSize()
- monitor[i].setBackgroundColor(colors.black)
- monitor[i].clear()
- monitor[i].setCursorPos(2,2)
- monitor[i].setTextScale(2)
- local longueur = xmax - 4
- -- energie pour CapaPrinc :
- if msg["energy"] ~= nil then
- lastEnergy=msg["energy"]
- lastEnergyMax=msg["maxenergy"]
- end
- if lastEnergy <= lastEnergyMax/3 then
- monitor[i].setBackgroundColor(colors.red)
- elseif (lastEnergy > lastEnergyMax/3) and (lastEnergy <= lastEnergyMax/3*2) then
- monitor[i].setBackgroundColor(colors.orange)
- else
- monitor[i].setBackgroundColor(colors.green)
- end
- local ispace = math.floor(longueur*lastEnergy/lastEnergyMax)+1
- for ii=1, ispace do
- monitor[i].write(" ")
- end
- monitor[i].setCursorPos(2,4)
- monitor[i].setTextColor(colors.green)
- monitor[i].setBackgroundColor(colors.black)
- monitor[i].write(tostring(lastEnergy).." RF")
- --write(msg["energy"])
- --print("Msg recu dans boucle for")
- -- energie pour CapaPlantations
- if msg["energy2"] ~= nil then
- lastEnergy2=msg["energy2"]
- lastEnergyMax2=msg["maxenergy2"]
- end
- monitor[i].setCursorPos(2,8)
- if lastEnergy2 <= lastEnergyMax2/3 then
- monitor[i].setBackgroundColor(colors.red)
- elseif (lastEnergy2 > lastEnergyMax2/3) and (lastEnergy2 <= lastEnergyMax2/3*2) then
- monitor[i].setBackgroundColor(colors.orange)
- else
- monitor[i].setBackgroundColor(colors.green)
- end
- local ispace = math.floor(longueur*lastEnergy2/lastEnergyMax2)+1
- for ii=1, ispace do
- monitor[i].write(" ")
- end
- monitor[i].setCursorPos(2,10)
- monitor[i].setTextColor(colors.green)
- monitor[i].setBackgroundColor(colors.black)
- monitor[i].write(tostring(lastEnergy2).." RF")
- -- moniteur suivant
- i=i+1
- end
- modem.close(200)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement