sxrgini

Untitled

Nov 3rd, 2024 (edited)
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.33 KB | None | 0 0
  1. -- Casino Card for Casino Machines --
  2. -- Created by iiAmPanda --
  3. -- pastebin get cDaurxvD casinocard(wip) --
  4.  
  5. local collectorFee = 10
  6. local creds = 0
  7. local credsPerDia = 75
  8. local credsPerGoldIngot = 45
  9. local credsPerGoldNugget = 5
  10. local playerName = ""
  11.  
  12. -- Function to center text on the screen
  13. function centerText(y, text)
  14. local width = term.getSize()
  15. term.setCursorPos(math.floor((width - #text) / 2), y)
  16. term.write(text)
  17. end
  18.  
  19. -- Function to wrap and display text within the screen width
  20. function wrapText(y, text)
  21. local width = term.getSize()
  22. for line in text:gmatch(".{1," .. width .. "}") do
  23. term.setCursorPos(1, y)
  24. term.write(line)
  25. y = y + 1
  26. end
  27. return y -- Return the new y position after writing
  28. end
  29.  
  30. -- Function to check if the disk is a Casino Card
  31. function checkForCasinoCard()
  32. return fs.exists("disk/creds.lua")
  33. end
  34.  
  35. -- Function to write card data to disk and update the disk label with credits
  36. function writeCard()
  37. local Card = fs.open("disk/creds.lua", "w")
  38. if not Card then
  39. centerText(8, "Error writing to disk!")
  40. sleep(2)
  41. return
  42. end
  43.  
  44. local data = (tostring(math.random(1, 163456)) .. "11066011" .. tostring(creds) .. "11077011" .. tostring(math.random(1, 163456)))
  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) .. " Credits")
  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. -- Successfully read card, break the loop
  85. centerText(6, "Card inserted successfully!")
  86. sleep(2)
  87. return -- Exit the loop if a valid card is inserted
  88. else
  89. centerText(8, "This isn't a Casino Card.")
  90. sleep(2)
  91. centerText(10, "Would you like to create one? (Y/N)")
  92. local event, key = os.pullEvent("key")
  93. if key == keys.y or key == keys.enter then
  94. term.clear()
  95. centerText(7, "Enter your name:")
  96. playerName = read() -- Prompt for player's name
  97. centerText(8, "Creating a new Casino Card...")
  98. creds = 0 -- Start with 0 credits
  99. writeCard()
  100. centerText(9, "Casino Card created.")
  101. sleep(2)
  102. else
  103. centerText(10, "Please remove the disk.")
  104. sleep(2)
  105. end
  106. end
  107. end
  108. end
  109. end
  110.  
  111. -- Function to check credit balance
  112. function checkBalance()
  113. term.clear()
  114. centerText(4, "Your Balance: " .. creds .. " Credits")
  115. centerText(6, "Press any key to continue...")
  116. os.pullEvent("key")
  117. end
  118.  
  119. -- Function to deposit credits
  120. function depositCredits()
  121. if not checkForCasinoCard() then
  122. centerText(10, "No Casino Card Found.")
  123. sleep(2)
  124. return
  125. end
  126.  
  127. term.clear()
  128. readCard()
  129. centerText(4, "Deposit Credits")
  130. centerText(6, "Diamonds, Gold Ingots, or Gold Nuggets.")
  131.  
  132. local totalCreds = 0
  133.  
  134. -- Function to find the chest behind the turtle
  135. local function findChest()
  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. return false -- No chest found
  143. end
  144.  
  145. if not findChest() then
  146. centerText(8, "No chest found behind the turtle!")
  147. sleep(2)
  148. return
  149. end
  150.  
  151. for i = 1, 16 do
  152. if turtle.getItemCount(i) > 0 then
  153. local slot = turtle.getItemDetail(i)
  154. if slot.name == "minecraft:diamond" then
  155. totalCreds = totalCreds + (slot.count * credsPerDia)
  156. turtle.select(i)
  157. turtle.drop(slot.count) -- Drop diamonds to deposit
  158. elseif slot.name == "minecraft:gold_ingot" then
  159. totalCreds = totalCreds + (slot.count * credsPerGoldIngot)
  160. turtle.select(i)
  161. turtle.drop(slot.count) -- Drop gold ingots to deposit
  162. elseif slot.name == "minecraft:gold_nugget" then
  163. totalCreds = totalCreds + (slot.count * credsPerGoldNugget)
  164. turtle.select(i)
  165. turtle.drop(slot.count) -- Drop gold nuggets to deposit
  166. end
  167. end
  168. end
  169.  
  170. if totalCreds > 0 then
  171. creds = creds + totalCreds
  172. writeCard() -- Update card data and disk label
  173. centerText(8, totalCreds .. " Credits deposited.")
  174. else
  175. centerText(8, "No items to deposit!")
  176. end
  177.  
  178. centerText(10, "Press 'B' to go back or any key to continue...")
  179. local event, key = os.pullEvent("key")
  180. if key == keys.b then
  181. return
  182. end
  183. end
  184.  
  185. -- Function to withdraw credits
  186. function withdrawCredits()
  187. if not checkForCasinoCard() then
  188. centerText(10, "No Casino Card Found.")
  189. sleep(2)
  190. return
  191. end
  192.  
  193. term.clear()
  194. readCard()
  195. if creds <= 0 then -- Check if there are no credits available
  196. centerText(8, "The Bank is Empty!")
  197. centerText(10, "Press any key to return...")
  198. os.pullEvent("key") -- Wait for user input
  199. return
  200. end
  201.  
  202. centerText(4, "Withdraw Credits")
  203. centerText(6, "Enter amount to withdraw:")
  204.  
  205. local amount = tonumber(read())
  206.  
  207. if amount and amount > 0 and amount <= creds then
  208. creds = creds - amount
  209. writeCard() -- Update card data and disk label
  210.  
  211. -- Calculate how many items to withdraw based on credits
  212. local diamondsToWithdraw = math.floor(amount / credsPerDia)
  213. local goldIngotsToWithdraw = math.floor((amount % credsPerDia) / credsPerGoldIngot)
  214. local goldNuggetsToWithdraw = math.floor((amount % credsPerGoldIngot) / credsPerGoldNugget)
  215.  
  216. -- Function to find the chest behind the turtle
  217. local function findChest()
  218. for _ = 1, 4 do
  219. if turtle.suck(0) then
  220. return true -- Chest found
  221. end
  222. turtle.turnLeft() -- Keep turning until a chest is found
  223. end
  224. return false -- No chest found
  225. end
  226.  
  227. if not findChest() then
  228. centerText(8, "No chest found behind the turtle!")
  229. sleep(2)
  230. return
  231. end
  232.  
  233. -- Withdraw diamonds
  234. for i = 1, diamondsToWithdraw do
  235. turtle.select(1) -- Ensure the turtle is ready to suck
  236. turtle.suck(1) -- Try to pull a diamond from the chest
  237. end
  238.  
  239. -- Withdraw gold ingots
  240. for i = 1, goldIngotsToWithdraw do
  241. turtle.select(2) -- Ensure the turtle is ready to suck
  242. turtle.suck(1) -- Try to pull a gold ingot from the chest
  243. end
  244.  
  245. -- Withdraw gold nuggets
  246. for i = 1, goldNuggetsToWithdraw do
  247. turtle.select(3) -- Ensure the turtle is ready to suck
  248. turtle.suck(1) -- Try to pull a gold nugget from the chest
  249. end
  250.  
  251. centerText(8, "Withdrawn: " .. diamondsToWithdraw .. " Diamonds, " .. goldIngotsToWithdraw .. " Gold Ingots, " .. goldNuggetsToWithdraw .. " Gold Nuggets.")
  252. else
  253. centerText(8, "Invalid amount!")
  254. end
  255.  
  256. centerText(10, "Press 'B' to go back or any key to continue...")
  257. local event, key = os.pullEvent("key")
  258. if key == keys.b then
  259. return
  260. end
  261. end
  262.  
Advertisement
Add Comment
Please, Sign In to add comment