Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --x,y,z= gps.locate(5)
- function RANDBI()
- NUM1 = math.random(2)
- return NUM1
- end
- function netcheck()
- while (DR==false) do
- --term.clear()
- rednet.open("top")
- rednet.broadcast("0"..",".."0"..",".."0")
- term.setCursorPos(1,4)
- print("Sent Announcement")
- term.setCursorPos(1,5)
- print("Waiting")
- term.setCursorPos(1,6)
- print(" ")
- term.setCursorPos(1,7)
- print(" ")
- term.setCursorPos(1,8)
- print(" ")
- term.setCursorPos(1,9)
- print(" ")
- senderID, message = rednet.receive(1)
- if(senderID==nil)then
- DR = false
- term.setCursorPos(1,6)
- print("No Reply Trying Again")
- else
- if(message==ID..",OK") then
- DR = true
- term.setCursorPos(1,6)
- print("Reply Received From: "..senderID.." Message: "..message)
- controllerid = senderID
- else
- DR = false
- term.setCursorPos(1,6)
- print("Reply But Not Me. Trying Again")
- end
- end
- rednet.close("top")
- os.sleep(RANDBI())
- end
- end
- function cellcheck()
- CellMax = 0
- CellStored = 0
- CellPercent = 0
- for i = 1, #PowerBlocks do
- cell = peripheral.wrap(PowerBlocks[i])
- CellMax = CellMax + cell.getMaxEnergyStored()
- CellStored = CellStored + cell.getEnergyStored()
- print (PowerBlocks[i] .." = "..cell.getEnergyStored().."/"..cell.getMaxEnergyStored().."/"..math.floor(100*cell.getEnergyStored()/cell.getMaxEnergyStored()).."% ")
- --print (cell.getEnergyStored())
- os.sleep(.01)
- end
- CellPercent = math.floor(100*CellStored/CellMax)
- term.redirect(mon)
- local w, h = term.getSize()
- bar1 = ""
- bar1 = string.rep("#",w)
- bar2 = ""
- bar2 = string.rep(" ",w)
- for i =1, w do
- end
- --onechunk = math.floor(30 / 100)
- seg = math.floor(h/100)
- barleng = h
- filledleng = math.floor(barleng * CellStored / CellMax)
- pos = h
- curpos = 0
- for i = 1, h do
- if i <= filledleng then
- term.setCursorPos(1,pos+1)
- term.setTextColor( colors.green )
- print (bar1)
- pos = pos -1
- else
- term.setCursorPos(1,pos+1)
- term.setTextColor( colors.black )
- print (bar2)
- pos = pos -1
- end
- end
- term.redirect(term.native())
- -- if (CellPercent <= 25) then
- -- mon.setBackgroundColor(colors.red)
- -- mon.clear()
- -- elseif (CellPercent <= 50) then
- -- mon.setBackgroundColor(colors.yellow)
- -- mon.clear()
- -- elseif (CellPercent <= 75) then
- -- mon.setBackgroundColor(colors.blue)
- -- mon.clear()
- -- elseif (CellPercent <= 100) then
- -- mon.setBackgroundColor(colors.green)
- -- mon.clear()
- -- end
- end
- term.clear()
- PowerBlocks = {}
- term.setCursorPos(1,1)
- print ("Building Local Power network =")
- term.setCursorPos(31,1)
- os.sleep(1)
- --Build Power array off of wired net
- --===============================================
- for _, name in pairs(peripheral.getNames()) do
- if peripheral.getType(name) == "powered_tile" then --# change "power_tille" to your peripheral type.
- table.insert(PowerBlocks, name)
- end
- end
- --===============================================
- print (" Done #"..#PowerBlocks)
- os.sleep(2)
- mon = peripheral.wrap("right")
- ID = os.getComputerID()
- CellStored = 0
- CellMax = 0
- CellPercent = 0
- controllerid = 0
- CounterCT=0
- DR = true
- term.clear()
- while (true) do
- --term.clear()
- if (DR~=true)then
- term.clear()
- term.setCursorPos(1,2)
- print("this might take a few mins")
- print("Connecting to Network =")
- netcheck()
- term.setCursorPos(24,3)
- print (" Done")
- os.sleep(1)
- term.clear()
- end
- rednet.open("top")
- --term.clear()
- term.setCursorPos(1,1)
- --print("Waiting-Tries:"..CounterCT)
- senderID, message = rednet.receive(2)
- if (senderID ~= nil)then
- if (senderID==controllerid)then
- print("My Traffic")
- if(message==ID..",Update"==true)then
- print("Send Update")
- cellcheck()
- print("Sent:"..CellPercent.." "..CellStored.."/"..CellMax)
- rednet.broadcast(CellPercent..","..CellStored..","..CellMax)
- --print(CellFull)
- Rid, Mess = rednet.receive(2)
- rednet.close("top")
- CounterCT=0
- os.sleep(0.5)
- elseif(message==ID..",Reboot"==true)then
- print("Rebooting")
- rednet.broadcast("RemoveNow")
- Rid, Mess = rednet.receive(2)
- --rednet.send(controllerid,"RemoveNow")
- os.sleep(1)
- rednet.close("top")
- os.sleep(2)
- os.reboot()
- else
- end
- else
- term.setCursorPos(1,1)
- print("Not My Traffic")
- end
- else
- term.setCursorPos(1,1)
- print("No Com Traffic: "..CounterCT.." ")
- cellcheck()
- print(CellStored.."/"..CellMax.."/"..CellPercent.."% ")
- if (CounterCT == 25)then
- DR=true
- CounterCT=0
- term.clear()
- rednet.close("top")
- end
- CounterCT=CounterCT+1
- end
- --os.sleep(0.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement