Advertisement
NekoTiki

Untitled

Dec 4th, 2018
106
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. modem.open(2)
  6.  
  7. function roundTo(number, scale)
  8.     local num = number
  9.     for i=0,scale do
  10.         num = num * 10
  11.     end
  12.  
  13.     num = math.floor(num)
  14.  
  15.     for i=0,scale do
  16.         num = num / 10
  17.     end
  18.  
  19.     return num
  20. end
  21.  
  22. function numberToText(number)
  23.     local num = tonumber(number)
  24.     if num >= 1000000000000 then return (roundTo((num/1000000000000), 2) .. " T") end
  25.     if num >= 1000000000 then return (roundTo((num/1000000000), 2) .. " G") end
  26.     if num >= 1000000 then return (roundTo((num/1000000), 2) .. " M") end
  27.     if num >= 1000 then return (roundTo((num/1000), 2) .. " k") end
  28. end
  29.  
  30. function draw(data)
  31.     mon.clear()
  32.     mon.setTextScale(3)
  33.  
  34.     local stockedEnergy = numberToText(data["en"])
  35.     mon.setCursorPos(monX / 2 - string.len(stockedEnergy) / 2, 1)
  36.     mon.write(numberToText(stockedEnergy))
  37.  
  38.     local producedEnergy = numberToText(data["enPT"])
  39.     mon.setCursorPos(monX / 2 - string.len(producedEnergy) / 2, 2)
  40.     mon.write(numberToText(producedEnergy))
  41. end
  42.  
  43. while true do
  44.     modem.transmit(1,2,"getEnergy")
  45.     local event, mS, sC, rC,
  46.           data, sD = os.pullEvent("modem_message")
  47.    
  48.     print(data["en"] .. " - " .. data["enPT"])
  49.    
  50.     draw(data)
  51.    
  52.     sleep(1)
  53. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement