Advertisement
AstolfoFate

tpEval.lua

Mar 27th, 2021 (edited)
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.22 KB | None | 0 0
  1. -- Summation function
  2. function sum(t)
  3.   local sum = 0
  4.   for k, v in pairs(t) do
  5.     sum = sum + v
  6.   end
  7.  
  8.   return sum
  9. end
  10.  
  11. -- Comma value function
  12. function comma_value(n)
  13.   local left, num, right = string.match(n, '^([^%d]*%d)(%d*)(.-)$')
  14.   return left..(num:reverse():gsub('(%d%d%d)', '%1,'):reverse())..right
  15. end
  16.  
  17. -- Center text function
  18. function centerWrite(text)
  19.   local width, height = term.getSize()
  20.   local x, y = term.getCursorPos()
  21.   term.setCursorPos(math.ceil((width / 2) - (text:len() / 2)), y)
  22.   term.write(text)
  23. end
  24.  
  25. -- DBC TP cost calculator
  26.   term.clear()
  27.   term.setCursorPos(1, 1)
  28.   centerWrite("DBC TP EVAL COST CALCULATOR")
  29.  
  30.   tpTable = {}
  31.   write("\nEnter your tp cost ")
  32.   currentTpCost = read()
  33.   tpTable[1] = currentTpCost
  34.   write("How much TP do you have? ")
  35.   tpEval = read()
  36.   numTpEval = tonumber(tpEval)
  37.   a = 1
  38.   i = 2
  39.   repeat
  40.     numTpTable = tonumber(tpTable[a])
  41.     currentTpCost = currentTpCost + 60
  42.     tpTable[i] = currentTpCost
  43.     total = sum(tpTable)
  44.     numTotal = tonumber(total)
  45.     i = i + 1
  46.     a = a + 1
  47.     sleep(0)
  48.   until numTotal >= numTpEval
  49.     i = i - 1
  50.     print("Total TP Cost: "..comma_value(total))
  51.     print("Attributes Obtainable: "..i)
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement