Advertisement
NekoTiki

Untitled

Dec 4th, 2018
113
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 == nil then return "nil" end
  25.     if num >= 1000000000000 then return (roundTo((num/1000000000000), 2) .. " T") end
  26.     if num >= 1000000000 then return (roundTo((num/1000000000), 2) .. " G") end
  27.     if num >= 1000000 then return (roundTo((num/1000000), 2) .. " M") end
  28.     if num >= 1000 then return (roundTo((num/1000), 2) .. " k") end
  29. end
  30.  
  31. function draw(data)
  32.     mon.clear()
  33.     mon.setTextScale(3)
  34.  
  35.     local stockedEnergy = numberToText(data["en"])
  36.     mon.setCursorPos(monX / 2 - string.len(stockedEnergy) / 2, 1)
  37.     mon.write(numberToText(stockedEnergy))
  38.  
  39.     local producedEnergy = numberToText(data["enPT"])
  40.     mon.setCursorPos(monX / 2 - string.len(producedEnergy) / 2, 2)
  41.     mon.write(numberToText(producedEnergy))
  42. end
  43.  
  44. while true do
  45.     modem.transmit(1,2,"getEnergy")
  46.     local event, mS, sC, rC,
  47.           data, sD = os.pullEvent("modem_message")
  48.    
  49.     print(data["en"] .. " - " .. data["enPT"])
  50.    
  51.     draw(data)
  52.    
  53.     sleep(1)
  54. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement