Advertisement
dadragon84

Pay For Power

Apr 29th, 2023 (edited)
905
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.65 KB | None | 0 0
  1.  
  2. --version 0.5--
  3. -- Prompting for which color wire the signal will travel through --
  4. write("Which Line?")
  5. local z = read()
  6. z = z+0
  7. write("How much electricty would you like to buy?:")
  8. local x = read()
  9. x = x+0
  10. local y = x
  11. -- the power math x being the number of ticks dived this by your power per tick, y is setting the base price Ei 1 unit of pay per how ever many units you divide it by
  12. x = x/20480
  13. x = x/20
  14. y = y/10000
  15. -- The money taker in my case I choose it to use gold you may use what ever you want just replace the world gold with what ever you want it to be
  16. print("Please insert ", y ," gold in slot one to continue")
  17. write("Press enter to continue")
  18. local data = turtle.getItemDetail()
  19. print(data.name)
  20. print(data.count)
  21. -- replaace minecraft:gold_block with what ever you want yours to be I three gold_block gold_ingot and gold_nuggets
  22. if data.name == "minecraft:gold_block" then
  23. --Multipled by 81 because a gold block is worth 81 of my money units which are based on gold nuggets
  24. local m = data.count*81
  25. turtle.dropDown(m/81, 1)
  26. if m >= y then
  27. print(m-y, " funds remaining")
  28. local h = m-y
  29. write("return remaining funds?, y, n?:")
  30. local t = read()
  31. if t == "y" then
  32. -- I got lazy and didn't want to find a way of making it return the exact number of stuff so I just went with the closet number of gold blocks You could find a way for it to return the perfect amount of stuff though
  33. print ("will not be exactly, to the nearest 81 gold be more carful next time!")
  34. turtle.suckUp(h/81)
  35. print("Retrive from slot 2")
  36. end
  37. --Sets the output to z the output color, and then sleeps for x the time now in seconds that it must output a signal to allow power to flow through
  38. rs.setBundledOutput("front", z)
  39. sleep(x)
  40. rs.setBundledOutput("front", 0)
  41. end
  42. elseif data.name == "minecraft:gold_ingot" then
  43. local m = data.count*9
  44. local h = m-y
  45. turtle.dropDown(m/9, 1)
  46. if m >= y then
  47. print(m-y, " funds remaining")
  48. write("return remaining funds?, y, n?:")
  49. local t = read()
  50. if t == "y" then
  51. print ("will not be exactly, to the nearest 81 gold be more carful next time!")
  52. turtle.suckUp(h/81)
  53. print("Retrive from slot 2")
  54. end
  55.  
  56. rs.setBundledOutput("front", z)
  57. sleep(x)
  58. rs.setBundledOutput("front", 0)
  59. end
  60. if data.name == "minecraft:gold_nugget" then
  61. local m = data.count
  62. local h = m-y
  63. turtle.dropDown(m, 1)
  64. if m >= y then
  65. print(m-y, " funds remaining")
  66. write("return remaining funds?, y, n?:")
  67. local t = read()
  68. if t == "y" then
  69. print ("will not be exactly, to the nearest 81 gold be more carful next time!")
  70. turtle.suckUp(h/81)
  71. print("Retrive from slot 2")
  72. end
  73.  
  74. rs.setBundledOutput("front", z)
  75. sleep(x)
  76. rs.setBundledOutput("front", 0)
  77. end
  78. end
  79. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement