Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[Global variables--]]
- deck = {}
- deckGUID = 'aef879'
- dealerzones = {}
- dealerzoneGUIDs = {'4a99b5', '439af7', '8e6a75', '3dad42', 'a80ea9', '05bfd3', '4a7627', '75b7e8'}
- dealer = 0
- board = {}
- boardGUID = '5a1d5c'
- dealbutton = {}
- dealbuttonGUID = '1745d7'
- dealerbutton = {}
- dealerbuttonGUID = 'bebe08'
- muck = {1.65, 1, 12.75}
- newdeckbutton = {}
- newdeckbuttonGUID = 'ea1c95'
- resetbutton = {}
- resetbuttonGUID = 'c3b0f3'
- holedealt = false
- dealing = false
- players = {}
- --[[ onLoad function --]]
- function onload ()
- dealerbutton = getObjectFromGUID(dealerbuttonGUID)
- deck = getObjectFromGUID(deckGUID)
- board = getObjectFromGUID(boardGUID)
- newdeckbutton = getObjectFromGUID(newdeckbuttonGUID)
- dealbutton = getObjectFromGUID(dealbuttonGUID)
- resetbutton = getObjectFromGUID(resetbuttonGUID)
- for i, v in ipairs (dealerzoneGUIDs) do
- dealerzones[i] = getObjectFromGUID(v)
- end
- local button = {}
- --[[ If you need to delete the deck (because of duped cards, etc),
- use this button to spawn a new one.--]]
- button.label = 'New Deck'
- button.click_function = "newDeck"
- button.function_owner = nil
- button.position = {0, 0.09, 0}
- button.rotation = {0,180,0}
- button.width = 600
- button.height = 600
- button.font_size = 150
- newdeckbutton.createButton(button)
- --[[ This button deals out cards for each stage of the hand --]]
- button = {}
- button.label = 'Deal'
- button.click_function = "deal"
- button.function_owner = nil
- button.position = {0, 0.09, 0}
- button.rotation = {0,180,0}
- button.width = 600
- button.height = 600
- button.font_size = 300
- dealbutton.createButton(button)
- --[[ Resets deck and variables --]]
- button = {}
- button.label = 'Reset'
- button.click_function = "resetGame"
- button.function_owner = nil
- button.position = {0, 0.09, 0}
- button.rotation = {0, 0, 0}
- button.width = 600
- button.height = 600
- button.font_size = 300
- resetbutton.createButton(button)
- end
- --[[ deal function
- Deals the hole if the game is fresh, then determines whether
- to deal flop, turn or river based on cards on the board
- (assuming no foreign objects are present)--]]
- function deal()
- local cards = board.getObjects()
- local x = 0
- for i, v in ipairs (cards) do
- --if v.getVar(object, 'type') == "Random Card" then
- x = x+1
- --end
- end
- if dealing == false then
- if holedealt == false then
- hole()
- else
- if x == 0 then
- flop ()
- elseif x == 3 then
- turn ()
- elseif x == 4 then
- river ()
- elseif x == 5 then
- resetGame()
- else
- print('Error: Invalid board', {1,0,0})
- end
- end
- end
- end
- --[[find dealer based on location of dealer button --]]
- function findDealer()
- local allcolors = {"White", "Red", "Orange", "Yellow", "Green", "Blue", "Purple", "Pink"}
- --[[ find which zone the dealer button is in --]]
- for i, v in ipairs(dealerzones) do
- local objects = v.getObjects()
- for j, w in ipairs (objects) do
- if w == dealerbutton then
- dealer = i
- print("Dealer button found in seat: ".. allcolors[dealer])
- break
- end
- end
- if dealer>0 then
- break
- end
- end
- if dealer == 0 then
- print("Dealer button not found")
- end
- local playersx = getSeatedPlayers()
- local g = #playersx --number of seated players
- --[[ sort players table to match clockwise turn order --]]
- for i, v in ipairs (allcolors) do
- for j, w in ipairs (playersx) do
- if w == v then
- table.insert(players, w)
- break
- end
- end
- end
- for i, v in ipairs (players) do
- if allcolors[dealer] == players[i] then
- dealer = i
- break
- end
- end
- end
- --[[ deal hole --]]
- function hole ()
- dealing = true
- findDealer()
- startLuaCoroutine(nil, 'holeCoroutine')
- end
- function holeCoroutine()
- local x = 0
- local y = {}
- for i = 1, 2 do
- x = 0
- for i, v in ipairs (players) do
- y = dealer + i - x
- if players[y] then
- deck.dealToColor(1, players[y])
- else
- x = dealer+i-1
- y = dealer + i - x
- deck.dealToColor(1, players[y])
- end
- for i=1, 5 do
- coroutine.yield(0)
- end
- end
- end
- holedealt = true
- dealing = false
- return (1)
- end
- --[[ deal flop --]]
- function flop ()
- dealing = true
- printToAll ('Flop', {0, 1, 1})
- startLuaCoroutine(nil, 'flopCoroutine')
- end
- function flopCoroutine ()
- local card1 = {8.55, 1, 12.75}
- local card2 = {11.325, 1, 12.75}
- local card3 = {14.1, 1, 12.75}
- deck.dealToColorWithOffset(muck, false, 'White')
- for i = 1, 20 do
- coroutine.yield(0)
- end
- deck.dealToColorWithOffset(card1, true, 'White')
- for i = 1, 20 do
- coroutine.yield(0)
- end
- deck.dealToColorWithOffset(card2, true, 'White')
- for i = 1, 20 do
- coroutine.yield(0)
- end
- deck.dealToColorWithOffset(card3, true, 'White')
- for i = 0, 30 do
- coroutine.yield(0)
- end
- dealing = false
- return (1)
- end
- --[[ deal turn --]]
- function turn ()
- dealing = true
- printToAll("Turn", {0,1,1})
- startLuaCoroutine(nil, 'turnCoroutine')
- end
- function turnCoroutine ()
- local card4 = {16.875, 1, 12.75}
- deck.dealToColorWithOffset(muck, false, 'White')
- for i = 0, 20 do
- coroutine.yield(0)
- end
- deck.dealToColorWithOffset(card4, true, 'White')
- for i = 0, 30 do
- coroutine.yield(0)
- end
- dealing = false
- return (1)
- end
- --[[ deal river --]]
- function river ()
- dealing = true
- printToAll("River", {0,1,1})
- startLuaCoroutine(nil, 'riverCoroutine')
- end
- function riverCoroutine ()
- local card5 = {19.65, 1, 12.75}
- deck.dealToColorWithOffset(muck, false, 'White')
- for i = 0, 20 do
- coroutine.yield(0)
- end
- deck.dealToColorWithOffset(card5, true, 'White')
- for i = 0, 30 do
- coroutine.yield(0)
- end
- dealing = false
- return (1)
- end
- function newDeck ()
- deck = spawnObject("Standard Deck", {-9,2,-2.5})
- end
- --[[ reset the game --]]
- function resetGame ()
- if dealing == false then
- dealing = true
- deck.reset()
- holedealt = false
- dealer = 0
- players = {}
- end
- startLuaCoroutine(nil, 'resetGameCoroutine')
- end
- function resetGameCoroutine()
- --[[ delay to prevent deal button from being spam-clicked
- which caused cards to duplicate --]]
- for i = 1, 50 do
- coroutine.yield(0)
- end
- dealing = false
- return (1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement