Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Video explicative : https://youtu.be/mG_4e6uEOy0
- -- id unique pour channel wifi
- local id=100
- local donne={}
- -- cote turbine
- local react=peripheral.wrap("back")
- -- cote double ecran
- local ecran=peripheral.wrap("top")
- -- cote modem
- local modem=peripheral.wrap("right")
- -- function pour transformer 9876543 en 9 876 543
- function number_format(n)
- local test=mille(n)
- if test.Mille==0 then
- return math.floor(n)
- else
- test.Mille=mille(test.Mille)
- if test.Mille.Mille==0 then
- return test.Mille.Cent.." "..cent(test.Cent)
- else
- return test.Mille.Mille.." "..cent(test.Mille.Cent).." "..cent(test.Cent)
- end
- end
- end
- -- function pour etre sur d'avoir trois chiffre (99 devient 099, 9 devient 009)
- function cent(n)
- n=math.floor(n)
- if n>99 then
- return n
- elseif n>9 then
- return "0"..n
- else
- return "00"..n
- end
- end
- -- creer un objet avec les centaine d'un cote les millier de l'autre
- function mille(n)
- if n<1000 then
- return {Mille=0,Cent=n}
- else
- return {Mille=math.floor(n/1000),Cent=n%1000}
- end
- end
- -- lance l'actu du contenu
- function actu()
- while true do
- actu2()
- os.sleep(1)
- end
- end
- -- actualise l'ecran et envoi les infos
- function actu2()
- donne["active"]=react.getActive()
- donne["fuel"]=react.getFuelAmount()
- donne["fuelMax"]=react.getFuelAmountMax()
- donne["prod"]=react.getHotFluidProducedLastTick()
- donne["id"]=id
- donne["type"]="reactor"
- modem.transmit(id,id+50,textutils.serialize(donne))
- ecran.clear()
- ecran.setCursorPos(1,1)
- if donne["active"] then
- ecran.setBackgroundColor(colors.green)
- ecran.write("Active")
- else
- ecran.setBackgroundColor(colors.red)
- ecran.write("Desactive")
- end
- ecran.setCursorPos(1,2)
- ecran.write("Fuel : "..number_format(donne["fuel"]/1000).." yell")
- ecran.setCursorPos(1,3)
- ecran.write("Stock : "..math.ceil(donne["fuel"]/donne["fuelMax"]*100).."%")
- ecran.setCursorPos(1,4)
- ecran.write("Prod : "..number_format(donne["prod"]))
- end
- -- ecoute pour on/off
- modem.open(50+id)
- function ecoute()
- while true do
- local e, m, sc, rc, msg, sd = os.pullEvent("modem_message")
- if react.getActive() then
- react.setActive(false)
- else
- react.setActive(true)
- end
- actu2()
- end
- end
- parallel.waitForAll(actu,ecoute)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement