Advertisement
Youseikun

Item Cost Calc

Jul 24th, 2021 (edited)
1,134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.26 KB | None | 0 0
  1. me = peripheral.find("meBridge")
  2.  
  3. -- first line: item name
  4. -- second line: maxAmount
  5. -- third line: unitCost
  6. local handle = fs.open("values.txt", "r")
  7. if handle then
  8.     name = handle.readLine()
  9.     print("Name is " .. name)
  10.     maxAmount = handle.readLine()
  11.     print("Max amount is " .. maxAmount)
  12.     unitCost = handle.readLine()
  13.     print("Unit cost is " .. unitCost)
  14. else
  15.     print("File not found...")
  16.     quit()
  17. end
  18. handle.close()
  19.  
  20. melist = me.listItems()
  21.  
  22. for i=1, #melist do
  23.     print(melist[i].name)
  24.     if melist[i].name == name then
  25.         listIndex = melist[i]
  26.         print(name .. " found at index " .. i)
  27.     else
  28.         print(name .. " not found.")
  29.     end
  30. end
  31.  
  32. print(listIndex.name .. " " .. listIndex.amount)
  33.  
  34. --maxAmount = 4000
  35. print("Max amount " .. maxAmount)
  36.  
  37. --unitCost = 1024
  38. print("Cost at 50% " .. unitCost)
  39.  
  40. percent = (listIndex.amount / maxAmount) * 100
  41. print("Current percent " .. percent)
  42.  
  43. shrinkAmount = (percent-50)/25
  44. print("Shrink result " .. shrinkAmount)
  45.  
  46. sigmoid = shrinkAmount/(1+math.abs(shrinkAmount))
  47. print("Sigmoid " .. sigmoid)
  48.  
  49. finalCost = math.floor(unitCost * (1 - (sigmoid * 1.5)))
  50. print("Final cost " .. finalCost)
  51.  
  52. SellPrice = math.floor(finalCost * 0.9)
  53. print("Sell cost " .. SellPrice)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement