Advertisement
skorpion9x

Untitled

Mar 17th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.24 KB | None | 0 0
  1. --[[Global variables--]]
  2.  
  3. deck = {}
  4. deckGUID = 'aef879'
  5. dealerzones = {}
  6. dealerzoneGUIDs = {'4a99b5', '439af7', '8e6a75', '3dad42', 'a80ea9', '05bfd3', '4a7627', '75b7e8'}
  7. dealer = 0
  8. board = {}
  9. boardGUID = '5a1d5c'
  10. dealbutton = {}
  11. dealbuttonGUID = '1745d7'
  12. dealerbutton = {}
  13. dealerbuttonGUID = 'bebe08'
  14. muck = {1.65, 1, 12.75}
  15. newdeckbutton = {}
  16. newdeckbuttonGUID = 'ea1c95'
  17. resetbutton = {}
  18. resetbuttonGUID = 'c3b0f3'
  19. holedealt = false
  20. dealing = false
  21. players = {}
  22.  
  23. --[[ onLoad function --]]
  24.  
  25. function onload ()
  26.  
  27. dealerbutton = getObjectFromGUID(dealerbuttonGUID)
  28. deck = getObjectFromGUID(deckGUID)
  29. board = getObjectFromGUID(boardGUID)
  30. newdeckbutton = getObjectFromGUID(newdeckbuttonGUID)
  31. dealbutton = getObjectFromGUID(dealbuttonGUID)
  32. resetbutton = getObjectFromGUID(resetbuttonGUID)
  33. for i, v in ipairs (dealerzoneGUIDs) do
  34. dealerzones[i] = getObjectFromGUID(v)
  35. end
  36.  
  37.  
  38. local button = {}
  39.  
  40. --[[ If you need to delete the deck (because of duped cards, etc),
  41. use this button to spawn a new one.--]]
  42. button.label = 'New Deck'
  43. button.click_function = "newDeck"
  44. button.function_owner = nil
  45. button.position = {0, 0.09, 0}
  46. button.rotation = {0,180,0}
  47. button.width = 600
  48. button.height = 600
  49. button.font_size = 150
  50. newdeckbutton.createButton(button)
  51.  
  52. --[[ This button deals out cards for each stage of the hand --]]
  53. button = {}
  54. button.label = 'Deal'
  55. button.click_function = "deal"
  56. button.function_owner = nil
  57. button.position = {0, 0.09, 0}
  58. button.rotation = {0,180,0}
  59. button.width = 600
  60. button.height = 600
  61. button.font_size = 300
  62. dealbutton.createButton(button)
  63.  
  64.  
  65. --[[ Resets deck and variables --]]
  66. button = {}
  67. button.label = 'Reset'
  68. button.click_function = "resetGame"
  69. button.function_owner = nil
  70. button.position = {0, 0.09, 0}
  71. button.rotation = {0, 0, 0}
  72. button.width = 600
  73. button.height = 600
  74. button.font_size = 300
  75. resetbutton.createButton(button)
  76.  
  77. end
  78.  
  79. --[[ deal function
  80. Deals the hole if the game is fresh, then determines whether
  81. to deal flop, turn or river based on cards on the board
  82. (assuming no foreign objects are present)--]]
  83.  
  84. function deal()
  85.  
  86. local cards = board.getObjects()
  87. local x = 0
  88.  
  89. for i, v in ipairs (cards) do
  90. --if v.getVar(object, 'type') == "Random Card" then
  91. x = x+1
  92. --end
  93. end
  94.  
  95. if dealing == false then
  96. if holedealt == false then
  97. hole()
  98. else
  99. if x == 0 then
  100. flop ()
  101. elseif x == 3 then
  102. turn ()
  103. elseif x == 4 then
  104. river ()
  105. elseif x == 5 then
  106. resetGame()
  107. else
  108. print('Error: Invalid board', {1,0,0})
  109. end
  110. end
  111. end
  112.  
  113. end
  114.  
  115. --[[find dealer based on location of dealer button --]]
  116.  
  117. function findDealer()
  118.  
  119. local allcolors = {"White", "Red", "Orange", "Yellow", "Green", "Blue", "Purple", "Pink"}
  120.  
  121. --[[ find which zone the dealer button is in --]]
  122. for i, v in ipairs(dealerzones) do
  123.  
  124. local objects = v.getObjects()
  125.  
  126. for j, w in ipairs (objects) do
  127.  
  128. if w == dealerbutton then
  129. dealer = i
  130. print("Dealer button found in seat: ".. allcolors[dealer])
  131. break
  132. end
  133.  
  134. end
  135.  
  136. if dealer>0 then
  137. break
  138. end
  139.  
  140. end
  141.  
  142. if dealer == 0 then
  143. print("Dealer button not found")
  144. end
  145.  
  146. local playersx = getSeatedPlayers()
  147. local g = #playersx --number of seated players
  148.  
  149. --[[ sort players table to match clockwise turn order --]]
  150. for i, v in ipairs (allcolors) do
  151.  
  152. for j, w in ipairs (playersx) do
  153.  
  154. if w == v then
  155. table.insert(players, w)
  156. break
  157. end
  158.  
  159. end
  160.  
  161. end
  162.  
  163. for i, v in ipairs (players) do
  164. if allcolors[dealer] == players[i] then
  165. dealer = i
  166. break
  167. end
  168. end
  169.  
  170. end
  171.  
  172. --[[ deal hole --]]
  173.  
  174. function hole ()
  175.  
  176. dealing = true
  177.  
  178. findDealer()
  179. startLuaCoroutine(nil, 'holeCoroutine')
  180.  
  181. end
  182.  
  183. function holeCoroutine()
  184.  
  185. local x = 0
  186. local y = {}
  187.  
  188. for i = 1, 2 do
  189.  
  190. x = 0
  191.  
  192. for i, v in ipairs (players) do
  193.  
  194. y = dealer + i - x
  195.  
  196. if players[y] then
  197. deck.dealToColor(1, players[y])
  198. else
  199. x = dealer+i-1
  200. y = dealer + i - x
  201. deck.dealToColor(1, players[y])
  202. end
  203.  
  204. for i=1, 5 do
  205. coroutine.yield(0)
  206. end
  207. end
  208.  
  209. end
  210.  
  211. holedealt = true
  212. dealing = false
  213.  
  214. return (1)
  215.  
  216. end
  217.  
  218.  
  219. --[[ deal flop --]]
  220.  
  221. function flop ()
  222.  
  223. dealing = true
  224.  
  225. printToAll ('Flop', {0, 1, 1})
  226.  
  227. startLuaCoroutine(nil, 'flopCoroutine')
  228.  
  229. end
  230.  
  231. function flopCoroutine ()
  232.  
  233. local card1 = {8.55, 1, 12.75}
  234. local card2 = {11.325, 1, 12.75}
  235. local card3 = {14.1, 1, 12.75}
  236.  
  237. deck.dealToColorWithOffset(muck, false, 'White')
  238.  
  239. for i = 1, 20 do
  240. coroutine.yield(0)
  241. end
  242.  
  243. deck.dealToColorWithOffset(card1, true, 'White')
  244.  
  245. for i = 1, 20 do
  246. coroutine.yield(0)
  247. end
  248.  
  249. deck.dealToColorWithOffset(card2, true, 'White')
  250.  
  251. for i = 1, 20 do
  252. coroutine.yield(0)
  253. end
  254.  
  255. deck.dealToColorWithOffset(card3, true, 'White')
  256.  
  257. for i = 0, 30 do
  258. coroutine.yield(0)
  259. end
  260.  
  261. dealing = false
  262.  
  263. return (1)
  264.  
  265. end
  266.  
  267. --[[ deal turn --]]
  268.  
  269. function turn ()
  270.  
  271. dealing = true
  272.  
  273. printToAll("Turn", {0,1,1})
  274.  
  275. startLuaCoroutine(nil, 'turnCoroutine')
  276.  
  277. end
  278.  
  279. function turnCoroutine ()
  280.  
  281. local card4 = {16.875, 1, 12.75}
  282.  
  283. deck.dealToColorWithOffset(muck, false, 'White')
  284.  
  285. for i = 0, 20 do
  286. coroutine.yield(0)
  287. end
  288.  
  289. deck.dealToColorWithOffset(card4, true, 'White')
  290.  
  291. for i = 0, 30 do
  292. coroutine.yield(0)
  293. end
  294.  
  295. dealing = false
  296.  
  297. return (1)
  298.  
  299. end
  300.  
  301. --[[ deal river --]]
  302.  
  303. function river ()
  304.  
  305. dealing = true
  306.  
  307. printToAll("River", {0,1,1})
  308.  
  309. startLuaCoroutine(nil, 'riverCoroutine')
  310.  
  311. end
  312.  
  313. function riverCoroutine ()
  314.  
  315. local card5 = {19.65, 1, 12.75}
  316.  
  317. deck.dealToColorWithOffset(muck, false, 'White')
  318.  
  319. for i = 0, 20 do
  320. coroutine.yield(0)
  321. end
  322.  
  323. deck.dealToColorWithOffset(card5, true, 'White')
  324.  
  325. for i = 0, 30 do
  326. coroutine.yield(0)
  327. end
  328.  
  329. dealing = false
  330.  
  331. return (1)
  332.  
  333. end
  334.  
  335. function newDeck ()
  336.  
  337. deck = spawnObject("Standard Deck", {-9,2,-2.5})
  338.  
  339. end
  340.  
  341. --[[ reset the game --]]
  342.  
  343. function resetGame ()
  344.  
  345. if dealing == false then
  346. dealing = true
  347. deck.reset()
  348. holedealt = false
  349. dealer = 0
  350. players = {}
  351. end
  352.  
  353. startLuaCoroutine(nil, 'resetGameCoroutine')
  354.  
  355. end
  356.  
  357. function resetGameCoroutine()
  358.  
  359. --[[ delay to prevent deal button from being spam-clicked
  360. which caused cards to duplicate --]]
  361. for i = 1, 50 do
  362. coroutine.yield(0)
  363. end
  364.  
  365. dealing = false
  366.  
  367. return (1)
  368.  
  369. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement