Advertisement
NekoTiki

Untitled

Dec 4th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local modem = peripheral.wrap("top")
  2. local mon = peripheral.wrap("bottom")
  3. local monX, monY = mon.getSize()
  4.  
  5. mon.setBackgroundColor(colors.white)
  6. mon.setTextColor(colors.gray)
  7. modem.open(2)
  8.  
  9. function roundTo(number, scale)
  10.     local num = number
  11.     for i=0,scale do
  12.         num = num * 10
  13.     end
  14.  
  15.     num = math.floor(num)
  16.  
  17.     for i=0,scale do
  18.         num = num / 10
  19.     end
  20.  
  21.     return num
  22. end
  23.  
  24. function numberToText(number)
  25.     local num = tonumber(number)
  26.     if num == nil then return "nil" end
  27.     if num >= 1000000000000 then return (roundTo((num/1000000000000), 2) .. " T") end
  28.     if num >= 1000000000 then return (roundTo((num/1000000000), 2) .. " G") end
  29.     if num >= 1000000 then return (roundTo((num/1000000), 2) .. " M") end
  30.     if num >= 1000 then return (roundTo((num/1000), 2) .. " k") end
  31. end
  32.  
  33. function draw(data)
  34.     mon.clear()
  35.     mon.setTextScale(3)
  36.  
  37.     local stockedEnergy = numberToText(data["en"])
  38.     mon.setCursorPos(math.floor(monX / 2 - string.len(stockedEnergy) / 2), 1)
  39.     mon.write(stockedEnergy .. " RF")
  40.  
  41.     local producedEnergy = numberToText(data["enPT"])
  42.     mon.setCursorPos(math.floor(monX / 2 - string.len(producedEnergy) / 2), 2)
  43.     mon.write(producedEnergy .. " RF/t")
  44. end
  45.  
  46. while true do
  47.     modem.transmit(1,2,"getEnergy")
  48.     local event, mS, sC, rC,
  49.           data, sD = os.pullEvent("modem_message")
  50.    
  51.     print(data["en"] .. " - " .. data["enPT"])
  52.    
  53.     draw(data)
  54.    
  55.     sleep(1)
  56. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement