sxrgini

cc test

Nov 5th, 2024 (edited)
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local collectorFee = 10
  2. local creds = 0
  3. local credsPerDia = 75
  4. local credsPerGoldIngot = 45
  5. local credsPerGoldNugget = 5
  6. local playerName = ""
  7. local originalDirection = 1 -- 1: north, 2: east, 3: south, 4: west
  8.  
  9. -- Function to center text on the screen
  10. function centerText(y, text)
  11. local width = term.getSize()
  12. term.setCursorPos(math.floor((width - #text) / 2), y)
  13. term.write(text)
  14. end
  15.  
  16. -- Function to wrap and display text within the screen width
  17. function wrapText(y, text)
  18. local width = term.getSize()
  19. for line in text:gmatch(".{1," .. width .. "}") do
  20. term.setCursorPos(1, y)
  21. term.write(line)
  22. y = y + 1
  23. end
  24. return y -- Return the new y position after writing
  25. end
  26.  
  27. -- Function to check if the disk is a Casino Card
  28. function checkForCasinoCard()
  29. return fs.exists("disk/creds.lua")
  30. end
  31.  
  32. -- Function to write card data to disk and update the disk label with credits
  33. function writeCard()
  34. local Card = fs.open("disk/creds.lua", "w")
  35. if not Card then
  36. centerText(8, "Error writing to disk!")
  37. sleep(2)
  38. return
  39. end
  40.  
  41. local data = (tostring(math.random(1, 163456)) .. "11066011" .. tostring(creds) .. "11077011" .. tostring(math.random(1, 163456)))
  42. local file = fs.open("disk/name.txt", "w")
  43. file.write(playerName)
  44. file.close()
  45. Card.write(data)
  46. Card.close()
  47.  
  48. -- Update the disk label to include current credits and player's name
  49. disk.setLabel("right",playerName .. "'s Casino Card - " .. tostring(creds) .. "C")
  50. end
  51.  
  52. -- Function to read card data from the disk
  53. function readCard()
  54. if not fs.exists("disk/creds.lua") then
  55. return false
  56. end
  57.  
  58. local Card = fs.open("disk/creds.lua", "r")
  59. if not Card then
  60. centerText(8, "Error reading from disk!")
  61. sleep(2)
  62. return false
  63. end
  64.  
  65. local data = Card.readAll()
  66. Card.close()
  67.  
  68. local a, b = string.find(data, "11066011")
  69. local c, d = string.find(data, "11077011")
  70. creds = tonumber(string.sub(data, b + 1, c - 1))
  71. return true
  72. end
  73.  
  74. -- Function to insert a card
  75. function insertCard()
  76. while true do
  77. term.clear()
  78. centerText(6, "Please insert your Casino Card.")
  79. sleep(1)
  80.  
  81. if fs.exists("disk/") then
  82. term.clear()
  83. if readCard() then
  84. -- Rename the disk to reflect player credits and name
  85. disk.setLabel("right",playerName .. "'s Casino Card - " .. tostring(creds) .. "C")
  86. break -- Exit the loop if a valid card is inserted
  87. else
  88. centerText(8, "This isn't a Casino Card.")
  89. sleep(2)
  90. centerText(10, "Would you like to create one? (Y/N)")
  91. local event, key = os.pullEvent("key")
  92. if key == keys.y or key == keys.enter then
  93. term.clear()
  94. centerText(7, "Enter your name:")
  95. playerName = read() -- Prompt for player's name
  96. centerText(8, "Creating a new Casino Card...")
  97. creds = 0 -- Start with 0 credits
  98. writeCard()
  99. centerText(9, "Casino Card created.")
  100. sleep(2)
  101. else
  102. centerText(10, "Please remove the disk.")
  103. sleep(2)
  104. end
  105. end
  106. end
  107. end
  108. end
  109.  
  110. -- Function to check credit balance
  111. function checkBalance()
  112. term.clear()
  113. centerText(4, "Your Balance: " .. creds .. " Credits")
  114. centerText(6, "Press any key to continue...")
  115. os.pullEvent("key")
  116. end
  117.  
  118. -- Function to deposit credits
  119. function depositCredits()
  120. if not checkForCasinoCard() then
  121. centerText(10, "No Casino Card Found.")
  122. sleep(2)
  123. return
  124. end
  125.  
  126. term.clear()
  127. readCard()
  128. centerText(4, "Deposit Credits")
  129. centerText(6, "Diamonds, Gold Ingots, or Gold Nuggets.")
  130.  
  131. local totalCreds = 0
  132.  
  133. -- Function to find the chest behind the turtle
  134. local function findChest()
  135. originalDirection = 1 -- Reset to original direction
  136. for _ = 1, 4 do
  137. if turtle.suck(0) then
  138. return true -- Chest found
  139. end
  140. turtle.turnLeft() -- Keep turning until a chest is found
  141. end
  142. -- Restore original direction
  143. turtle.turnRight() -- Restore to original facing direction
  144. return false -- No chest found
  145. end
  146.  
  147. if not findChest() then
  148. centerText(8, "No chest found behind the turtle!")
  149. sleep(2)
  150. return
  151. end
  152.  
  153. for i = 1, 16 do
  154. if turtle.getItemCount(i) > 0 then
  155. local slot = turtle.getItemDetail(i)
  156. if slot.name == "minecraft:diamond" then
  157. totalCreds = totalCreds + (slot.count * credsPerDia)
  158. turtle.select(i)
  159. turtle.drop(slot.count) -- Drop diamonds to deposit
  160. elseif slot.name == "minecraft:gold_ingot" then
  161. totalCreds = totalCreds + (slot.count * credsPerGoldIngot)
  162. turtle.select(i)
  163. turtle.drop(slot.count) -- Drop gold ingots to deposit
  164. elseif slot.name == "minecraft:gold_nugget" then
  165. totalCreds = totalCreds + (slot.count * credsPerGoldNugget)
  166. turtle.select(i)
  167. turtle.drop(slot.count) -- Drop gold nuggets to deposit
  168. end
  169. end
  170. end
  171.  
  172. if totalCreds > 0 then
  173. creds = creds + totalCreds
  174. writeCard() -- Update card data and disk label
  175. centerText(8, totalCreds .. " Credits deposited.")
  176. else
  177. centerText(8, "No items to deposit!")
  178. end
  179.  
  180. centerText(10, "Press any key to continue...")
  181. local event, key = os.pullEvent("key")
  182. if key == keys.b then
  183. return
  184. end
  185. end
  186.  
  187. -- Function to withdraw credits
  188. function withdrawCredits()
  189. if not checkForCasinoCard() then
  190. centerText(10, "No Casino Card Found.")
  191. sleep(2)
  192. return
  193. end
  194.  
  195. term.clear()
  196. readCard()
  197. if creds <= 0 then -- Check if there are no credits available
  198. centerText(8, "The Bank is Empty!")
  199. centerText(10, "Press any key to return...")
  200. os.pullEvent("key") -- Wait for user input
  201. return
  202. end
  203.  
  204. centerText(4, "Withdraw Credits")
  205. centerText(6, "Enter amount to withdraw:")
  206.  
  207. local amount = tonumber(read())
  208.  
  209. if amount and amount > 0 and amount <= creds then
  210. creds = creds - amount
  211. writeCard() -- Update card data and disk label
  212.  
  213. -- Calculate how many items to withdraw based on credits
  214. local diamondsToWithdraw = math.floor(amount / credsPerDia)
  215. local goldIngotsToWithdraw = math.floor((amount % credsPerDia) / credsPerGoldIngot)
  216. local goldNuggetsToWithdraw = math.floor((amount % credsPerGoldIngot) / credsPerGoldNugget)
  217.  
  218. -- Function to find the chest behind the turtle
  219. local function findChest()
  220. originalDirection = 1 -- Reset to original direction
  221. for _ = 1, 4 do
  222. if turtle.suck(0) then
  223. return true -- Chest found
  224. end
  225. turtle.turnLeft() -- Keep turning until a chest is found
  226. end
  227. -- Restore original direction
  228. turtle.turnRight() -- Restore to original facing direction
  229. return false -- No chest found
  230. end
  231.  
  232. if not findChest() then
  233. centerText(8, "No chest found behind the turtle!")
  234. sleep(2)
  235. return
  236. end
  237.  
  238. -- Withdraw diamonds
  239. for i = 1, diamondsToWithdraw do
  240. turtle.select(1) -- Ensure the turtle is ready to suck
  241. turtle.suck(1) -- Try to pull a diamond from the chest
  242. end
  243.  
  244. -- Withdraw gold ingots
  245. for i = 1, goldIngotsToWithdraw do
  246. turtle.select(2) -- Ensure the turtle is ready to suck
  247. turtle.suck(1) -- Try to pull a gold ingot from the chest
  248. end
  249.  
  250. -- Withdraw gold nuggets
  251. for i = 1, goldNuggetsToWithdraw do
  252. turtle.select(3) -- Ensure the turtle is ready to suck
  253. turtle.suck(1) -- Try to pull a gold nugget from the chest
  254. end
  255.  
  256. centerText(8, "Withdrawn: " .. diamondsToWithdraw .. " Diamonds, " .. goldIngotsToWithdraw .. " Gold Ingots, " .. goldNuggetsToWithdraw .. " Gold Nuggets.")
  257. else
  258. centerText(8, "Invalid amount!")
  259. end
  260.  
  261. centerText(10, "Press 'B' to go back or any key to continue...")
  262. local event, key = os.pullEvent("key")
  263. if key == keys.b then
  264. return
  265. end
  266. end
  267.  
  268. -- Main program loop
  269. insertCard()
  270.  
  271. while true do
  272. term.clear()
  273. centerText(4, "Welcome to the Casino!")
  274. centerText(6, "1. Check Balance")
  275. centerText(7, "2. Deposit Credits")
  276. centerText(8, "3. Withdraw Credits")
  277. centerText(9, "4. Exit")
  278. local event, key = os.pullEvent("key")
  279.  
  280. if key == keys.one then
  281. checkBalance()
  282. elseif key == keys.two then
  283. depositCredits()
  284. elseif key == keys.three then
  285. withdrawCredits()
  286. elseif key == keys.four then
  287. insertCard() -- Direct to insert card screen
  288. end
  289. end
Advertisement
Add Comment
Please, Sign In to add comment