Advertisement
SythsGod

Storage Unit Check

Mar 5th, 2014
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.48 KB | None | 0 0
  1. local bridge = peripheral.wrap("left")
  2. local net = peripheral.wrap("back")
  3.  
  4. bridge.clear()
  5.  
  6. local width = 200
  7.  
  8. local storageUnits = {
  9.    {
  10.          ["id"] = "resonant_energy_cell"
  11.          ["name"] = "Resonant Energy Cell"
  12.    }
  13. }
  14.  
  15. local offset = 0
  16. for key, storageUnit in pairs(storageUnits) do
  17.   pxOffset = offset * 20
  18.   storageUnit["label"] = bridge.addText(4, 4 + pxOffset, storageUnit["name"], 0x000000)
  19.   storageUnit["bar"] = bridge.addBox(4, 14 + pxOffset, 0, 5, 0xCC0000, 0.9)
  20.   storageUnit["bar"].setZIndex(2)
  21.   storageUnit["bg"] = bridge.addBox(4, 14 + pxOffset, width, 5, 0x000000, 0.5)
  22.   offset = offset + 1
  23. end
  24.  
  25. while true do
  26.   for i=#storageUnits,1,-1 do
  27.         storageUnit = storageUnits[i]
  28.         if net.isPresentRemote(storageUnit["id"]) then
  29.       if net.getTypeRemote(storageUnit["id"]) == "batbox" then
  30.             capacity = net.callRemote(storageUnit["id"], "getCapacity")
  31.             amount = net.callRemote(storageUnit["id"], "getStored")
  32.             storageUnit["bar"].setWidth(width / capacity * amount)
  33.           elseif net.getTypeRemote(storageUnit["id"] == "resonant_energy_cell" then
  34.         capacity = 50000000
  35.         amount = net.callRemote(storageUnit["id"], "getEnergyStored")
  36.         storageUnit["bar"].setWidth(width / capacity * amount)
  37.       end
  38.     else
  39.           storageUnit["bar"].delete()
  40.           storageUnit["bg"].delete()
  41.           storageUnit["label"].delete()
  42.           table.remove(storageUnits, i)
  43.         end
  44.   end
  45.   sleep(0.5)
  46. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement