Advertisement
NekoTiki

Untitled

Dec 4th, 2018
107
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=1,scale do
  12.         num = num * 10
  13.     end
  14.  
  15.     num = math.floor(num)
  16.  
  17.     for i=1,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.     if num >= 0 then return (rountTo(num, 2)) end
  32.     if num <= -1000 then return ("-" .. roundTo(((0-num) / 1000), 2) .. " k") end
  33.     if num <= -1000000 then return ("-" .. roundTo(((0-num) / 1000000), 2) .. " M") end
  34.     if num <= -1000000000 then return ("-" .. roundTo(((0-num) / 1000000000), 2) .. " G") end
  35.     if num <= -1000000000000 then return ("-" .. roundTo(((0-num) / 1000000000000), 2) .. " T") end
  36. end
  37.  
  38. function draw(data)
  39.     mon.clear()
  40.     mon.setTextScale(3)
  41.  
  42.     local stockedEnergy = numberToText(data["en"]) .. " RF"
  43.     mon.setCursorPos(math.floor((monX / 2) - (string.len(stockedEnergy) / 2)), 1)
  44.     mon.write(stockedEnergy)
  45.  
  46.     local producedEnergy = numberToText(data["enPT"]) .. " RF/t"
  47.     mon.setCursorPos(math.floor((monX / 2) - (string.len(producedEnergy) / 2)), 2)
  48.     mon.write(producedEnergy)
  49. end
  50.  
  51. while true do
  52.     modem.transmit(1,2,"getEnergy")
  53.     local event, mS, sC, rC,
  54.           data, sD = os.pullEvent("modem_message")
  55.    
  56.     print(data["en"] .. " - " .. data["enPT"])
  57.    
  58.     draw(data)
  59.    
  60.     sleep(1)
  61. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement