Advertisement
Marlingaming

Slot Machine V1 MC CC Tweakes

Dec 8th, 2023 (edited)
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.22 KB | None | 0 0
  1. local Losses = 1
  2. local Jackpot = 0
  3. local Charge = 5
  4.  
  5. local Jackpot_Growth = {0,2}--{mode,number}, mode 0=X Loss, 1 = add each roll, 2 = static, 3 = random per loss
  6.  
  7. local Display_Mode = 0--0=Computer,1=Monitor
  8.  
  9. local Currency = {{"create_deco:brass_coin",64},{"createdeco:iron_coin",16},{"createdeco:copper_coin",1}}
  10.  
  11. local Payment_Box
  12. local Store_Box
  13. local Jackpot_Box
  14.  
  15. local Chance_Sheet
  16. local Win_Sheet
  17. local Roll_Sheet
  18.  
  19. local Monitor
  20.  
  21. function Dispense(amount)
  22. local E = 0
  23. for i = 1, Store_Box.size() do
  24. local Slot = Store_Box.getItemDetail(i)
  25. if E > 0 and Slot ~= nil then local A = Slot.count Store_Box.pushItems(peripheral.getName(Payment_Box),i,E) if E - A < 0 then E = 0 else E = E - A end end
  26. end
  27. end
  28.  
  29. function Jackpot_Dispense()
  30. for i = 1, Jackpot_Box.size() do
  31. Jackpot_Box.pushItems(peripheral.getName(Payment_Box),i)
  32. end
  33. end
  34.  
  35. function Requirements()
  36. local Check = false
  37. local E = 0
  38. for i = 1, Payment_Box.size() do
  39. local Slot = Payment_Box.getItemDetail(i)
  40. for M = 1, #Currency do
  41. if Currency[M][1] == Slot.name then E = E + Currency[M][2] * Slot.count Payment_Box.pushItems(peripheral.getName(Jackpot_Box),i) end
  42. end
  43. end
  44. if E == Charge then Check = true end
  45. return Check
  46. end
  47.  
  48. function UpdateData()
  49. local Data = {Losses, Jackpot, Charge, Display_Mode, Jackpot_Growth}
  50. local file = fs.open("settings.txt","w")
  51. file.write(textutils.serialize(Data))
  52. file.close()
  53. end
  54.  
  55. function Boot()
  56. local file = fs.open("settings.txt","r")
  57. local Data = textutils.unserialize(file.readAll())
  58. Losses, Jackpot, Charge, Display_Mode, Jackpot_Growth = Data[1], Data[2], Data[3], Data[4], Data[5]
  59. file.close()
  60. if Display_Mode == 0 then Monitor = term else Monitor = peripheral.wrap("top") end
  61. if Jackpot_Growth[1] == 2 then Jackpot = Jackpot_Growth[2] end
  62. Start()
  63. end
  64.  
  65. function Display_Menu()
  66. Monitor.clear()
  67. Monitor.setCursorPos(1,1)
  68. Monitor.write("JACKPOT:")
  69. Monitor.setCursorPos(1,2)
  70. Monitor.write("$"..Jackpot)
  71. Monitor.setCursorPos(1,3)
  72. Monitor.write("insert")
  73. Monitor.setCursorPos(1,4)
  74. Monitor.write("$"..Charge)
  75. end
  76.  
  77. function Display_Game(roll)
  78. roll = tostring(roll)
  79. local a, b, c = string.sub(roll,1,1), string.sub(roll,2,2), string.sub(roll,3,3)
  80. Monitor.clear()
  81. Monitor.setCursorPos(1,1)
  82. Monitor.write("SPIN!")
  83. Monitor.setCursorPos(3,2)
  84. Monitor.write("===========")
  85. Monitor.setCursorPos(1,5)
  86. Monitor.write("===========")
  87. Monitor.setCursorPos(3,4)
  88. Monitor.write("["..a.."]|["..b.."]|["..c.."]")
  89. Monitor.setCursorPos(1,6)
  90. Monitor.write("Combos")
  91. local file = fs.open(Win_Sheet,"r")
  92. local Data = textutils.unserialize(file.readAll())
  93. file.close()
  94. for i = 1, #Data do
  95. Monitor.setCursorPos(1,i+6)
  96. Monitor.write(Data[i][1].." : $"..Data[i][2])
  97. end
  98. end
  99.  
  100. function Display_WIN(title,amount)
  101. Monitor.clear()
  102. Monitor.setCursorPos(4,6)
  103. Monitor.write(title)
  104. Monitor.setCursorPos(4,7)
  105. Monitor.write("$"..amount)
  106. end
  107.  
  108. function Spin()
  109. local Result = 0--0=loss,1=win,2=jackpot
  110. local file = fs.open(Chance_Sheet,"r")
  111. local Data = textutils.unserialize(file.readAll())
  112. file.close()
  113. local Roll = math.random(1,100)
  114. if Roll == Data[Losses] then Result = 2 elseif Roll>Data[Losses]-8 and Roll<Data[Losses]+8 then Result = 1 end
  115. local Rolls = fs.open(Roll_Sheet,"r")
  116. local R = textutils.unserialize(Rolls.readAll())
  117. Rolls.close()
  118. for i = math.random(1,5), 8 do
  119. Display_Game(R[i])
  120. os.sleep(2)
  121. end
  122. if Result == 2 then
  123. Display_Game("777")
  124. Losses = 1
  125. os.sleep(2)
  126. Display_WIN("JACKPOT! 777",Jackpot)
  127. Jackpot_Dispense()
  128. os.sleep(3)
  129. Jackpot = 0
  130. elseif Result == 1 then
  131. local Ws = fs.open(Win_Sheet,"r")
  132. local RW = textutils.unserialize(Ws.readAll())
  133. Ws.close()
  134. local WinData = RW[math.random(1,#RW)]
  135. Display_Game(WinData[1])
  136. Losses = 1
  137. os.sleep(2)
  138. Display_WIN("Congratulations!",WinData[2])
  139. Dispense(WinData[2])
  140. os.sleep(3)
  141. elseif Result == 0 then
  142. if Jackpot_Growth[1] == 3 and math.random(1,Jackpot_Growth[2]) == 1 then
  143. Jackpot = Jackpot + Charge
  144. elseif Jackpot_Growth[1] == 0 then
  145. Jackpot = Jackpot_Growth[2] * Losses
  146. end
  147. Losses = Losses + 1
  148. end
  149. if Jackpot_Growth[1] == 1 then
  150. Jackpot = Jackpot + Jackpot_Growth[2]
  151. end
  152. end
  153.  
  154. function Start()
  155. while true do
  156. Display_Menu()
  157. local a, b, c, d, e = os.pullEvent("redstone")
  158. if Requirements() == true then Spin() end
  159. UpdateData()
  160. end
  161. end
  162.  
  163. Boot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement