AstolfoFate

tpcost.lua

Mar 27th, 2021 (edited)
60
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 TOTAL TP COST CALCULATOR")
  29.  
  30. tpTable = {}
  31. write("\nEnter your tp cost ")
  32. currentTpCost = read()
  33. currentTpCost = tonumber(currentTpCost)
  34. tpTable[1] = currentTpCost
  35. write("How many attributes? ")
  36. levelUps = read()
  37. levelUps = tonumber(levelUps)
  38. levelUps = levelUps + 2
  39.  
  40. if currentTpCost == 16 then
  41.   for i = 2, levelUps do
  42.     if i < 19 then
  43.       currentTpCost = currentTpCost + 0
  44.       tpTable[i] = currentTpCost
  45.     elseif i == 19 then
  46.       currentTpCost = currentTpCost + 5
  47.       tpTable[i] = currentTpCost
  48.     elseif i > 19 and i < 137 then
  49.       currentTpCost = currentTpCost + 7
  50.       tpTable[i] = currentTpCost
  51.     elseif i >= 137 then
  52.       currentTpCost = currentTpCost + 6
  53.       tpTable[i] = currentTpCost
  54.     end
  55.   end
  56.  
  57. elseif currentTpCost >= 21 and currentTpCost < 840 then
  58.   iOne = 2
  59.   repeat
  60.     currentTpCost = currentTpCost + 7
  61.     tpTable[iOne] = currentTpCost
  62.     iOne = iOne + 1
  63.     levelUps = levelUps - 1
  64.   until currentTpCost >= 840 or levelUps <= 0
  65.   if currentTpCost >= 840 and levelUps > 0 then
  66.     for i = iOne, levelUps do
  67.       currentTpCost = currentTpCost + 6
  68.       tpTable[i] = currentTpCost
  69.     end
  70.   end
  71.  
  72.  
  73. elseif currentTpCost >= 840 then
  74.   for i = 2, levelUps do
  75.     currentTpCost = currentTpCost + 6
  76.     tpTable[i] = currentTpCost
  77.   end
  78. end
  79.  
  80.  
  81. total = sum(tpTable)
  82. print("Total TP Cost: "..comma_value(total))
  83. print("Next Level Up: "..comma_value(currentTpCost))
  84.  
RAW Paste Data