Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Configs:
- pool_numb = 5
- mana_min = 75
- rs_side = "top"
- monitor = "monitor_8"
- -- Init Variables:
- pool_list = { }
- have_monitor = false
- -- Functions:
- function wrapPeriph()
- wrap_list = peripheral.getNames()
- for _,w in pairs(wrap_list) do
- if string.find(w, "manaPool") ~= nil then
- wrap_name = string.sub(w,5,string.len(w))
- wrap_side = w
- wrap = peripheral.wrap(wrap_side)
- pool_list[wrap_name] = wrap
- wrap_info = string.format("%s connected to %s",wrap_name,wrap_side)
- sleep(1)
- elseif string.find(w,"monitor") ~= nil then
- wrap_side = w
- mon = peripheral.wrap(wrap_side)
- wrap_info = string.format("[mon] connected to %s - %s;%s",wrap_side,mon_x,mon_y)
- have_monitor = true
- mon.clear()
- mon_x, mon_y = mon.getSize()
- else
- wrap_name = w
- wrap_info = string.format("%s not connected to Network",wrap_name)
- end
- print(wrap_info)
- end
- end
- function drawMana()
- dx = mon_x
- dy_max = mon_y-3
- dy = math.floor((pp_t*dy_max)/100)
- for d = dy_max,dy,-1 do
- mon.setCursorPos(2,d)
- mon.clearLine()
- mon.setBackgroundColor(colors.lightBlue)
- mon.write(" ")
- --mon.setCursorPos(5,d+1)
- mon.setBackgroundColor(colors.black)
- --last_y = d
- end
- --mon.setCursorPos(5,last_y+1)
- --mon.clearLine()
- --mon.setBackgroundColor(colors.lightBlue)
- --mon.setTextColor(colors.black)
- --mon.write(pp_t.."%")
- --mon.setBackgroundColor(colors.black)
- end
- function writeMana(ys,data)
- mon.setCursorPos(2,ys)
- mon.clearLine()
- mon.setTextColor(colors.white)
- mon.write(data)
- end
- -- Init Main Loop:
- wrapPeriph()
- signal = false
- -- Main Loop:
- term.clear()
- sleep(2)
- term.clear()
- while true do
- sleep(0.5)
- term.setCursorPos(1,3)
- pl_t = 0
- pm_t = 0
- pn_t = 0
- pp_t = 0
- pb_t = false
- ys = 4
- for k,v in pairs(pool_list) do
- p_name = k
- p = pool_list[p_name]
- pl = p["getMana"]()
- pm = p["getMaxMana"]()
- pn = p["getManaNeeded"]()
- pb = p["isFull"]()
- pp = math.floor((pl*100)/pm)
- pl_t = pl_t+pl
- pm_t = pm_t+pm
- pn_t = pn_t+pn
- str = string.format("%s: %s/%s [%s] - %s (%s)",p_name,pl,pm,pp,pn,pb)
- term.clearLine()
- print(str)
- if have_monitor then
- writeMana(ys,str)
- ys = ys+1
- last_ys = ys+1
- end
- sleep(0.5)
- if not pb then
- pb_t = false
- else
- pb_t = true
- end
- end
- pp_t = math.floor((pl_t*100)/pm_t)
- x,y = term.getCursorPos()
- term.setCursorPos(1,y+1)
- str_t = string.format("Total: %s/%s [%s] - %s (%s)",pl_t,pm_t,pp_t,pn_t,pb_t)
- writeMana(last_ys,str_t)
- print(str_t)
- -- if have_monitor then
- -- mon.setBackgroundColor(colors.black)
- -- drawMana()
- -- end
- if pp_t <= mana_min then
- signal = true
- elseif pp_t == 100 then
- signal = false
- end
- rs.setOutput(rs_side,signal)
- end
Advertisement
Add Comment
Please, Sign In to add comment