-- Hello to anyone reading this, and thank you for checking out my Blackjack Dealer AddOn!

-- DISCLAIMER:
-- This was my first attempt at creating a WoW AddOn, and so the code may look messy to more 
-- experienced developers (apologies)!
-- For any questions or queries, you're welcome to add my Battle Tag: Kingett#2160



-- Variables Initially Set
unitName1 = GetRaidRosterInfo(2) or "Seat Empty";
unitName2 = GetRaidRosterInfo(3) or "Seat Empty";
unitName3 = GetRaidRosterInfo(4) or "Seat Empty";
unitName4 = GetRaidRosterInfo(5) or "Seat Empty";
unitName5 = GetRaidRosterInfo(6) or "Seat Empty";

playerName = UnitName("player");

turn = 0
gameRunning = false

Player1Active = false
player1PPSideBetWin = false
player1213SideBetWin = false
player1DoubleToggle = false
player1SplitToggle = false
player1DoubleHand1Toggle = false
player1DoubleHand2Toggle = false
player1totalBetAmount = 0
player1totalWin = 0
player1totalLoss = 0
player1totalProfit = 0
player1TotalBankrollAmount = 0
player1NumberOfCards = 0
player1NumberOfCardsH1 = 0
player1SessionWin = 0
player1Hotstreak = 0
player1MainBet = 0
player1PPBet = 0
player1213Bet = 0

Player2Active = false
player2PPSideBetWin = false
player2213SideBetWin = false
player2DoubleToggle = false
player2DoubleHand1Toggle = false
player2DoubleHand2Toggle = false
player2totalBetAmount = 0
player2totalWin = 0
player2totalLoss = 0
player2totalProfit = 0
player2TotalBankrollAmount = 0

Player3Active = false
player3PPSideBetWin = false
player3213SideBetWin = false
player3DoubleToggle = false
player3DoubleHand1Toggle = false
player3DoubleHand2Toggle = false
player3totalBetAmount = 0
player3totalWin = 0
player3totalLoss = 0
player3totalProfit = 0
player3TotalBankrollAmount = 0

Player4Active = false
player4PPSideBetWin = false
player4213SideBetWin = false
player4DoubleToggle = false
player4DoubleHand1Toggle = false
player4DoubleHand2Toggle = false
player4totalBetAmount = 0
player4totalWin = 0
player4totalLoss = 0
player4totalProfit = 0
player4TotalBankrollAmount = 0

Player5Active = false
player5PPSideBetWin = false
player5213SideBetWin = false
player5DoubleToggle = false
player5DoubleHand1Toggle = false
player5DoubleHand2Toggle = false
player5totalBetAmount = 0
player5totalWin = 0
player5totalLoss = 0
player5totalProfit = 0
player5TotalBankrollAmount = 0

countdownDuration = 30

minBetMain = 50
maxBetMain = 4000
minBetPP = 5
maxBetPP = 500
minBet213 = 5
maxBet213 = 500

drawnCards = {}
dealtCards = {}

local soundFiles = {
    "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
    "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21",
    "1 or 11", -- 22
    "2 or 12", -- 23
    "3 or 13", -- 24
    "4 or 14", -- 25
    "5 or 15", -- 26
    "6 or 16", -- 27
    "7 or 17", -- 28
    "8 or 18", -- 29
    "9 or 19", -- 30
    "10 or 20", -- 31
    "PlayerBlackjack", "PlayerWin", "PlayerLoss", "PlayerBust", -- 32, 33, 34, 35
    "DealerBlackjack", "DealerBust", -- 36, 37
    "Push", -- 38
    "Hit", "Stand", "Double", -- 39, 40, 41
    "DealingCard", "ConfirmBet", -- 42, 43
    "Player1Win", -- 44
    "Player2Win", -- 45
    "Player1Loss", -- 46
    "Player2Loss", -- 47
    "Player1Bust", -- 48
    "Player2Bust", -- 49
    "Player12Win", -- 50
    "Player12Loss", -- 51
    "Player1BJ", -- 52
    "Player2BJ", -- 53
    "Player12Push", -- 54
    "Player1Push", -- 55
    "Player2Push", -- 56
    "Player1SplitWinWin", "Player1SplitWinLoss", "Player1SplitWinPush", -- 57, 58, 59
    "Player1SplitPushWin", "Player1SplitPushLoss", "Player1SplitPushPush", -- 60, 61, 62
    "Player1SplitLossWin", "Player1SplitLossLoss", "Player1SplitLossPush" -- 63, 64, 65
}

local soundFilePaths = {}

for i, fileName in ipairs(soundFiles) do
    soundFilePaths[i] = "Interface\\AddOns\\BlackjackPlayer\\Sounds\\" .. fileName .. ".mp3"
end


local cardNames = {
    ["AD.tga"] = "Ace of Diamonds",
    ["2D.tga"] = "2 of Diamonds",
    ["3D.tga"] = "3 of Diamonds",
    ["4D.tga"] = "4 of Diamonds",
    ["5D.tga"] = "5 of Diamonds",
    ["6D.tga"] = "6 of Diamonds",
    ["7D.tga"] = "7 of Diamonds",
    ["8D.tga"] = "8 of Diamonds",
    ["9D.tga"] = "9 of Diamonds",
    ["10D.tga"] = "10 of Diamonds",
    ["JD.tga"] = "Jack of Diamonds",
    ["QD.tga"] = "Queen of Diamonds",
    ["KD.tga"] = "King of Diamonds",
    ["AH.tga"] = "Ace of Hearts",
    ["2H.tga"] = "2 of Hearts",
    ["3H.tga"] = "3 of Hearts",
    ["4H.tga"] = "4 of Hearts",
    ["5H.tga"] = "5 of Hearts",
    ["6H.tga"] = "6 of Hearts",
    ["7H.tga"] = "7 of Hearts",
    ["8H.tga"] = "8 of Hearts",
    ["9H.tga"] = "9 of Hearts",
    ["10H.tga"] = "10 of Hearts",
    ["JH.tga"] = "Jack of Hearts",
    ["QH.tga"] = "Queen of Hearts",
    ["KH.tga"] = "King of Hearts",
    ["AC.tga"] = "Ace of Clubs",
    ["2C.tga"] = "2 of Clubs",
    ["3C.tga"] = "3 of Clubs",
    ["4C.tga"] = "4 of Clubs",
    ["5C.tga"] = "5 of Clubs",
    ["6C.tga"] = "6 of Clubs",
    ["7C.tga"] = "7 of Clubs",
    ["8C.tga"] = "8 of Clubs",
    ["9C.tga"] = "9 of Clubs",
    ["10C.tga"] = "10 of Clubs",
    ["JC.tga"] = "Jack of Clubs",
    ["QC.tga"] = "Queen of Clubs",
    ["KC.tga"] = "King of Clubs",
    ["AS.tga"] = "Ace of Spades",
    ["2S.tga"] = "2 of Spades",
    ["3S.tga"] = "3 of Spades",
    ["4S.tga"] = "4 of Spades",
    ["5S.tga"] = "5 of Spades",
    ["6S.tga"] = "6 of Spades",
    ["7S.tga"] = "7 of Spades",
    ["8S.tga"] = "8 of Spades",
    ["9S.tga"] = "9 of Spades",
    ["10S.tga"] = "10 of Spades",
    ["JS.tga"] = "Jack of Spades",
    ["QS.tga"] = "Queen of Spades",
    ["KS.tga"] = "King of Spades",
    -- Add more card entries as needed
}

local cardValues = {
    ["AD.tga"] = {1, 11},
    ["2D.tga"] = {2},
    ["3D.tga"] = {3},
    ["4D.tga"] = {4},
    ["5D.tga"] = {5},
    ["6D.tga"] = {6},
    ["7D.tga"] = {7},
    ["8D.tga"] = {8},
    ["9D.tga"] = {9},
    ["10D.tga"] = {10},
    ["JD.tga"] = {10},
    ["QD.tga"] = {10},
    ["KD.tga"] = {10},
    ["AH.tga"] = {1, 11},
    ["2H.tga"] = {2},
    ["3H.tga"] = {3},
    ["4H.tga"] = {4},
    ["5H.tga"] = {5},
    ["6H.tga"] = {6},
    ["7H.tga"] = {7},
    ["8H.tga"] = {8},
    ["9H.tga"] = {9},
    ["10H.tga"] = {10},
    ["JH.tga"] = {10},
    ["QH.tga"] = {10},
    ["KH.tga"] = {10},
    ["AC.tga"] = {1, 11},
    ["2C.tga"] = {2},
    ["3C.tga"] = {3},
    ["4C.tga"] = {4},
    ["5C.tga"] = {5},
    ["6C.tga"] = {6},
    ["7C.tga"] = {7},
    ["8C.tga"] = {8},
    ["9C.tga"] = {9},
    ["10C.tga"] = {10},
    ["JC.tga"] = {10},
    ["QC.tga"] = {10},
    ["KC.tga"] = {10},
    ["AS.tga"] = {1, 11},
    ["2S.tga"] = {2},
    ["3S.tga"] = {3},
    ["4S.tga"] = {4},
    ["5S.tga"] = {5},
    ["6S.tga"] = {6},
    ["7S.tga"] = {7},
    ["8S.tga"] = {8},
    ["9S.tga"] = {9},
    ["10S.tga"] = {10},
    ["JS.tga"] = {10},
    ["QS.tga"] = {10},
    ["KS.tga"] = {10},
}



























-- >> PLAYERFRAME <<
-- >> PLAYERFRAME <<
-- >> PLAYERFRAME <<

-- Creating the main playerFrame
playerFrame = CreateFrame("Frame", "BlackjackPlayerFrame", UIParent, "BasicFrameTemplateWithInset")
playerFrame:SetSize(1280, 720)
playerFrame:SetPoint("CENTER")
playerFrame:SetFrameStrata("HIGH")
playerFrame:SetFrameLevel(1)
playerFrame:Hide()

-- Setting a title
playerFrame.title = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.title:SetPoint("TOP", playerFrame, 0, -5)
playerFrame.title:SetText("Blackjack Player Client v2.4.3 - Developed by Hyrav")

-- Setting background texture (Blackjack Table)
backgroundImage = playerFrame:CreateTexture(nil, "BACKGROUND")
backgroundImage:SetSize(2048, 1024)
backgroundImage:SetPoint("TOP", playerFrame, "TOP", 17, 187)
backgroundImage:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\blackjackplayer.tga")
backgroundImage:SetBlendMode("BLEND")
backgroundImage:SetDrawLayer("ARTWORK")

-- "Rules" button which displays the rules of Blackjack
playerFrame.RulesButton = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.RulesButton:SetPoint("TOPRIGHT", playerFrame, -23, -40)
playerFrame.RulesButton:SetSize(80, 30)
playerFrame.RulesButton:SetText("Rules")

-- "Payouts" button which shows side-bet combinations
playerFrame.payoutsButton = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.payoutsButton:SetPoint("TOPRIGHT", playerFrame, -23, -90)
playerFrame.payoutsButton:SetSize(80, 30)
playerFrame.payoutsButton:SetText("Payouts")

-- "History" button which shows Profit/Loss in real-time
playerFrame.historyButton = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.historyButton:SetPoint("TOPRIGHT", playerFrame, -23, -123)
playerFrame.historyButton:SetSize(80, 30)
playerFrame.historyButton:SetText("History")

-- "Rebet" button which allows players to pre-load bets
playerFrame.rebetButton = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.rebetButton:SetPoint("TOPRIGHT", playerFrame, -23, -155)
playerFrame.rebetButton:SetSize(80, 30)
playerFrame.rebetButton:SetText("Rebet")

-- "Cards" button which shows an enlarged image of dealt cards
playerFrame.cardsButton = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.cardsButton:SetPoint("TOPLEFT", playerFrame, 23, -72)
playerFrame.cardsButton:SetSize(85, 30)
playerFrame.cardsButton:SetText("Cards")

-- "Chat" button which displays all Blackjack related messages from chat
playerFrame.chatLogButton = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.chatLogButton:SetPoint("TOPLEFT", playerFrame, 23, -40)
playerFrame.chatLogButton:SetSize(85, 30)
playerFrame.chatLogButton:SetText("Chat Log")

-- "Leave Table" button
playerFrame.leaveTableButton = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.leaveTableButton:SetPoint("BOTTOMLEFT", playerFrame, 17, 138)
playerFrame.leaveTableButton:SetSize(90, 30)
playerFrame.leaveTableButton:SetText("Leave Table")
playerFrame.leaveTableButton:SetNormalFontObject("GameFontWhiteSmall")
playerFrame.leaveTableButton:SetHighlightFontObject("GameFontWhiteSmall")

-- Disclaimer text below leave table button
playerFrame.DisclaimerText = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.DisclaimerText:SetPoint("BOTTOMLEFT", playerFrame, 18, 75)
playerFrame.DisclaimerText:SetJustifyH("LEFT")
playerFrame.DisclaimerText:SetText("Only stake what you can afford to lose.\nWhen the fun stops - stop immediately.") -- Get the character's name
playerFrame.DisclaimerText:SetTextColor(1 , 0, 0)
playerFrame.DisclaimerText:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")

-- Table limit text in corner
tableLimitText = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
tableLimitText:SetPoint("BOTTOMLEFT", playerFrame, 18, 105)
tableLimitText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
tableLimitText:SetJustifyH("LEFT")
tableLimitText:SetText("Table Limits:    50 G - 4000 G\nSide Bets:           5 G -   500 G")

-- Timer Limit 1
playerFrame.timerText1 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightLarge")
playerFrame.timerText1:SetFont("Fonts\\FRIZQT__.TTF", 20, "OUTLINE")

-- Timer Limit 2
playerFrame.timerText2 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightLarge")
playerFrame.timerText2:SetFont("Fonts\\FRIZQT__.TTF", 18, "OUTLINE")

-- Timer Limit 3
playerFrame.timerText3 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightLarge")
playerFrame.timerText3:SetFont("Fonts\\FRIZQT__.TTF", 18, "OUTLINE")

-- Timer Limit 4
playerFrame.timerText4 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightLarge")
playerFrame.timerText4:SetFont("Fonts\\FRIZQT__.TTF", 18, "OUTLINE")

-- Timer Limit 5
playerFrame.timerText5 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightLarge")
playerFrame.timerText5:SetFont("Fonts\\FRIZQT__.TTF", 18, "OUTLINE")

-- Timer Limit Bets
playerFrame.timerTextBets = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightLarge")
playerFrame.timerTextBets:SetPoint("LEFT", playerFrame, 227, 200)
playerFrame.timerTextBets:SetFont("Fonts\\FRIZQT__.TTF", 40, "OUTLINE")
playerFrame.timerTextBets:SetJustifyH("CENTER")

-- Enabling click-and-drag functionality
playerFrame:SetMovable(true)
playerFrame:EnableMouse(true)
playerFrame:RegisterForDrag("LeftButton")

-- Script for handling the drag of playerFrame
playerFrame:SetScript("OnDragStart", function(self)
    self:StartMoving()
end)

playerFrame:SetScript("OnDragStop", function(self)
    self:StopMovingOrSizing()
end)

-- Bankroll frame in the bottom-left of playerFrame
bankrollFrame = CreateFrame("Frame", "BlackjackBankrollFrame", playerFrame, "GlowBorderTemplate")
bankrollFrame:SetSize(240, 40)
bankrollFrame:SetPoint("BOTTOMLEFT", playerFrame, 18, 18)
bankrollFrame:SetFrameStrata("HIGH")
bankrollFrame:SetFrameLevel(2)

bankrollFrame.player1TotalBankrollTableDisplay = bankrollFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
bankrollFrame.player1TotalBankrollTableDisplay:SetPoint("LEFT", bankrollFrame, 9, 0)
bankrollFrame.player1TotalBankrollTableDisplay:SetJustifyH("LEFT")
bankrollFrame.player1TotalBankrollTableDisplay:SetText("Total Bankroll: 0 G")
bankrollFrame.player1TotalBankrollTableDisplay:SetFont("Fonts\\FRIZQT__.TTF", 16, "OUTLINE")
bankrollFrame.player1TotalBankrollTableDisplay:Hide()

bankrollFrame.player2TotalBankrollTableDisplay = bankrollFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
bankrollFrame.player2TotalBankrollTableDisplay:SetPoint("LEFT", bankrollFrame, 9, 0)
bankrollFrame.player2TotalBankrollTableDisplay:SetJustifyH("LEFT")
bankrollFrame.player2TotalBankrollTableDisplay:SetText("Total Bankroll: 0 G")
bankrollFrame.player2TotalBankrollTableDisplay:SetFont("Fonts\\FRIZQT__.TTF", 16, "OUTLINE")
bankrollFrame.player2TotalBankrollTableDisplay:Hide()

bankrollFrame.player3TotalBankrollTableDisplay = bankrollFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
bankrollFrame.player3TotalBankrollTableDisplay:SetPoint("LEFT", bankrollFrame, 9, 0)
bankrollFrame.player3TotalBankrollTableDisplay:SetJustifyH("LEFT")
bankrollFrame.player3TotalBankrollTableDisplay:SetText("Total Bankroll: 0 G")
bankrollFrame.player3TotalBankrollTableDisplay:SetFont("Fonts\\FRIZQT__.TTF", 16, "OUTLINE")
bankrollFrame.player3TotalBankrollTableDisplay:Hide()

bankrollFrame.player4TotalBankrollTableDisplay = bankrollFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
bankrollFrame.player4TotalBankrollTableDisplay:SetPoint("LEFT", bankrollFrame, 9, 0)
bankrollFrame.player4TotalBankrollTableDisplay:SetJustifyH("LEFT")
bankrollFrame.player4TotalBankrollTableDisplay:SetText("Total Bankroll: 0 G")
bankrollFrame.player4TotalBankrollTableDisplay:SetFont("Fonts\\FRIZQT__.TTF", 16, "OUTLINE")
bankrollFrame.player4TotalBankrollTableDisplay:Hide()

bankrollFrame.player5TotalBankrollTableDisplay = bankrollFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
bankrollFrame.player5TotalBankrollTableDisplay:SetPoint("LEFT", bankrollFrame, 9, 0)
bankrollFrame.player5TotalBankrollTableDisplay:SetJustifyH("LEFT")
bankrollFrame.player5TotalBankrollTableDisplay:SetText("Total Bankroll: 0 G")
bankrollFrame.player5TotalBankrollTableDisplay:SetFont("Fonts\\FRIZQT__.TTF", 16, "OUTLINE")
bankrollFrame.player5TotalBankrollTableDisplay:Hide()

























-- >> CASH DESK <<
-- >> CASH DESK <<
-- >> CASH DESK <<

-- Creating the cashDeskFrame window
cashDeskFrame = CreateFrame("Frame", "BlackjackCashDeskFrame", UIParent, "BasicFrameTemplateWithInset")
cashDeskFrame:SetSize(1280, 720)
cashDeskFrame:SetPoint("CENTER")
cashDeskFrame:SetFrameStrata("HIGH")
cashDeskFrame:SetFrameLevel(1)
cashDeskFrame:Hide()

-- Setting a title
cashDeskFrame.title = cashDeskFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
cashDeskFrame.title:SetPoint("TOP", cashDeskFrame, 0, -5)
cashDeskFrame.title:SetText("Blackjack Player Client v2.4.3 - Developed by Hyrav")

-- Setting background texture (Cash Desk)
cashDeskBackgroundImage = cashDeskFrame:CreateTexture(nil, "BACKGROUND")
cashDeskBackgroundImage:SetSize(1498, 725)
cashDeskBackgroundImage:SetPoint("CENTER", cashDeskFrame, 0, -7)
cashDeskBackgroundImage:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CashDeskBase.tga")
cashDeskBackgroundImage:SetBlendMode("BLEND")
cashDeskBackgroundImage:SetDrawLayer("ARTWORK")

-- Enabling click-and-drag functionality
cashDeskFrame:SetMovable(true)
cashDeskFrame:EnableMouse(true)
cashDeskFrame:RegisterForDrag("LeftButton")

-- Script for handling the drag of CashDeskFrame
cashDeskFrame:SetScript("OnDragStart", function(self)
    self:StartMoving()
end)

cashDeskFrame:SetScript("OnDragStop", function(self)
    self:StopMovingOrSizing()
end)

-- Creating the Buy In button
cashDeskFrame.buyInButton = CreateFrame("Button", nil, cashDeskFrame, "GameMenuButtonTemplate")
cashDeskFrame.buyInButton:SetPoint("CENTER", cashDeskFrame, -130, -150)
cashDeskFrame.buyInButton:SetSize(150, 40)
cashDeskFrame.buyInButton:SetText("Buy-In")

-- Creating the Cash Out button
cashDeskFrame.cashOutButton = CreateFrame("Button", nil, cashDeskFrame, "GameMenuButtonTemplate")
cashDeskFrame.cashOutButton:SetPoint("CENTER", cashDeskFrame, 130, -150)
cashDeskFrame.cashOutButton:SetSize(150, 40)
cashDeskFrame.cashOutButton:SetText("Cash-Out")

-- Buy In Amount
buyInEditBox = CreateFrame("EditBox", nil, cashDeskFrame, "InputBoxTemplate")
buyInEditBox:SetSize(80, 30)
buyInEditBox:SetPoint("CENTER", cashDeskFrame, -135, -115)
buyInEditBox:SetAutoFocus(false)
buyInEditBox:SetNumeric(true)

cashDeskFrame.buyInAmountG = cashDeskFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
cashDeskFrame.buyInAmountG:SetPoint("CENTER", cashDeskFrame, -81, -114)
cashDeskFrame.buyInAmountG:SetText("G")
cashDeskFrame.buyInAmountG:SetJustifyH("CENTER")
cashDeskFrame.buyInAmountG:SetFont("Fonts\\FRIZQT__.TTF", 16, "OUTLINE")

-- Cash Out Amount
cashOutEditBox = CreateFrame("EditBox", nil, cashDeskFrame, "InputBoxTemplate")
cashOutEditBox:SetSize(80, 30)
cashOutEditBox:SetPoint("CENTER", cashDeskFrame, 125, -115)
cashOutEditBox:SetAutoFocus(false)

cashDeskFrame.buyInAmountG = cashDeskFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
cashDeskFrame.buyInAmountG:SetPoint("CENTER", cashDeskFrame, 178, -114)
cashDeskFrame.buyInAmountG:SetText("G")
cashDeskFrame.buyInAmountG:SetJustifyH("CENTER")
cashDeskFrame.buyInAmountG:SetFont("Fonts\\FRIZQT__.TTF", 16, "OUTLINE")

-- Create a "Join Table" button to start the game
cashDeskFrame.joinButtonCashDesk = CreateFrame("Button", nil, cashDeskFrame, "GameMenuButtonTemplate")
cashDeskFrame.joinButtonCashDesk:SetPoint("BOTTOMRIGHT", cashDeskFrame, -25, 45)
cashDeskFrame.joinButtonCashDesk:SetSize(120, 40)
cashDeskFrame.joinButtonCashDesk:SetText("Join Table")
cashDeskFrame.joinButtonCashDesk:Disable()

-- Create a "Back" button to start the game
cashDeskFrame.backButton = CreateFrame("Button", nil, cashDeskFrame, "GameMenuButtonTemplate")
cashDeskFrame.backButton:SetPoint("BOTTOMLEFT", cashDeskFrame, 25, 45)
cashDeskFrame.backButton:SetSize(120, 40)
cashDeskFrame.backButton:SetText("Back")

-- Bankroll
cashDeskFrame.player1TotalBankroll = cashDeskFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
cashDeskFrame.player1TotalBankroll:SetPoint("CENTER", cashDeskFrame, 0, -225)
cashDeskFrame.player1TotalBankroll:SetText("Total Bankroll: 0 G")
cashDeskFrame.player1TotalBankroll:SetJustifyH("CENTER")
cashDeskFrame.player1TotalBankroll:SetFont("Fonts\\FRIZQT__.TTF", 18, "OUTLINE")

-- Bankroll
cashDeskFrame.player2TotalBankroll = cashDeskFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
cashDeskFrame.player2TotalBankroll:SetPoint("CENTER", cashDeskFrame, 0, -225)
cashDeskFrame.player2TotalBankroll:SetText("Total Bankroll: 0 G")
cashDeskFrame.player2TotalBankroll:SetJustifyH("CENTER")
cashDeskFrame.player2TotalBankroll:SetFont("Fonts\\FRIZQT__.TTF", 18, "OUTLINE")

-- Bankroll
cashDeskFrame.player3TotalBankroll = cashDeskFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
cashDeskFrame.player3TotalBankroll:SetPoint("CENTER", cashDeskFrame, 0, -225)
cashDeskFrame.player3TotalBankroll:SetText("Total Bankroll: 0 G")
cashDeskFrame.player3TotalBankroll:SetJustifyH("CENTER")
cashDeskFrame.player3TotalBankroll:SetFont("Fonts\\FRIZQT__.TTF", 18, "OUTLINE")

-- Bankroll
cashDeskFrame.player4TotalBankroll = cashDeskFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
cashDeskFrame.player4TotalBankroll:SetPoint("CENTER", cashDeskFrame, 0, -225)
cashDeskFrame.player4TotalBankroll:SetText("Total Bankroll: 0 G")
cashDeskFrame.player4TotalBankroll:SetJustifyH("CENTER")
cashDeskFrame.player4TotalBankroll:SetFont("Fonts\\FRIZQT__.TTF", 18, "OUTLINE")

-- Bankroll
cashDeskFrame.player5TotalBankroll = cashDeskFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
cashDeskFrame.player5TotalBankroll:SetPoint("CENTER", cashDeskFrame, 0, -225)
cashDeskFrame.player5TotalBankroll:SetText("Total Bankroll: 0 G")
cashDeskFrame.player5TotalBankroll:SetJustifyH("CENTER")
cashDeskFrame.player5TotalBankroll:SetFont("Fonts\\FRIZQT__.TTF", 18, "OUTLINE")

-- Player 1 Buy-In Function
local function player1BuyIn()
    player1BuyInAmount = tonumber(buyInEditBox:GetText())
    if player1BuyInAmount and player1BuyInAmount >= minBetMain then

        buyInEditBox:SetFocus(false)
        buyInEditBox:ClearFocus()
        
        player1BuyInAmountGoldValue = player1BuyInAmount * 10000

        local chatFrame = SELECTED_DOCK_FRAME
        ChatFrame_OpenChat("/trade", chatFrame)
        local editBox = _G[chatFrame:GetName().."EditBox"]
        editBox:Insert("/trade")
        ChatEdit_SendText(editBox)
        C_Timer.After(1, function()
            if TradeFrame:IsShown() then
                -- Set the copper amount in the trade window
                MoneyInputFrame_SetCopper(TradePlayerInputMoneyFrame, player1BuyInAmountGoldValue)
                PlaySoundFile(soundFilePaths[43])
                -- Send the chat message only if the trade window is open
                SendChatMessage("{square} [P1] Buy-In for " .. player1BuyInAmount .. "G.", "RAID")
            end
        end)
    else
        print("Please enter a value of at least 50G.")
    end

end

-- Player 1 Cash-Out Function
local function player1CashOut()
    player1CashOutAmount = tonumber(cashOutEditBox:GetText()) -- Get the entered bet amount
    player1currentBankroll = tonumber(string.match(cashDeskFrame.player1TotalBankroll:GetText(), "%d+"))

    if player1CashOutAmount <= player1currentBankroll then

        cashOutEditBox:SetFocus(false)
        cashOutEditBox:ClearFocus()
        

        local chatFrame = SELECTED_DOCK_FRAME
        ChatFrame_OpenChat("/trade", chatFrame)
        local editBox = _G[chatFrame:GetName().."EditBox"]
        editBox:Insert("/trade")
        ChatEdit_SendText(editBox)

        C_Timer.After(1, function()
            if TradeFrame:IsShown() then
                PlaySoundFile(soundFilePaths[43])
                SendChatMessage("{square} [P1] Cash-Out for " .. player1CashOutAmount .. "G.", "RAID")
            end
        end)
     
    else
        print("You don't have that much in your bankroll. Please choose a lower amount.")
    end

end

-- Player 2 Buy-In Function
local function player2BuyIn()
    player2BuyInAmount = tonumber(buyInEditBox:GetText()) -- Get the entered bet amount
    if player2BuyInAmount and player2BuyInAmount >= minBetMain then
        
        buyInEditBox:SetFocus(false)
        buyInEditBox:ClearFocus()
        
        
        player2BuyInAmountGoldValue = player2BuyInAmount * 10000

        local chatFrame = SELECTED_DOCK_FRAME
        ChatFrame_OpenChat("/trade", chatFrame)
        local editBox = _G[chatFrame:GetName().."EditBox"]
        editBox:Insert("/trade")
        ChatEdit_SendText(editBox)
        C_Timer.After(1, function()
            if TradeFrame:IsShown() then
                -- Set the copper amount in the trade window
                MoneyInputFrame_SetCopper(TradePlayerInputMoneyFrame, player2BuyInAmountGoldValue)
                PlaySoundFile(soundFilePaths[43])
                -- Send the chat message only if the trade window is open
                SendChatMessage("{square} [P2] Buy-In for " .. player2BuyInAmount .. "G.", "RAID")
            end
        end)
    else
        print("Please enter a value of at least 50G.")
    end

end

-- Player 2 Cash-Out Function
local function player2CashOut()
    player2CashOutAmount = tonumber(cashOutEditBox:GetText()) -- Get the entered bet amount
    player2currentBankroll = tonumber(string.match(cashDeskFrame.player2TotalBankroll:GetText(), "%d+"))

    if player2CashOutAmount <= player2currentBankroll then

        cashOutEditBox:SetFocus(false)
        cashOutEditBox:ClearFocus()
        

        local chatFrame = SELECTED_DOCK_FRAME
        ChatFrame_OpenChat("/trade", chatFrame)
        local editBox = _G[chatFrame:GetName().."EditBox"]
        editBox:Insert("/trade")
        ChatEdit_SendText(editBox)

        C_Timer.After(1, function()
            if TradeFrame:IsShown() then
                SendChatMessage("{square} [P2] Cash-Out for " .. player2CashOutAmount .. "G.", "RAID")

                player2TotalBankrollAmount = player2currentBankroll - player2CashOutAmount
                bankrollFrame.player2TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")
                cashDeskFrame.player2TotalBankroll:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")
            end
        end)
     
    else
        print("You don't have that much in your bankroll. Please choose a lower amount.")
    end

end

-- Player 3 Buy-In Function
local function player3BuyIn()
    player3BuyInAmount = tonumber(buyInEditBox:GetText()) -- Get the entered bet amount
    if player3BuyInAmount and player3BuyInAmount >= minBetMain then
        
        buyInEditBox:SetFocus(false)
        buyInEditBox:ClearFocus()
        PlaySoundFile(soundFilePaths[43])
        
        player3BuyInAmountGoldValue = player3BuyInAmount * 10000

        local chatFrame = SELECTED_DOCK_FRAME
        ChatFrame_OpenChat("/trade", chatFrame)
        local editBox = _G[chatFrame:GetName().."EditBox"]
        editBox:Insert("/trade")
        ChatEdit_SendText(editBox)
        C_Timer.After(1, function()
            if TradeFrame:IsShown() then
                -- Set the copper amount in the trade window
                MoneyInputFrame_SetCopper(TradePlayerInputMoneyFrame, player3BuyInAmountGoldValue)
                
                -- Send the chat message only if the trade window is open
                SendChatMessage("{square} [P3] Buy-In for " .. player3BuyInAmount .. "G.", "RAID")
            end
        end)
    else
        print("Please enter a value of at least 50G.")
    end

end

-- Player 4 Buy-In Function
local function player4BuyIn()
    player4BuyInAmount = tonumber(buyInEditBox:GetText()) -- Get the entered bet amount
    if player4BuyInAmount and player4BuyInAmount >= minBetMain then
        
        buyInEditBox:SetFocus(false)
        buyInEditBox:ClearFocus()
        PlaySoundFile(soundFilePaths[43])
        
        player4BuyInAmountGoldValue = player4BuyInAmount * 10000

        local chatFrame = SELECTED_DOCK_FRAME
        ChatFrame_OpenChat("/trade", chatFrame)
        local editBox = _G[chatFrame:GetName().."EditBox"]
        editBox:Insert("/trade")
        ChatEdit_SendText(editBox)
        C_Timer.After(1, function()
            if TradeFrame:IsShown() then
                -- Set the copper amount in the trade window
                MoneyInputFrame_SetCopper(TradePlayerInputMoneyFrame, player4BuyInAmountGoldValue)
                
                -- Send the chat message only if the trade window is open
                SendChatMessage("{square} [P4] Buy-In for " .. player4BuyInAmount .. "G.", "RAID")
            end
        end)
    else
        print("Please enter a value of at least 50G.")
    end

end

-- Player 5 Buy-In Function
local function player5BuyIn()
    player5BuyInAmount = tonumber(buyInEditBox:GetText()) -- Get the entered bet amount
    if player5BuyInAmount and player5BuyInAmount >= minBetMain then
        
        buyInEditBox:SetFocus(false)
        buyInEditBox:ClearFocus()
        PlaySoundFile(soundFilePaths[43])
        
        player5BuyInAmountGoldValue = player5BuyInAmount * 10000

        local chatFrame = SELECTED_DOCK_FRAME
        ChatFrame_OpenChat("/trade", chatFrame)
        local editBox = _G[chatFrame:GetName().."EditBox"]
        editBox:Insert("/trade")
        ChatEdit_SendText(editBox)
        C_Timer.After(1, function()
            if TradeFrame:IsShown() then
                -- Set the copper amount in the trade window
                MoneyInputFrame_SetCopper(TradePlayerInputMoneyFrame, player5BuyInAmountGoldValue)
                
                -- Send the chat message only if the trade window is open
                SendChatMessage("{square} [P5] Buy-In for " .. player5BuyInAmount .. "G.", "RAID")
            end
        end)
    else
        print("Please enter a value of at least 50G.")
    end

end

-- Buy-In Instructions Frame
stepsFrame = CreateFrame("Frame", "BlackjackStepsFrame", UIParent, "BasicFrameTemplate")
stepsFrame:SetSize(300, 250)
stepsFrame:SetPoint("LEFT", cashDeskFrame, 5, 40)
stepsFrame:SetFrameStrata("HIGH")
stepsFrame:SetFrameLevel(5)
stepsFrame:Hide()

stepsFrame.title = stepsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
stepsFrame.title:SetPoint("TOP", stepsFrame, 0, -5)
stepsFrame.title:SetText("Buy-In Instructions")

stepsFrame.dealerImage = stepsFrame:CreateTexture(nil, "OVERLAY")
stepsFrame.dealerImage:SetSize(256, 128)
stepsFrame.dealerImage:SetPoint("CENTER", stepsFrame, 0, 13)
stepsFrame.dealerImage:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\DealerTarget.tga")
stepsFrame.dealerImage:SetBlendMode("BLEND")
stepsFrame.dealerImage:SetDrawLayer("ARTWORK")

stepsFrame.step1Title = stepsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
stepsFrame.step1Title:SetPoint("CENTER", stepsFrame, 0, 83)
stepsFrame.step1Title:SetText("STEP 1")
stepsFrame.step1Title:SetJustifyH("CENTER")
stepsFrame.step1Title:SetTextColor(1, 0.298, 0.298)
stepsFrame.step1Title:SetFont("Fonts\\FRIZQT__.TTF", 14, "OUTLINE")

stepsFrame.step1Text = stepsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
stepsFrame.step1Text:SetPoint("CENTER", stepsFrame, 0, 67)
stepsFrame.step1Text:SetText("Target the Dealer (Blackjackk)")
stepsFrame.step1Text:SetJustifyH("CENTER")
stepsFrame.step1Text:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")

stepsFrame.step2Title = stepsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
stepsFrame.step2Title:SetPoint("CENTER", stepsFrame, 0, -35)
stepsFrame.step2Title:SetText("STEP 2")
stepsFrame.step2Title:SetJustifyH("CENTER")
stepsFrame.step2Title:SetTextColor(1, 0.298, 0.298)
stepsFrame.step2Title:SetFont("Fonts\\FRIZQT__.TTF", 14, "OUTLINE")

stepsFrame.step2Text = stepsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
stepsFrame.step2Text:SetPoint("CENTER", stepsFrame, 0, -51)
stepsFrame.step2Text:SetText("Type in an amount (50G minimum)")
stepsFrame.step2Text:SetJustifyH("CENTER")
stepsFrame.step2Text:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")

stepsFrame.step3Title = stepsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
stepsFrame.step3Title:SetPoint("CENTER", stepsFrame, 0, -84)
stepsFrame.step3Title:SetText("STEP 3")
stepsFrame.step3Title:SetJustifyH("CENTER")
stepsFrame.step3Title:SetTextColor(1, 0.298, 0.298)
stepsFrame.step3Title:SetFont("Fonts\\FRIZQT__.TTF", 14, "OUTLINE")

stepsFrame.step3Text = stepsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
stepsFrame.step3Text:SetPoint("CENTER", stepsFrame, 0, -100)
stepsFrame.step3Text:SetText("Press the 'Buy-In' button")
stepsFrame.step3Text:SetJustifyH("CENTER")
stepsFrame.step3Text:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")

-- Cash-Out Instructions Frame
stepsFrame2 = CreateFrame("Frame", "BlackjackStepsFrame", UIParent, "BasicFrameTemplate")
stepsFrame2:SetSize(300, 250)
stepsFrame2:SetPoint("RIGHT", cashDeskFrame, -5, 40)
stepsFrame2:SetFrameStrata("HIGH")
stepsFrame2:SetFrameLevel(5)
stepsFrame2:Hide()

stepsFrame2.title = stepsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
stepsFrame2.title:SetPoint("TOP", stepsFrame2, 0, -5)
stepsFrame2.title:SetText("Cash-Out Instructions")

stepsFrame2.dealerImage2 = stepsFrame2:CreateTexture(nil, "OVERLAY")
stepsFrame2.dealerImage2:SetSize(256, 128)
stepsFrame2.dealerImage2:SetPoint("CENTER", stepsFrame2, 0, 13)
stepsFrame2.dealerImage2:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\DealerTarget.tga")
stepsFrame2.dealerImage2:SetBlendMode("BLEND")
stepsFrame2.dealerImage2:SetDrawLayer("ARTWORK")

stepsFrame2.step1Title2 = stepsFrame2:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
stepsFrame2.step1Title2:SetPoint("CENTER", stepsFrame2, 0, 83)
stepsFrame2.step1Title2:SetText("STEP 1")
stepsFrame2.step1Title2:SetJustifyH("CENTER")
stepsFrame2.step1Title2:SetTextColor(1, 0.298, 0.298)
stepsFrame2.step1Title2:SetFont("Fonts\\FRIZQT__.TTF", 14, "OUTLINE")

stepsFrame2.step1Text2 = stepsFrame2:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
stepsFrame2.step1Text2:SetPoint("CENTER", stepsFrame2, 0, 67)
stepsFrame2.step1Text2:SetText("Target the Dealer (Blackjackk)")
stepsFrame2.step1Text2:SetJustifyH("CENTER")
stepsFrame2.step1Text2:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")

stepsFrame2.step2Title2 = stepsFrame2:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
stepsFrame2.step2Title2:SetPoint("CENTER", stepsFrame2, 0, -35)
stepsFrame2.step2Title2:SetText("STEP 2")
stepsFrame2.step2Title2:SetJustifyH("CENTER")
stepsFrame2.step2Title2:SetTextColor(1, 0.298, 0.298)
stepsFrame2.step2Title2:SetFont("Fonts\\FRIZQT__.TTF", 14, "OUTLINE")

stepsFrame2.step2Text2 = stepsFrame2:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
stepsFrame2.step2Text2:SetPoint("CENTER", stepsFrame2, 0, -51)
stepsFrame2.step2Text2:SetText("Type in any amount (within your bankroll)")
stepsFrame2.step2Text2:SetJustifyH("CENTER")
stepsFrame2.step2Text2:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")

stepsFrame2.step3Title2 = stepsFrame2:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
stepsFrame2.step3Title2:SetPoint("CENTER", stepsFrame2, 0, -84)
stepsFrame2.step3Title2:SetText("STEP 3")
stepsFrame2.step3Title2:SetJustifyH("CENTER")
stepsFrame2.step3Title2:SetTextColor(1, 0.298, 0.298)
stepsFrame2.step3Title2:SetFont("Fonts\\FRIZQT__.TTF", 14, "OUTLINE")

stepsFrame2.step3Text2 = stepsFrame2:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
stepsFrame2.step3Text2:SetPoint("CENTER", stepsFrame2, 0, -100)
stepsFrame2.step3Text2:SetText("Press the 'Cash-Out' button")
stepsFrame2.step3Text2:SetJustifyH("CENTER")
stepsFrame2.step3Text2:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")

cashDeskFrame:SetScript("OnHide", function(self)
    stepsFrame:Hide()
    stepsFrame2:Hide()
end)




























-- >> INITIAL FRAME <<
-- >> INITIAL FRAME <<
-- >> INITIAL FRAME <<

-- Create a frame for the initial screen
initialFrame = CreateFrame("Frame", "BlackjackInitialFrame", UIParent, "BasicFrameTemplateWithInset")
initialFrame:SetSize(400, 230)
initialFrame:SetPoint("CENTER")
initialFrame:Hide()

-- Add a title to the initial frame
initialFrame.title = initialFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
initialFrame.title:SetPoint("TOP", initialFrame, 0, -5)
initialFrame.title:SetText("Welcome to Blackjack!")

-- Create a "Reload Table" button to start the game
initialFrame.reloadButton = CreateFrame("Button", nil, initialFrame, "GameMenuButtonTemplate")
initialFrame.reloadButton:SetPoint("CENTER", initialFrame, 0, 0)
initialFrame.reloadButton:SetSize(120, 30)
initialFrame.reloadButton:SetText("Reload")

-- Create a "Join Table" button to start the game
initialFrame.cashDeskButton = CreateFrame("Button", nil, initialFrame, "GameMenuButtonTemplate")
initialFrame.cashDeskButton:SetPoint("CENTER", initialFrame, 0, -31)
initialFrame.cashDeskButton:SetSize(120, 30)
initialFrame.cashDeskButton:SetText("Cash Desk")

-- Create a "Join Table" button to start the game
initialFrame.joinButton = CreateFrame("Button", nil, initialFrame, "GameMenuButtonTemplate")
initialFrame.joinButton:SetPoint("CENTER", initialFrame, 0, -62)
initialFrame.joinButton:SetSize(120, 30)
initialFrame.joinButton:SetText("Join Table")
initialFrame.joinButton:Disable()

-- Create a font string to display the join instructions
initialFrame.join1Text = initialFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
initialFrame.join1Text:SetPoint("TOP", initialFrame, 0, -40)
initialFrame.join1Text:SetText("You will be able to play\nonce the dealer has opened up a table\n\nPlease hit the 'Reload' button before playing")
initialFrame.join1Text:SetJustifyH("CENTER")
initialFrame.join1Text:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")

-- Create a font string to display the developer
initialFrame.join3Text = initialFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
initialFrame.join3Text:SetPoint("BOTTOM", initialFrame, 0, 15)
initialFrame.join3Text:SetText("Blackjack Player v2.4.3  |  Developed by Hyrav")
initialFrame.join3Text:SetJustifyH("CENTER")
initialFrame.join3Text:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
initialFrame.join3Text:SetTextColor(1, 0.5, 0)

-- Enable click-and-drag functionality
initialFrame:SetMovable(true)
initialFrame:EnableMouse(true)
initialFrame:RegisterForDrag("LeftButton")

-- Set the frame's script for handling the drag
initialFrame:SetScript("OnDragStart", function(self)
    self:StartMoving()
end)

initialFrame:SetScript("OnDragStop", function(self)
    self:StopMovingOrSizing()
end)

-- Function to enable the "Join Table" button
local function EnableJoinButton()
    initialFrame.joinButton:Enable()
    cashDeskFrame.joinButtonCashDesk:Enable()
end

-- Add a click event handler to the "Join Table" button
initialFrame.reloadButton:SetScript("OnClick", function(self, button, down)
    local chatFrame = SELECTED_DOCK_FRAME
    ChatFrame_OpenChat("/reload", chatFrame)
    local editBox = _G[chatFrame:GetName().."EditBox"]
    editBox:Insert("/reload")
    ChatEdit_SendText(editBox)
    SendChatMessage("Initiating..", "RAID")
end)





























-- >> REBET WINDOW <<
-- >> REBET WINDOW <<
-- >> REBET WINDOW <<

-- Rebet window
rebetFrame = CreateFrame("Frame", "BlackjackPayoutsFrame", UIParent, "InsetFrameTemplate")
rebetFrame:SetSize(170, 140)
rebetFrame:SetPoint("TOPRIGHT", playerFrame, -118, -43)
rebetFrame:SetFrameStrata("HIGH")
rebetFrame:SetFrameLevel(8)
rebetFrame:Hide()

-- Setting a title
rebetFrame.title = rebetFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
rebetFrame.title:SetPoint("TOP", rebetFrame, 0, -7)
rebetFrame.title:SetText("Preload Bets")

-- Main Bet Text
rebetFrame.preloadMainBetText = rebetFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
rebetFrame.preloadMainBetText:SetPoint("LEFT", rebetFrame, 12, 30)
rebetFrame.preloadMainBetText:SetJustifyH("LEFT")
rebetFrame.preloadMainBetText:SetText("Main Bet:")
rebetFrame.preloadMainBetText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
rebetFrame.preloadMainBetText:Hide()

-- PP Side Bet Text
rebetFrame.preloadPPBetText = rebetFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
rebetFrame.preloadPPBetText:SetPoint("LEFT", rebetFrame, 12, 8)
rebetFrame.preloadPPBetText:SetJustifyH("LEFT")
rebetFrame.preloadPPBetText:SetText("PP Side Bet:")
rebetFrame.preloadPPBetText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
rebetFrame.preloadPPBetText:Hide()

-- PP Side Bet Text
rebetFrame.preload213BetText = rebetFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
rebetFrame.preload213BetText:SetPoint("LEFT", rebetFrame, 12, -14)
rebetFrame.preload213BetText:SetJustifyH("LEFT")
rebetFrame.preload213BetText:SetText("21+3 Side Bet:")
rebetFrame.preload213BetText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
rebetFrame.preload213BetText:Hide()

-- Wagers for Player 1
-- Main Bet
player1PreloadEditBoxMainBet = CreateFrame("EditBox", nil, rebetFrame, "InputBoxTemplate")
player1PreloadEditBoxMainBet:SetSize(55, 30)
player1PreloadEditBoxMainBet:SetPoint("LEFT", rebetFrame, 102, 30)
player1PreloadEditBoxMainBet:SetAutoFocus(false)
player1PreloadEditBoxMainBet:SetNumeric(true)
player1PreloadEditBoxMainBet:Hide()
-- Perfect Pairs
player1PreloadEditBoxPPBet = CreateFrame("EditBox", nil, rebetFrame, "InputBoxTemplate")
player1PreloadEditBoxPPBet:SetSize(35, 30)
player1PreloadEditBoxPPBet:SetPoint("LEFT", rebetFrame, 121, 8)
player1PreloadEditBoxPPBet:SetAutoFocus(false)
player1PreloadEditBoxPPBet:SetNumeric(true)
player1PreloadEditBoxPPBet:Hide()
-- 21+3
player1PreloadEditBox213Bet = CreateFrame("EditBox", nil, rebetFrame, "InputBoxTemplate")
player1PreloadEditBox213Bet:SetSize(35, 30)
player1PreloadEditBox213Bet:SetPoint("LEFT", rebetFrame, 121, -14)
player1PreloadEditBox213Bet:SetAutoFocus(false)
player1PreloadEditBox213Bet:SetNumeric(true)
player1PreloadEditBox213Bet:Hide()

-- Player 1 Preload Bet button
player1PreloadBetButton = CreateFrame("Button", nil, rebetFrame, "GameMenuButtonTemplate")
player1PreloadBetButton:SetPoint("BOTTOM", rebetFrame, 1, 13)
player1PreloadBetButton:SetSize(85, 25)
player1PreloadBetButton:SetText("Bet All")
player1PreloadBetButton:Hide()

-- Wagers for Player 2
-- Main Bet
player2PreloadEditBoxMainBet = CreateFrame("EditBox", nil, rebetFrame, "InputBoxTemplate")
player2PreloadEditBoxMainBet:SetSize(55, 30)
player2PreloadEditBoxMainBet:SetPoint("LEFT", rebetFrame, 102, 30)
player2PreloadEditBoxMainBet:SetAutoFocus(false)
player2PreloadEditBoxMainBet:SetNumeric(true)
player2PreloadEditBoxMainBet:Hide()
-- Perfect Pairs
player2PreloadEditBoxPPBet = CreateFrame("EditBox", nil, rebetFrame, "InputBoxTemplate")
player2PreloadEditBoxPPBet:SetSize(35, 30)
player2PreloadEditBoxPPBet:SetPoint("LEFT", rebetFrame, 121, 8)
player2PreloadEditBoxPPBet:SetAutoFocus(false)
player2PreloadEditBoxPPBet:SetNumeric(true)
player2PreloadEditBoxPPBet:Hide()
-- 21+3
player2PreloadEditBox213Bet = CreateFrame("EditBox", nil, rebetFrame, "InputBoxTemplate")
player2PreloadEditBox213Bet:SetSize(35, 30)
player2PreloadEditBox213Bet:SetPoint("LEFT", rebetFrame, 121, -14)
player2PreloadEditBox213Bet:SetAutoFocus(false)
player2PreloadEditBox213Bet:SetNumeric(true)
player2PreloadEditBox213Bet:Hide()

-- Player 2 Preload Bet button
player2PreloadBetButton = CreateFrame("Button", nil, rebetFrame, "GameMenuButtonTemplate")
player2PreloadBetButton:SetPoint("BOTTOM", rebetFrame, 1, 13)
player2PreloadBetButton:SetSize(85, 25)
player2PreloadBetButton:SetText("Bet All")
player2PreloadBetButton:Hide()


























-- >> HISTORY WINDOW <<
-- >> HISTORY WINDOW <<
-- >> HISTORY WINDOW <<

-- History window
historyFrame = CreateFrame("Frame", "BlackjackPayoutsFrame", UIParent, "InsetFrameTemplate")
historyFrame:SetSize(246, 105)
historyFrame:SetPoint("TOP", playerFrame, 2, -26)
historyFrame:SetFrameStrata("HIGH")
historyFrame:SetFrameLevel(8)
historyFrame:Hide()

-- Setting a title
historyFrame.title = historyFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
historyFrame.title:SetPoint("TOP", historyFrame, 0, -9)
historyFrame.title:SetText("Profit/Loss")

-- Total Wagered Text
historyFrame.totalWageredText = historyFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
historyFrame.totalWageredText:SetPoint("CENTER", historyFrame, -42, 12)
historyFrame.totalWageredText:SetJustifyH("RIGHT")
historyFrame.totalWageredText:SetText("Total Wagered:")
historyFrame.totalWageredText:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
historyFrame.totalWageredText:Hide()

-- Total Wagered Amount
historyFrame.player1totalWageredAmount = historyFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
historyFrame.player1totalWageredAmount:SetPoint("CENTER", historyFrame, 40, 12)
historyFrame.player1totalWageredAmount:SetJustifyH("LEFT")
historyFrame.player1totalWageredAmount:SetText("0 G")
historyFrame.player1totalWageredAmount:SetTextColor(1, 0.98, 0.557)
historyFrame.player1totalWageredAmount:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
historyFrame.player1totalWageredAmount:Hide()

historyFrame.player2totalWageredAmount = historyFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
historyFrame.player2totalWageredAmount:SetPoint("CENTER", historyFrame, 40, 12)
historyFrame.player2totalWageredAmount:SetJustifyH("LEFT")
historyFrame.player2totalWageredAmount:SetText("0 G")
historyFrame.player2totalWageredAmount:SetTextColor(1, 0.98, 0.557)
historyFrame.player2totalWageredAmount:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
historyFrame.player2totalWageredAmount:Hide()

-- Total Won Text
historyFrame.totalWonText = historyFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
historyFrame.totalWonText:SetPoint("CENTER", historyFrame, -30, -3)
historyFrame.totalWonText:SetJustifyH("RIGHT")
historyFrame.totalWonText:SetText("Total Won:")
historyFrame.totalWonText:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
historyFrame.totalWonText:Hide()

-- Total Won Amount
historyFrame.player1totalWonAmount = historyFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
historyFrame.player1totalWonAmount:SetPoint("CENTER", historyFrame, 40, -3)
historyFrame.player1totalWonAmount:SetJustifyH("LEFT")
historyFrame.player1totalWonAmount:SetText("0 G")
historyFrame.player1totalWonAmount:SetTextColor(1, 0.98, 0.557)
historyFrame.player1totalWonAmount:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
historyFrame.player1totalWonAmount:Hide()

historyFrame.player2totalWonAmount = historyFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
historyFrame.player2totalWonAmount:SetPoint("CENTER", historyFrame, 40, -3)
historyFrame.player2totalWonAmount:SetJustifyH("LEFT")
historyFrame.player2totalWonAmount:SetText("0 G")
historyFrame.player2totalWonAmount:SetTextColor(1, 0.98, 0.557)
historyFrame.player2totalWonAmount:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
historyFrame.player2totalWonAmount:Hide()

-- Total Lost Text
historyFrame.totalLostText = historyFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
historyFrame.totalLostText:SetPoint("CENTER", historyFrame, -28, -18)
historyFrame.totalLostText:SetJustifyH("RIGHT")
historyFrame.totalLostText:SetText("Total Lost:")
historyFrame.totalLostText:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
historyFrame.totalLostText:Hide()

-- Total Lost Amount
historyFrame.player1totalLostAmount = historyFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
historyFrame.player1totalLostAmount:SetPoint("CENTER", historyFrame, 40, -18)
historyFrame.player1totalLostAmount:SetJustifyH("LEFT")
historyFrame.player1totalLostAmount:SetText("0 G")
historyFrame.player1totalLostAmount:SetTextColor(1, 0.98, 0.557)
historyFrame.player1totalLostAmount:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
historyFrame.player1totalLostAmount:Hide()

historyFrame.player2totalLostAmount = historyFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
historyFrame.player2totalLostAmount:SetPoint("CENTER", historyFrame, 40, -18)
historyFrame.player2totalLostAmount:SetJustifyH("LEFT")
historyFrame.player2totalLostAmount:SetText("0 G")
historyFrame.player2totalLostAmount:SetTextColor(1, 0.98, 0.557)
historyFrame.player2totalLostAmount:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
historyFrame.player2totalLostAmount:Hide()

-- Profit Text
historyFrame.ProfitText = historyFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
historyFrame.ProfitText:SetPoint("CENTER", historyFrame, -16, -33)
historyFrame.ProfitText:SetJustifyH("RIGHT")
historyFrame.ProfitText:SetText("Profit:")
historyFrame.ProfitText:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
historyFrame.ProfitText:Hide()

-- Total Profit Amount
historyFrame.player1ProfitAmount = historyFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
historyFrame.player1ProfitAmount:SetPoint("CENTER", historyFrame, 40, -33)
historyFrame.player1ProfitAmount:SetJustifyH("LEFT")
historyFrame.player1ProfitAmount:SetText("0 G")
historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
historyFrame.player1ProfitAmount:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
historyFrame.player1ProfitAmount:Hide()

historyFrame.player2ProfitAmount = historyFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
historyFrame.player2ProfitAmount:SetPoint("CENTER", historyFrame, 40, -33)
historyFrame.player2ProfitAmount:SetJustifyH("LEFT")
historyFrame.player2ProfitAmount:SetText("0 G")
historyFrame.player2ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
historyFrame.player2ProfitAmount:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
historyFrame.player2ProfitAmount:Hide()





















-- >> RULES WINDOW <<
-- >> RULES WINDOW <<
-- >> RULES WINDOW <<

-- Rules window
-- Creating the rulesFrame
rulesFrame = CreateFrame("Frame", "BlackjackPayoutsFrame", UIParent, "InsetFrameTemplate")
rulesFrame:SetSize(900, 546)
rulesFrame:SetPoint("CENTER", playerFrame, 0, 0)
rulesFrame:SetFrameStrata("HIGH")
rulesFrame:SetFrameLevel(10)
rulesFrame:Hide()

-- Setting a title
rulesFrame.title = rulesFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
rulesFrame.title:SetPoint("TOP", rulesFrame, 0, -8)
rulesFrame.title:SetText("Blackjack Rules")

-- Text1
rulesFrame.rulesText1 = rulesFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
rulesFrame.rulesText1:SetPoint("TOP", rulesFrame, 20, -50)
rulesFrame.rulesText1:SetJustifyH("CENTER")
rulesFrame.rulesText1:SetText("Blackjack (otherwise known as '21') is a popular card game. The goal is to beat the dealer by having\n a hand value closer to 21 than the dealer's hand, without going over 21. Here are the basic rules:")
rulesFrame.rulesText1:SetFont("Fonts\\FRIZQT__.TTF", 14, "OUTLINE")
rulesFrame.rulesText1:Hide()

-- "Card Values" Heading
rulesFrame.HeadingText1 = rulesFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
rulesFrame.HeadingText1:SetPoint("CENTER", rulesFrame, -340, 150)
rulesFrame.HeadingText1:SetJustifyH("CENTER")
rulesFrame.HeadingText1:SetText("1. Card Values")
rulesFrame.HeadingText1:SetTextColor(1, 0.298, 0.298)
rulesFrame.HeadingText1:SetFont("Fonts\\FRIZQT__.TTF", 18, "OUTLINE")
rulesFrame.HeadingText1:Hide()

-- Text2
rulesFrame.rulesText2 = rulesFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
rulesFrame.rulesText2:SetPoint("CENTER", rulesFrame, -231, 100)
rulesFrame.rulesText2:SetJustifyH("LEFT")
rulesFrame.rulesText2:SetText("• Number cards (2-10) are worth their face value\n• Face cards (Jack, Queen, King) are each worth 10 points\n• Aces can be worth 1 or 11 points\n\nThe dealer uses the '/roll 1-13' in-game command\nto decide the card, which ensures a 100% random result")
rulesFrame.rulesText2:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
rulesFrame.rulesText2:Hide()

-- Text3
rulesFrame.rulesText3 = rulesFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
rulesFrame.rulesText3:SetPoint("CENTER", rulesFrame, -353, 10)
rulesFrame.rulesText3:SetJustifyH("LEFT")
rulesFrame.rulesText3:SetTextColor(0.969, 0.961, 0.42)
rulesFrame.rulesText3:SetText("1 = 1 or 11 (Ace)\n2 = 2\n3 = 3\n4 = 4\n5 = 5\n6 = 6\n7 = 7")
rulesFrame.rulesText3:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
rulesFrame.rulesText3:Hide()

-- Text4
rulesFrame.rulesText4 = rulesFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
rulesFrame.rulesText4:SetPoint("CENTER", rulesFrame, -210, 15)
rulesFrame.rulesText4:SetJustifyH("LEFT")
rulesFrame.rulesText4:SetTextColor(0.969, 0.961, 0.42)
rulesFrame.rulesText4:SetText("8 = 8\n9 = 9\n10 = 10\n11 = 10 (Jack)\n12 = 10 (Queen)\n13 = 10 (King)")
rulesFrame.rulesText4:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
rulesFrame.rulesText4:Hide()

-- "Starting the Game" Heading
rulesFrame.HeadingText2 = rulesFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
rulesFrame.HeadingText2:SetPoint("CENTER", rulesFrame, -308, -65)
rulesFrame.HeadingText2:SetJustifyH("CENTER")
rulesFrame.HeadingText2:SetText("2. Starting the Game")
rulesFrame.HeadingText2:SetTextColor(1, 0.298, 0.298)
rulesFrame.HeadingText2:SetFont("Fonts\\FRIZQT__.TTF", 18, "OUTLINE")
rulesFrame.HeadingText2:Hide()

-- Text5
rulesFrame.rulesText5 = rulesFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
rulesFrame.rulesText5:SetPoint("CENTER", rulesFrame, -229, -105)
rulesFrame.rulesText5:SetJustifyH("LEFT")
rulesFrame.rulesText5:SetText("• Players place their bets (within the table limits) and trade\n the dealer the total amount of gold\n• Each player receives two cards - the dealer only receives\n one card (known as the 'upcard')")
rulesFrame.rulesText5:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
rulesFrame.rulesText5:Hide()

-- "Player's Turn" Heading
rulesFrame.HeadingText3 = rulesFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
rulesFrame.HeadingText3:SetPoint("CENTER", rulesFrame, -333, -160)
rulesFrame.HeadingText3:SetJustifyH("CENTER")
rulesFrame.HeadingText3:SetText("3. Player's Turn")
rulesFrame.HeadingText3:SetTextColor(1, 0.298, 0.298)
rulesFrame.HeadingText3:SetFont("Fonts\\FRIZQT__.TTF", 18, "OUTLINE")
rulesFrame.HeadingText3:Hide()

-- Text6
rulesFrame.rulesText6 = rulesFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
rulesFrame.rulesText6:SetPoint("CENTER", rulesFrame, -233, -206)
rulesFrame.rulesText6:SetJustifyH("LEFT")
rulesFrame.rulesText6:SetText("• Players decide to 'Hit' (take another card), 'Stand'\n (keep their current total) or 'Double' (double their bet for\n one extra card only)\n• Players can continue to hit as many times as they like\n but if they exceed 21, they bust and lose the round")
rulesFrame.rulesText6:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
rulesFrame.rulesText6:Hide()

-- "Dealer's Turn" Heading
rulesFrame.HeadingText4 = rulesFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
rulesFrame.HeadingText4:SetPoint("CENTER", rulesFrame, 124, 150)
rulesFrame.HeadingText4:SetJustifyH("CENTER")
rulesFrame.HeadingText4:SetText("4. Dealer's Turn")
rulesFrame.HeadingText4:SetTextColor(1, 0.298, 0.298)
rulesFrame.HeadingText4:SetFont("Fonts\\FRIZQT__.TTF", 18, "OUTLINE")
rulesFrame.HeadingText4:Hide()

-- Text7
rulesFrame.rulesText7 = rulesFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
rulesFrame.rulesText7:SetPoint("CENTER", rulesFrame, 217, 117)
rulesFrame.rulesText7:SetJustifyH("LEFT")
rulesFrame.rulesText7:SetText("• Once all players have finished their turns, the dealer\n will begin their turn\n• The dealer must hit until their hand totals 17 or higher")
rulesFrame.rulesText7:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
rulesFrame.rulesText7:Hide()

-- "Win / Push / Loss" Heading
rulesFrame.HeadingText5 = rulesFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
rulesFrame.HeadingText5:SetPoint("CENTER", rulesFrame, 145, 64)
rulesFrame.HeadingText5:SetJustifyH("CENTER")
rulesFrame.HeadingText5:SetText("5. Win / Push / Loss")
rulesFrame.HeadingText5:SetTextColor(1, 0.298, 0.298)
rulesFrame.HeadingText5:SetFont("Fonts\\FRIZQT__.TTF", 18, "OUTLINE")
rulesFrame.HeadingText5:Hide()

-- "WIN" Heading
rulesFrame.HeadingText6 = rulesFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
rulesFrame.HeadingText6:SetPoint("CENTER", rulesFrame, 70, 42)
rulesFrame.HeadingText6:SetJustifyH("CENTER")
rulesFrame.HeadingText6:SetText("WIN:")
rulesFrame.HeadingText6:SetTextColor(0.325, 0.98, 0.365)
rulesFrame.HeadingText6:SetFont("Fonts\\FRIZQT__.TTF", 14, "OUTLINE")
rulesFrame.HeadingText6:Hide()

-- Text8
rulesFrame.rulesText8 = rulesFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
rulesFrame.rulesText8:SetPoint("CENTER", rulesFrame, 221, 1)
rulesFrame.rulesText8:SetJustifyH("LEFT")
rulesFrame.rulesText8:SetText("• If the players hand is closer to 21 (without going over)\n than the dealer\n• If the dealer busts (goes over 21)\n• If the player has Blackjack (see below) and the dealer's\n upcard is not an Ace or 10")
rulesFrame.rulesText8:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
rulesFrame.rulesText8:Hide()

-- "PUSH" Heading
rulesFrame.HeadingText7 = rulesFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
rulesFrame.HeadingText7:SetPoint("CENTER", rulesFrame, 75, -48)
rulesFrame.HeadingText7:SetJustifyH("CENTER")
rulesFrame.HeadingText7:SetText("PUSH:")
rulesFrame.HeadingText7:SetTextColor(0.275, 0.635, 1)
rulesFrame.HeadingText7:SetFont("Fonts\\FRIZQT__.TTF", 14, "OUTLINE")
rulesFrame.HeadingText7:Hide()

-- Text9
rulesFrame.rulesText9 = rulesFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
rulesFrame.rulesText9:SetPoint("CENTER", rulesFrame, 217, -72)
rulesFrame.rulesText9:SetJustifyH("LEFT")
rulesFrame.rulesText9:SetText("• If the player and dealer have the same hand value, it's\n a push (a tie), and the players bet is returned")
rulesFrame.rulesText9:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
rulesFrame.rulesText9:Hide()

-- "LOSS" Heading
rulesFrame.HeadingText8 = rulesFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
rulesFrame.HeadingText8:SetPoint("CENTER", rulesFrame, 74, -105)
rulesFrame.HeadingText8:SetJustifyH("CENTER")
rulesFrame.HeadingText8:SetText("LOSS:")
rulesFrame.HeadingText8:SetTextColor(1, 0.212, 0.212)
rulesFrame.HeadingText8:SetFont("Fonts\\FRIZQT__.TTF", 14, "OUTLINE")
rulesFrame.HeadingText8:Hide()

-- Text10
rulesFrame.rulesText10 = rulesFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
rulesFrame.rulesText10:SetPoint("CENTER", rulesFrame, 204, -134)
rulesFrame.rulesText10:SetJustifyH("LEFT")
rulesFrame.rulesText10:SetText("• If the players hand is less than the dealer (without\n going over 21)\n• If the player busts (goes over 21)")
rulesFrame.rulesText10:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
rulesFrame.rulesText10:Hide()

-- "Blackjack" Heading
rulesFrame.HeadingText9 = rulesFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
rulesFrame.HeadingText9:SetPoint("CENTER", rulesFrame, 107, -182)
rulesFrame.HeadingText9:SetJustifyH("CENTER")
rulesFrame.HeadingText9:SetText("6. Blackjack")
rulesFrame.HeadingText9:SetTextColor(1, 0.298, 0.298)
rulesFrame.HeadingText9:SetFont("Fonts\\FRIZQT__.TTF", 18, "OUTLINE")
rulesFrame.HeadingText9:Hide()

-- Text11
rulesFrame.rulesText11 = rulesFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
rulesFrame.rulesText11:SetPoint("CENTER", rulesFrame, 209, -217)
rulesFrame.rulesText11:SetJustifyH("LEFT")
rulesFrame.rulesText11:SetText("• A 'Blackjack' is a special hand consisting of an Ace\n and a 10-point card. It pays out at 3:2 instead of a\n regular 1:1 win")
rulesFrame.rulesText11:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
rulesFrame.rulesText11:Hide()



























-- >> PAYOUTS WINDOW <<
-- >> PAYOUTS WINDOW <<
-- >> PAYOUTS WINDOW <<

-- Payouts window
-- Creating the payoutsFrame
payoutsFrame = CreateFrame("Frame", "BlackjackPayoutsFrame", UIParent, "BasicFrameTemplateWithInset")
payoutsFrame:SetSize(275, 720)
payoutsFrame:SetPoint("LEFT", playerFrame, 0, 0)
payoutsFrame:SetFrameStrata("HIGH")
payoutsFrame:SetFrameLevel(4)
payoutsFrame:Hide()

-- Setting a title
payoutsFrame.title = payoutsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
payoutsFrame.title:SetPoint("TOP", payoutsFrame, 0, -5)
payoutsFrame.title:SetText("Payouts")

-- Headings
-- Main Bets
payoutsFrame.mainBetsTitle = payoutsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
payoutsFrame.mainBetsTitle:SetPoint("TOPLEFT", payoutsFrame, 15, -36)
payoutsFrame.mainBetsTitle:SetJustifyH("LEFT")
payoutsFrame.mainBetsTitle:SetText("Main Bets")
payoutsFrame.mainBetsTitle:SetFont("Fonts\\FRIZQT__.TTF", 16, "OUTLINE")
payoutsFrame.mainBetsTitle:SetTextColor(1, 0, 0)
payoutsFrame.mainBetsTitle:Hide()
-- Side Bets
payoutsFrame.sideBetsTitle = payoutsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
payoutsFrame.sideBetsTitle:SetPoint("TOPLEFT", payoutsFrame, 15, -135)
payoutsFrame.sideBetsTitle:SetJustifyH("LEFT")
payoutsFrame.sideBetsTitle:SetText("Side Bets")
payoutsFrame.sideBetsTitle:SetFont("Fonts\\FRIZQT__.TTF", 16, "OUTLINE")
payoutsFrame.sideBetsTitle:SetTextColor(1, 0, 0)
payoutsFrame.sideBetsTitle:Hide()
-- Perfect Pairs
payoutsFrame.perfectPairsTitle = payoutsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
payoutsFrame.perfectPairsTitle:SetPoint("TOPLEFT", payoutsFrame, 15, -155)
payoutsFrame.perfectPairsTitle:SetJustifyH("LEFT")
payoutsFrame.perfectPairsTitle:SetText("Perfect Pairs (PP)")
payoutsFrame.perfectPairsTitle:SetTextColor(1, 0.298, 0.298)
payoutsFrame.perfectPairsTitle:SetFont("Fonts\\FRIZQT__.TTF", 14, "OUTLINE")
payoutsFrame.perfectPairsTitle:Hide()
-- Perfect Pairs (explain)
payoutsFrame.perfectPairsExplain = payoutsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
payoutsFrame.perfectPairsExplain:SetPoint("TOPLEFT", payoutsFrame, 147, -156)
payoutsFrame.perfectPairsExplain:SetJustifyH("LEFT")
payoutsFrame.perfectPairsExplain:SetText("(Player's 2 Cards)")
payoutsFrame.perfectPairsExplain:SetTextColor(1, 0.298, 0.298)
payoutsFrame.perfectPairsExplain:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
payoutsFrame.perfectPairsExplain:Hide()
-- 21+3
payoutsFrame.t213Title = payoutsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
payoutsFrame.t213Title:SetPoint("TOPLEFT", payoutsFrame, 15, -325)
payoutsFrame.t213Title:SetJustifyH("LEFT")
payoutsFrame.t213Title:SetText("21+3")
payoutsFrame.t213Title:SetTextColor(1, 0.298, 0.298)
payoutsFrame.t213Title:SetFont("Fonts\\FRIZQT__.TTF", 14, "OUTLINE")
payoutsFrame.t213Title:Hide()
-- 21+3 (explain)
payoutsFrame.t213Explain = payoutsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
payoutsFrame.t213Explain:SetPoint("TOPLEFT", payoutsFrame, 62, -327)
payoutsFrame.t213Explain:SetJustifyH("LEFT")
payoutsFrame.t213Explain:SetText("(Player's 2 Cards + Dealer's Upcard)")
payoutsFrame.t213Explain:SetTextColor(1, 0.298, 0.298)
payoutsFrame.t213Explain:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
payoutsFrame.t213Explain:Hide()
-- 21+3 (explain) 2
payoutsFrame.t213Explain2 = payoutsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
payoutsFrame.t213Explain2:SetPoint("TOPLEFT", payoutsFrame, 198, -370)
payoutsFrame.t213Explain2:SetJustifyH("RIGHT")
payoutsFrame.t213Explain2:SetText("Any Card\n\nSame Suit")
payoutsFrame.t213Explain2:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
payoutsFrame.t213Explain2:Hide()
-- 21+3 (explain) 3
payoutsFrame.t213Explain3 = payoutsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
payoutsFrame.t213Explain3:SetPoint("TOPLEFT", payoutsFrame, 176, -444)
payoutsFrame.t213Explain3:SetJustifyH("RIGHT")
payoutsFrame.t213Explain3:SetText("Numeric Order\n\nAny Suit")
payoutsFrame.t213Explain3:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
payoutsFrame.t213Explain3:Hide()
-- 21+3 (explain) 4
payoutsFrame.t213Explain4 = payoutsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
payoutsFrame.t213Explain4:SetPoint("TOPLEFT", payoutsFrame, 198, -519)
payoutsFrame.t213Explain4:SetJustifyH("RIGHT")
payoutsFrame.t213Explain4:SetText("Same Card\n\nAny Suit")
payoutsFrame.t213Explain4:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
payoutsFrame.t213Explain4:Hide()
-- 21+3 (explain) 5
payoutsFrame.t213Explain5 = payoutsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
payoutsFrame.t213Explain5:SetPoint("TOPLEFT", payoutsFrame, 176, -589)
payoutsFrame.t213Explain5:SetJustifyH("RIGHT")
payoutsFrame.t213Explain5:SetText("Numeric Order\n\nSame Suit")
payoutsFrame.t213Explain5:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
payoutsFrame.t213Explain5:Hide()
-- 21+3 (explain) 6
payoutsFrame.t213Explain6 = payoutsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
payoutsFrame.t213Explain6:SetPoint("TOPLEFT", payoutsFrame, 198, -663)
payoutsFrame.t213Explain6:SetJustifyH("RIGHT")
payoutsFrame.t213Explain6:SetText("Same Card\n\nSame Suit")
payoutsFrame.t213Explain6:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
payoutsFrame.t213Explain6:Hide()

-- Subheadings and Payouts
-- Standard
payoutsFrame.mainBetStandard = payoutsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
payoutsFrame.mainBetStandard:SetPoint("TOPLEFT", payoutsFrame, 15, -60)
payoutsFrame.mainBetStandard:SetJustifyH("LEFT")
payoutsFrame.mainBetStandard:SetText("Standard")
payoutsFrame.mainBetStandard:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
payoutsFrame.mainBetStandard:Hide()
-- Standard 1:1
payoutsFrame.standardPayout = payoutsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
payoutsFrame.standardPayout:SetPoint("TOPLEFT", payoutsFrame, 87, -93)
payoutsFrame.standardPayout:SetJustifyH("LEFT")
payoutsFrame.standardPayout:SetText("1:1")
payoutsFrame.standardPayout:SetTextColor(1, 0.973, 0.4)
payoutsFrame.standardPayout:SetFont("Fonts\\FRIZQT__.TTF", 16, "OUTLINE")
payoutsFrame.standardPayout:Hide()
-- Blackjack
payoutsFrame.mainBetBlackjack = payoutsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
payoutsFrame.mainBetBlackjack:SetPoint("TOPLEFT", payoutsFrame, 137, -60)
payoutsFrame.mainBetBlackjack:SetJustifyH("LEFT")
payoutsFrame.mainBetBlackjack:SetText("Blackjack")
payoutsFrame.mainBetBlackjack:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
payoutsFrame.mainBetBlackjack:Hide()
-- Blackjack 3:2
payoutsFrame.blackjackPayout = payoutsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
payoutsFrame.blackjackPayout:SetPoint("TOPLEFT", payoutsFrame, 214, -93)
payoutsFrame.blackjackPayout:SetJustifyH("LEFT")
payoutsFrame.blackjackPayout:SetText("3:2")
payoutsFrame.blackjackPayout:SetTextColor(1, 0.973, 0.4)
payoutsFrame.blackjackPayout:SetFont("Fonts\\FRIZQT__.TTF", 16, "OUTLINE")
payoutsFrame.blackjackPayout:Hide()
-- (PP) Mixed Pair
payoutsFrame.mixedPairPP = payoutsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
payoutsFrame.mixedPairPP:SetPoint("TOPLEFT", payoutsFrame, 15, -175)
payoutsFrame.mixedPairPP:SetJustifyH("LEFT")
payoutsFrame.mixedPairPP:SetText("Mixed Pair")
payoutsFrame.mixedPairPP:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
payoutsFrame.mixedPairPP:Hide()
-- (PP) Mixed Pair 5:1
payoutsFrame.mixedPairPayout = payoutsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
payoutsFrame.mixedPairPayout:SetPoint("TOPLEFT", payoutsFrame, 89, -208)
payoutsFrame.mixedPairPayout:SetJustifyH("LEFT")
payoutsFrame.mixedPairPayout:SetText("5:1")
payoutsFrame.mixedPairPayout:SetTextColor(1, 0.973, 0.4)
payoutsFrame.mixedPairPayout:SetFont("Fonts\\FRIZQT__.TTF", 16, "OUTLINE")
payoutsFrame.mixedPairPayout:Hide()
-- (PP) Coloured Pair
payoutsFrame.colouredPairPP = payoutsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
payoutsFrame.colouredPairPP:SetPoint("TOPLEFT", payoutsFrame, 138, -175)
payoutsFrame.colouredPairPP:SetJustifyH("LEFT")
payoutsFrame.colouredPairPP:SetText("Coloured Pair")
payoutsFrame.colouredPairPP:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
payoutsFrame.colouredPairPP:Hide()
-- (PP) Coloured Pair 10:1
payoutsFrame.colouredPairPayout = payoutsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
payoutsFrame.colouredPairPayout:SetPoint("TOPLEFT", payoutsFrame, 212, -208)
payoutsFrame.colouredPairPayout:SetJustifyH("LEFT")
payoutsFrame.colouredPairPayout:SetText("10:1")
payoutsFrame.colouredPairPayout:SetTextColor(1, 0.973, 0.4)
payoutsFrame.colouredPairPayout:SetFont("Fonts\\FRIZQT__.TTF", 16, "OUTLINE")
payoutsFrame.colouredPairPayout:Hide()
-- (PP) Perfect Pair
payoutsFrame.perfectPairPP = payoutsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
payoutsFrame.perfectPairPP:SetPoint("TOPLEFT", payoutsFrame, 15, -248)
payoutsFrame.perfectPairPP:SetJustifyH("LEFT")
payoutsFrame.perfectPairPP:SetText("Perfect Pair")
payoutsFrame.perfectPairPP:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
payoutsFrame.perfectPairPP:Hide()
-- (PP) Perfect Pair 30:1
payoutsFrame.perfectPairPayout = payoutsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
payoutsFrame.perfectPairPayout:SetPoint("TOPLEFT", payoutsFrame, 89, -280)
payoutsFrame.perfectPairPayout:SetJustifyH("LEFT")
payoutsFrame.perfectPairPayout:SetText("30:1")
payoutsFrame.perfectPairPayout:SetTextColor(1, 0.973, 0.4)
payoutsFrame.perfectPairPayout:SetFont("Fonts\\FRIZQT__.TTF", 16, "OUTLINE")
payoutsFrame.perfectPairPayout:Hide()
-- Flush
payoutsFrame.flush213 = payoutsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
payoutsFrame.flush213:SetPoint("TOPLEFT", payoutsFrame, 15, -345)
payoutsFrame.flush213:SetJustifyH("LEFT")
payoutsFrame.flush213:SetText("Flush")
payoutsFrame.flush213:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
payoutsFrame.flush213:Hide()
-- Flush 5:1
payoutsFrame.flushPayout = payoutsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
payoutsFrame.flushPayout:SetPoint("TOPLEFT", payoutsFrame, 124, -377)
payoutsFrame.flushPayout:SetJustifyH("LEFT")
payoutsFrame.flushPayout:SetText("5:1")
payoutsFrame.flushPayout:SetTextColor(1, 0.973, 0.4)
payoutsFrame.flushPayout:SetFont("Fonts\\FRIZQT__.TTF", 16, "OUTLINE")
payoutsFrame.flushPayout:Hide()
-- Straight
payoutsFrame.straight213 = payoutsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
payoutsFrame.straight213:SetPoint("TOPLEFT", payoutsFrame, 15, -417)
payoutsFrame.straight213:SetJustifyH("LEFT")
payoutsFrame.straight213:SetText("Straight")
payoutsFrame.straight213:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
payoutsFrame.straight213:Hide()
-- Straight 10:1
payoutsFrame.straightPayout = payoutsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
payoutsFrame.straightPayout:SetPoint("TOPLEFT", payoutsFrame, 123, -450)
payoutsFrame.straightPayout:SetJustifyH("LEFT")
payoutsFrame.straightPayout:SetText("10:1")
payoutsFrame.straightPayout:SetTextColor(1, 0.973, 0.4)
payoutsFrame.straightPayout:SetFont("Fonts\\FRIZQT__.TTF", 16, "OUTLINE")
payoutsFrame.straightPayout:Hide()
-- Three of a Kind
payoutsFrame.threeOfAKind213 = payoutsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
payoutsFrame.threeOfAKind213:SetPoint("TOPLEFT", payoutsFrame, 15, -491)
payoutsFrame.threeOfAKind213:SetJustifyH("LEFT")
payoutsFrame.threeOfAKind213:SetText("Three of a Kind")
payoutsFrame.threeOfAKind213:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
payoutsFrame.threeOfAKind213:Hide()
-- Three of a Kind 30:1
payoutsFrame.threeOfAKindPayout = payoutsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
payoutsFrame.threeOfAKindPayout:SetPoint("TOPLEFT", payoutsFrame, 125, -525)
payoutsFrame.threeOfAKindPayout:SetJustifyH("LEFT")
payoutsFrame.threeOfAKindPayout:SetText("30:1")
payoutsFrame.threeOfAKindPayout:SetTextColor(1, 0.973, 0.4)
payoutsFrame.threeOfAKindPayout:SetFont("Fonts\\FRIZQT__.TTF", 16, "OUTLINE")
payoutsFrame.threeOfAKindPayout:Hide()
-- Straight Flush
payoutsFrame.straightFlush213 = payoutsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
payoutsFrame.straightFlush213:SetPoint("TOPLEFT", payoutsFrame, 15, -563)
payoutsFrame.straightFlush213:SetJustifyH("LEFT")
payoutsFrame.straightFlush213:SetText("Straight Flush")
payoutsFrame.straightFlush213:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
payoutsFrame.straightFlush213:Hide()
-- Straight Flush 40:1
payoutsFrame.straightFlushPayout = payoutsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
payoutsFrame.straightFlushPayout:SetPoint("TOPLEFT", payoutsFrame, 124, -595)
payoutsFrame.straightFlushPayout:SetJustifyH("LEFT")
payoutsFrame.straightFlushPayout:SetText("40:1")
payoutsFrame.straightFlushPayout:SetTextColor(1, 0.973, 0.4)
payoutsFrame.straightFlushPayout:SetFont("Fonts\\FRIZQT__.TTF", 16, "OUTLINE")
payoutsFrame.straightFlushPayout:Hide()
-- Suited Three of a Kind
payoutsFrame.suitedThreeOfAKind213 = payoutsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
payoutsFrame.suitedThreeOfAKind213:SetPoint("TOPLEFT", payoutsFrame, 15, -637)
payoutsFrame.suitedThreeOfAKind213:SetJustifyH("LEFT")
payoutsFrame.suitedThreeOfAKind213:SetText("Suited Three of a Kind")
payoutsFrame.suitedThreeOfAKind213:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
payoutsFrame.suitedThreeOfAKind213:Hide()
-- Suited Three of a Kind 100:1
payoutsFrame.suitedThreeOfAKindPayout = payoutsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
payoutsFrame.suitedThreeOfAKindPayout:SetPoint("TOPLEFT", payoutsFrame, 123, -669)
payoutsFrame.suitedThreeOfAKindPayout:SetJustifyH("LEFT")
payoutsFrame.suitedThreeOfAKindPayout:SetText("100:1")
payoutsFrame.suitedThreeOfAKindPayout:SetTextColor(1, 0.973, 0.4)
payoutsFrame.suitedThreeOfAKindPayout:SetFont("Fonts\\FRIZQT__.TTF", 16, "OUTLINE")
payoutsFrame.suitedThreeOfAKindPayout:Hide()

-- Creating card textures
-- Standard 1
payoutsFrame.card1image = payoutsFrame:CreateTexture(nil, "OVERLAY")
payoutsFrame.card1image:SetSize(32, 64)
payoutsFrame.card1image:SetPoint("TOPLEFT", payoutsFrame, 17, -70)
payoutsFrame.card1image:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\JH.tga")
payoutsFrame.card1image:SetBlendMode("BLEND")
payoutsFrame.card1image:SetDrawLayer("ARTWORK")
payoutsFrame.card1image:Hide()
-- Standard 2
payoutsFrame.card2image = payoutsFrame:CreateTexture(nil, "OVERLAY")
payoutsFrame.card2image:SetSize(32, 64)
payoutsFrame.card2image:SetPoint("TOPLEFT", payoutsFrame, 52, -70)
payoutsFrame.card2image:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\8S.tga")
payoutsFrame.card2image:SetBlendMode("BLEND")
payoutsFrame.card2image:SetDrawLayer("ARTWORK")
payoutsFrame.card2image:Hide()
-- Blackjack 1
payoutsFrame.card3image = payoutsFrame:CreateTexture(nil, "OVERLAY")
payoutsFrame.card3image:SetSize(32, 64)
payoutsFrame.card3image:SetPoint("TOPLEFT", payoutsFrame, 140, -70)
payoutsFrame.card3image:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\AS.tga")
payoutsFrame.card3image:SetBlendMode("BLEND")
payoutsFrame.card3image:SetDrawLayer("ARTWORK")
payoutsFrame.card3image:Hide()
-- Blackjack 2
payoutsFrame.card4image = payoutsFrame:CreateTexture(nil, "OVERLAY")
payoutsFrame.card4image:SetSize(32, 64)
payoutsFrame.card4image:SetPoint("TOPLEFT", payoutsFrame, 176, -70)
payoutsFrame.card4image:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\QD.tga")
payoutsFrame.card4image:SetBlendMode("BLEND")
payoutsFrame.card4image:SetDrawLayer("ARTWORK")
payoutsFrame.card4image:Hide()
-- (PP) Mixed Pair 1
payoutsFrame.card5image = payoutsFrame:CreateTexture(nil, "OVERLAY")
payoutsFrame.card5image:SetSize(32, 64)
payoutsFrame.card5image:SetPoint("TOPLEFT", payoutsFrame, 17, -185)
payoutsFrame.card5image:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\2C.tga")
payoutsFrame.card5image:SetBlendMode("BLEND")
payoutsFrame.card5image:SetDrawLayer("ARTWORK")
payoutsFrame.card5image:Hide()
-- (PP) Mixed Pair 2
payoutsFrame.card6image = payoutsFrame:CreateTexture(nil, "OVERLAY")
payoutsFrame.card6image:SetSize(32, 64)
payoutsFrame.card6image:SetPoint("TOPLEFT", payoutsFrame, 52, -185)
payoutsFrame.card6image:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\2D.tga")
payoutsFrame.card6image:SetBlendMode("BLEND")
payoutsFrame.card6image:SetDrawLayer("ARTWORK")
payoutsFrame.card6image:Hide()
-- (PP) Coloured Pair 1
payoutsFrame.card7image = payoutsFrame:CreateTexture(nil, "OVERLAY")
payoutsFrame.card7image:SetSize(32, 64)
payoutsFrame.card7image:SetPoint("TOPLEFT", payoutsFrame, 140, -185)
payoutsFrame.card7image:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\6S.tga")
payoutsFrame.card7image:SetBlendMode("BLEND")
payoutsFrame.card7image:SetDrawLayer("ARTWORK")
payoutsFrame.card7image:Hide()
-- (PP) Coloured Pair 2
payoutsFrame.card8image = payoutsFrame:CreateTexture(nil, "OVERLAY")
payoutsFrame.card8image:SetSize(32, 64)
payoutsFrame.card8image:SetPoint("TOPLEFT", payoutsFrame, 176, -185)
payoutsFrame.card8image:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\6C.tga")
payoutsFrame.card8image:SetBlendMode("BLEND")
payoutsFrame.card8image:SetDrawLayer("ARTWORK")
payoutsFrame.card8image:Hide()
-- (PP) Perfect Pair 1
payoutsFrame.card9image = payoutsFrame:CreateTexture(nil, "OVERLAY")
payoutsFrame.card9image:SetSize(32, 64)
payoutsFrame.card9image:SetPoint("TOPLEFT", payoutsFrame, 17, -257)
payoutsFrame.card9image:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\5D.tga")
payoutsFrame.card9image:SetBlendMode("BLEND")
payoutsFrame.card9image:SetDrawLayer("ARTWORK")
payoutsFrame.card9image:Hide()
-- (PP) Perfect Pair 2
payoutsFrame.card10image = payoutsFrame:CreateTexture(nil, "OVERLAY")
payoutsFrame.card10image:SetSize(32, 64)
payoutsFrame.card10image:SetPoint("TOPLEFT", payoutsFrame, 52, -257)
payoutsFrame.card10image:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\5D.tga")
payoutsFrame.card10image:SetBlendMode("BLEND")
payoutsFrame.card10image:SetDrawLayer("ARTWORK")
payoutsFrame.card10image:Hide()
-- (21+3) Flush 1
payoutsFrame.card11image = payoutsFrame:CreateTexture(nil, "OVERLAY")
payoutsFrame.card11image:SetSize(32, 64)
payoutsFrame.card11image:SetPoint("TOPLEFT", payoutsFrame, 17, -354)
payoutsFrame.card11image:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\3S.tga")
payoutsFrame.card11image:SetBlendMode("BLEND")
payoutsFrame.card11image:SetDrawLayer("ARTWORK")
payoutsFrame.card11image:Hide()
-- (21+3) Flush 2
payoutsFrame.card12image = payoutsFrame:CreateTexture(nil, "OVERLAY")
payoutsFrame.card12image:SetSize(32, 64)
payoutsFrame.card12image:SetPoint("TOPLEFT", payoutsFrame, 52, -354)
payoutsFrame.card12image:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\7S.tga")
payoutsFrame.card12image:SetBlendMode("BLEND")
payoutsFrame.card12image:SetDrawLayer("ARTWORK")
payoutsFrame.card12image:Hide()
-- (21+3) Flush 3
payoutsFrame.card13image = payoutsFrame:CreateTexture(nil, "OVERLAY")
payoutsFrame.card13image:SetSize(32, 64)
payoutsFrame.card13image:SetPoint("TOPLEFT", payoutsFrame, 88, -354)
payoutsFrame.card13image:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\QS.tga")
payoutsFrame.card13image:SetBlendMode("BLEND")
payoutsFrame.card13image:SetDrawLayer("ARTWORK")
payoutsFrame.card13image:Hide()
-- (21+3) Straight 1
payoutsFrame.card14image = payoutsFrame:CreateTexture(nil, "OVERLAY")
payoutsFrame.card14image:SetSize(32, 64)
payoutsFrame.card14image:SetPoint("TOPLEFT", payoutsFrame, 17, -426)
payoutsFrame.card14image:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\2H.tga")
payoutsFrame.card14image:SetBlendMode("BLEND")
payoutsFrame.card14image:SetDrawLayer("ARTWORK")
payoutsFrame.card14image:Hide()
-- (21+3) Straight 2
payoutsFrame.card15image = payoutsFrame:CreateTexture(nil, "OVERLAY")
payoutsFrame.card15image:SetSize(32, 64)
payoutsFrame.card15image:SetPoint("TOPLEFT", payoutsFrame, 52, -426)
payoutsFrame.card15image:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\3C.tga")
payoutsFrame.card15image:SetBlendMode("BLEND")
payoutsFrame.card15image:SetDrawLayer("ARTWORK")
payoutsFrame.card15image:Hide()
-- (21+3) Straight 3
payoutsFrame.card16image = payoutsFrame:CreateTexture(nil, "OVERLAY")
payoutsFrame.card16image:SetSize(32, 64)
payoutsFrame.card16image:SetPoint("TOPLEFT", payoutsFrame, 88, -426)
payoutsFrame.card16image:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\4D.tga")
payoutsFrame.card16image:SetBlendMode("BLEND")
payoutsFrame.card16image:SetDrawLayer("ARTWORK")
payoutsFrame.card16image:Hide()
-- (21+3) Three of a Kind 1
payoutsFrame.card17image = payoutsFrame:CreateTexture(nil, "OVERLAY")
payoutsFrame.card17image:SetSize(32, 64)
payoutsFrame.card17image:SetPoint("TOPLEFT", payoutsFrame, 17, -500)
payoutsFrame.card17image:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\AC.tga")
payoutsFrame.card17image:SetBlendMode("BLEND")
payoutsFrame.card17image:SetDrawLayer("ARTWORK")
payoutsFrame.card17image:Hide()
-- (21+3) Three of a Kind 2
payoutsFrame.card18image = payoutsFrame:CreateTexture(nil, "OVERLAY")
payoutsFrame.card18image:SetSize(32, 64)
payoutsFrame.card18image:SetPoint("TOPLEFT", payoutsFrame, 52, -500)
payoutsFrame.card18image:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\AD.tga")
payoutsFrame.card18image:SetBlendMode("BLEND")
payoutsFrame.card18image:SetDrawLayer("ARTWORK")
payoutsFrame.card18image:Hide()
-- (21+3) Three of a Kind 3
payoutsFrame.card19image = payoutsFrame:CreateTexture(nil, "OVERLAY")
payoutsFrame.card19image:SetSize(32, 64)
payoutsFrame.card19image:SetPoint("TOPLEFT", payoutsFrame, 88, -500)
payoutsFrame.card19image:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\AH.tga")
payoutsFrame.card19image:SetBlendMode("BLEND")
payoutsFrame.card19image:SetDrawLayer("ARTWORK")
payoutsFrame.card19image:Hide()
-- (21+3) Straight Flush 1
payoutsFrame.card20image = payoutsFrame:CreateTexture(nil, "OVERLAY")
payoutsFrame.card20image:SetSize(32, 64)
payoutsFrame.card20image:SetPoint("TOPLEFT", payoutsFrame, 17, -572)
payoutsFrame.card20image:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\2D.tga")
payoutsFrame.card20image:SetBlendMode("BLEND")
payoutsFrame.card20image:SetDrawLayer("ARTWORK")
payoutsFrame.card20image:Hide()
-- (21+3) Straight Flush 2
payoutsFrame.card21image = payoutsFrame:CreateTexture(nil, "OVERLAY")
payoutsFrame.card21image:SetSize(32, 64)
payoutsFrame.card21image:SetPoint("TOPLEFT", payoutsFrame, 52, -572)
payoutsFrame.card21image:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\3D.tga")
payoutsFrame.card21image:SetBlendMode("BLEND")
payoutsFrame.card21image:SetDrawLayer("ARTWORK")
payoutsFrame.card21image:Hide()
-- (21+3) Straight Flush 3
payoutsFrame.card22image = payoutsFrame:CreateTexture(nil, "OVERLAY")
payoutsFrame.card22image:SetSize(32, 64)
payoutsFrame.card22image:SetPoint("TOPLEFT", payoutsFrame, 88, -572)
payoutsFrame.card22image:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\4D.tga")
payoutsFrame.card22image:SetBlendMode("BLEND")
payoutsFrame.card22image:SetDrawLayer("ARTWORK")
payoutsFrame.card22image:Hide()
-- (21+3) Suited Three of a Kind 1
payoutsFrame.card23image = payoutsFrame:CreateTexture(nil, "OVERLAY")
payoutsFrame.card23image:SetSize(32, 64)
payoutsFrame.card23image:SetPoint("TOPLEFT", payoutsFrame, 17, -646)
payoutsFrame.card23image:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\AS.tga")
payoutsFrame.card23image:SetBlendMode("BLEND")
payoutsFrame.card23image:SetDrawLayer("ARTWORK")
payoutsFrame.card23image:Hide()
-- (21+3) Suited Three of a Kind 2
payoutsFrame.card24image = payoutsFrame:CreateTexture(nil, "OVERLAY")
payoutsFrame.card24image:SetSize(32, 64)
payoutsFrame.card24image:SetPoint("TOPLEFT", payoutsFrame, 52, -646)
payoutsFrame.card24image:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\AS.tga")
payoutsFrame.card24image:SetBlendMode("BLEND")
payoutsFrame.card24image:SetDrawLayer("ARTWORK")
payoutsFrame.card24image:Hide()
-- (21+3) Suited Three of a Kind 3
payoutsFrame.card25image = payoutsFrame:CreateTexture(nil, "OVERLAY")
payoutsFrame.card25image:SetSize(32, 64)
payoutsFrame.card25image:SetPoint("TOPLEFT", payoutsFrame, 88, -646)
payoutsFrame.card25image:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\AS.tga")
payoutsFrame.card25image:SetBlendMode("BLEND")
payoutsFrame.card25image:SetDrawLayer("ARTWORK")
payoutsFrame.card25image:Hide()

























-- >> DEALT CARDS WINDOW <<
-- >> DEALT CARDS WINDOW <<
-- >> DEALT CARDS WINDOW <<

-- Player Dealt Cards Frame
dealtCardsFramePlayer= CreateFrame("Frame", "BlackjackDealtCardsFrame", UIParent, "InsetFrameTemplate")
dealtCardsFramePlayer:SetSize(656, 200)
dealtCardsFramePlayer:SetPoint("BOTTOM", playerFrame, 0, 5)
dealtCardsFramePlayer:SetFrameStrata("HIGH")
dealtCardsFramePlayer:SetFrameLevel(6)
dealtCardsFramePlayer:Hide()

-- "Player" button which displays Player's Main Hand cards
dealtCardsFramePlayer.playerCardsButton = CreateFrame("Button", nil, dealtCardsFramePlayer, "GameMenuButtonTemplate")
dealtCardsFramePlayer.playerCardsButton:SetPoint("TOPLEFT", dealtCardsFramePlayer, 8, -8)
dealtCardsFramePlayer.playerCardsButton:SetSize(75, 25)
dealtCardsFramePlayer.playerCardsButton:SetText("Player")
dealtCardsFramePlayer.playerCardsButton:Disable()
dealtCardsFramePlayer.playerCardsButton:Hide()

-- "Dealer" button which displays Dealer's Hand cards
dealtCardsFramePlayer.dealerCardsButton = CreateFrame("Button", nil, dealtCardsFramePlayer, "GameMenuButtonTemplate")
dealtCardsFramePlayer.dealerCardsButton:SetPoint("TOPLEFT", dealtCardsFramePlayer, 84, -8)
dealtCardsFramePlayer.dealerCardsButton:SetSize(75, 25)
dealtCardsFramePlayer.dealerCardsButton:SetText("Dealer")
dealtCardsFramePlayer.dealerCardsButton:Hide()

dealtCardsFramePlayer.notStartedYetText = dealtCardsFramePlayer:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFramePlayer.notStartedYetText:SetPoint("CENTER", dealtCardsFramePlayer, 0, 0)
dealtCardsFramePlayer.notStartedYetText:SetJustifyH("CENTER")
dealtCardsFramePlayer.notStartedYetText:SetText("The round hasn't started yet")
dealtCardsFramePlayer.notStartedYetText:SetFont("Fonts\\FRIZQT__.TTF", 20, "OUTLINE")
dealtCardsFramePlayer.notStartedYetText:Hide()

dealtCardsFramePlayer.player1MainCardImage1 = dealtCardsFramePlayer:CreateTexture(nil, "OVERLAY")
dealtCardsFramePlayer.player1MainCardImage1:SetSize(85, 170)
dealtCardsFramePlayer.player1MainCardImage1:SetPoint("LEFT", dealtCardsFramePlayer, 10, -7)
dealtCardsFramePlayer.player1MainCardImage1:SetBlendMode("BLEND")
dealtCardsFramePlayer.player1MainCardImage1:SetDrawLayer("ARTWORK")

dealtCardsFramePlayer.player1MainCardImage2 = dealtCardsFramePlayer:CreateTexture(nil, "OVERLAY")
dealtCardsFramePlayer.player1MainCardImage2:SetSize(85, 170)
dealtCardsFramePlayer.player1MainCardImage2:SetPoint("LEFT", dealtCardsFramePlayer, 102, -7)
dealtCardsFramePlayer.player1MainCardImage2:SetBlendMode("BLEND")
dealtCardsFramePlayer.player1MainCardImage2:SetDrawLayer("ARTWORK")

dealtCardsFramePlayer.player1MainCardImage3 = dealtCardsFramePlayer:CreateTexture(nil, "OVERLAY")
dealtCardsFramePlayer.player1MainCardImage3:SetSize(85, 170)
dealtCardsFramePlayer.player1MainCardImage3:SetPoint("LEFT", dealtCardsFramePlayer, 194, -7)
dealtCardsFramePlayer.player1MainCardImage3:SetBlendMode("BLEND")
dealtCardsFramePlayer.player1MainCardImage3:SetDrawLayer("ARTWORK")

dealtCardsFramePlayer.player1MainCardImage4 = dealtCardsFramePlayer:CreateTexture(nil, "OVERLAY")
dealtCardsFramePlayer.player1MainCardImage4:SetSize(85, 170)
dealtCardsFramePlayer.player1MainCardImage4:SetPoint("LEFT", dealtCardsFramePlayer, 286, -7)
dealtCardsFramePlayer.player1MainCardImage4:SetBlendMode("BLEND")
dealtCardsFramePlayer.player1MainCardImage4:SetDrawLayer("ARTWORK")

dealtCardsFramePlayer.player1MainCardImage5 = dealtCardsFramePlayer:CreateTexture(nil, "OVERLAY")
dealtCardsFramePlayer.player1MainCardImage5:SetSize(85, 170)
dealtCardsFramePlayer.player1MainCardImage5:SetPoint("LEFT", dealtCardsFramePlayer, 378, -7)
dealtCardsFramePlayer.player1MainCardImage5:SetBlendMode("BLEND")
dealtCardsFramePlayer.player1MainCardImage5:SetDrawLayer("ARTWORK")

dealtCardsFramePlayer.player1MainCardImage6 = dealtCardsFramePlayer:CreateTexture(nil, "OVERLAY")
dealtCardsFramePlayer.player1MainCardImage6:SetSize(85, 170)
dealtCardsFramePlayer.player1MainCardImage6:SetPoint("LEFT", dealtCardsFramePlayer, 470, -7)
dealtCardsFramePlayer.player1MainCardImage6:SetBlendMode("BLEND")
dealtCardsFramePlayer.player1MainCardImage6:SetDrawLayer("ARTWORK")

dealtCardsFramePlayer.player1MainCardImage7 = dealtCardsFramePlayer:CreateTexture(nil, "OVERLAY")
dealtCardsFramePlayer.player1MainCardImage7:SetSize(85, 170)
dealtCardsFramePlayer.player1MainCardImage7:SetPoint("LEFT", dealtCardsFramePlayer, 562, -7)
dealtCardsFramePlayer.player1MainCardImage7:SetBlendMode("BLEND")
dealtCardsFramePlayer.player1MainCardImage7:SetDrawLayer("ARTWORK")

dealtCardsFramePlayer.playerFirstCardText = dealtCardsFramePlayer:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFramePlayer.playerFirstCardText:SetPoint("LEFT", dealtCardsFramePlayer, 23, -80)
dealtCardsFramePlayer.playerFirstCardText:SetJustifyH("CENTER")
dealtCardsFramePlayer.playerFirstCardText:SetText("1st Card")
dealtCardsFramePlayer.playerFirstCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFramePlayer.playerFirstCardText:Hide()

dealtCardsFramePlayer.playerSecondCardText = dealtCardsFramePlayer:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFramePlayer.playerSecondCardText:SetPoint("LEFT", dealtCardsFramePlayer, 112, -80)
dealtCardsFramePlayer.playerSecondCardText:SetJustifyH("CENTER")
dealtCardsFramePlayer.playerSecondCardText:SetText("2nd Card")
dealtCardsFramePlayer.playerSecondCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFramePlayer.playerSecondCardText:Hide()

dealtCardsFramePlayer.playerThirdCardText = dealtCardsFramePlayer:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFramePlayer.playerThirdCardText:SetPoint("LEFT", dealtCardsFramePlayer, 207, -80)
dealtCardsFramePlayer.playerThirdCardText:SetJustifyH("CENTER")
dealtCardsFramePlayer.playerThirdCardText:SetText("3rd Card")
dealtCardsFramePlayer.playerThirdCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFramePlayer.playerThirdCardText:Hide()

dealtCardsFramePlayer.playerFourthCardText = dealtCardsFramePlayer:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFramePlayer.playerFourthCardText:SetPoint("LEFT", dealtCardsFramePlayer, 299, -80)
dealtCardsFramePlayer.playerFourthCardText:SetJustifyH("CENTER")
dealtCardsFramePlayer.playerFourthCardText:SetText("4th Card")
dealtCardsFramePlayer.playerFourthCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFramePlayer.playerFourthCardText:Hide()

dealtCardsFramePlayer.playerFifthCardText = dealtCardsFramePlayer:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFramePlayer.playerFifthCardText:SetPoint("LEFT", dealtCardsFramePlayer, 392, -80)
dealtCardsFramePlayer.playerFifthCardText:SetJustifyH("CENTER")
dealtCardsFramePlayer.playerFifthCardText:SetText("5th Card")
dealtCardsFramePlayer.playerFifthCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFramePlayer.playerFifthCardText:Hide()

dealtCardsFramePlayer.playerSixthCardText = dealtCardsFramePlayer:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFramePlayer.playerSixthCardText:SetPoint("LEFT", dealtCardsFramePlayer, 483, -80)
dealtCardsFramePlayer.playerSixthCardText:SetJustifyH("CENTER")
dealtCardsFramePlayer.playerSixthCardText:SetText("6th Card")
dealtCardsFramePlayer.playerSixthCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFramePlayer.playerSixthCardText:Hide()

dealtCardsFramePlayer.playerSeventhCardText = dealtCardsFramePlayer:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFramePlayer.playerSeventhCardText:SetPoint("LEFT", dealtCardsFramePlayer, 576, -80)
dealtCardsFramePlayer.playerSeventhCardText:SetJustifyH("CENTER")
dealtCardsFramePlayer.playerSeventhCardText:SetText("7th Card")
dealtCardsFramePlayer.playerSeventhCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFramePlayer.playerSeventhCardText:Hide()








-- Player H1 Dealt Cards Frame
dealtCardsFramePlayer1H1= CreateFrame("Frame", "BlackjackDealtCardsFrame", UIParent, "InsetFrameTemplate")
dealtCardsFramePlayer1H1:SetSize(656, 200)
dealtCardsFramePlayer1H1:SetPoint("BOTTOM", playerFrame, 0, 5)
dealtCardsFramePlayer1H1:SetFrameStrata("HIGH")
dealtCardsFramePlayer1H1:SetFrameLevel(5)
dealtCardsFramePlayer1H1:Hide()

-- "Hand 1" button which displays Player's Hand 1 cards
dealtCardsFramePlayer1H1.playerH1CardsButton = CreateFrame("Button", nil, dealtCardsFramePlayer1H1, "GameMenuButtonTemplate")
dealtCardsFramePlayer1H1.playerH1CardsButton:SetPoint("TOPLEFT", dealtCardsFramePlayer1H1, 8, -8)
dealtCardsFramePlayer1H1.playerH1CardsButton:SetSize(75, 25)
dealtCardsFramePlayer1H1.playerH1CardsButton:SetText("Hand 1")
dealtCardsFramePlayer1H1.playerH1CardsButton:Disable()
dealtCardsFramePlayer1H1.playerH1CardsButton:Hide()

-- "Hand 2" button which displays Player's Hand 2 cards
dealtCardsFramePlayer1H1.playerH2CardsButton = CreateFrame("Button", nil, dealtCardsFramePlayer1H1, "GameMenuButtonTemplate")
dealtCardsFramePlayer1H1.playerH2CardsButton:SetPoint("TOPLEFT", dealtCardsFramePlayer1H1, 84, -8)
dealtCardsFramePlayer1H1.playerH2CardsButton:SetSize(75, 25)
dealtCardsFramePlayer1H1.playerH2CardsButton:SetText("Hand 2")
dealtCardsFramePlayer1H1.playerH2CardsButton:Hide()

-- "Dealer" button which displays Dealer's Hand cards
dealtCardsFramePlayer1H1.dealerCardsButton = CreateFrame("Button", nil, dealtCardsFramePlayer1H1, "GameMenuButtonTemplate")
dealtCardsFramePlayer1H1.dealerCardsButton:SetPoint("TOPLEFT", dealtCardsFramePlayer1H1, 160, -8)
dealtCardsFramePlayer1H1.dealerCardsButton:SetSize(75, 25)
dealtCardsFramePlayer1H1.dealerCardsButton:SetText("Dealer")
dealtCardsFramePlayer1H1.dealerCardsButton:Hide()

dealtCardsFramePlayer1H1.player1H1CardImage1 = dealtCardsFramePlayer1H1:CreateTexture(nil, "OVERLAY")
dealtCardsFramePlayer1H1.player1H1CardImage1:SetSize(85, 170)
dealtCardsFramePlayer1H1.player1H1CardImage1:SetPoint("LEFT", dealtCardsFramePlayer1H1, 10, -7)
dealtCardsFramePlayer1H1.player1H1CardImage1:SetBlendMode("BLEND")
dealtCardsFramePlayer1H1.player1H1CardImage1:SetDrawLayer("ARTWORK")

dealtCardsFramePlayer1H1.player1H1CardImage2 = dealtCardsFramePlayer1H1:CreateTexture(nil, "OVERLAY")
dealtCardsFramePlayer1H1.player1H1CardImage2:SetSize(85, 170)
dealtCardsFramePlayer1H1.player1H1CardImage2:SetPoint("LEFT", dealtCardsFramePlayer1H1, 102, -7)
dealtCardsFramePlayer1H1.player1H1CardImage2:SetBlendMode("BLEND")
dealtCardsFramePlayer1H1.player1H1CardImage2:SetDrawLayer("ARTWORK")

dealtCardsFramePlayer1H1.player1H1CardImage3 = dealtCardsFramePlayer1H1:CreateTexture(nil, "OVERLAY")
dealtCardsFramePlayer1H1.player1H1CardImage3:SetSize(85, 170)
dealtCardsFramePlayer1H1.player1H1CardImage3:SetPoint("LEFT", dealtCardsFramePlayer1H1, 194, -7)
dealtCardsFramePlayer1H1.player1H1CardImage3:SetBlendMode("BLEND")
dealtCardsFramePlayer1H1.player1H1CardImage3:SetDrawLayer("ARTWORK")

dealtCardsFramePlayer1H1.player1H1CardImage4 = dealtCardsFramePlayer1H1:CreateTexture(nil, "OVERLAY")
dealtCardsFramePlayer1H1.player1H1CardImage4:SetSize(85, 170)
dealtCardsFramePlayer1H1.player1H1CardImage4:SetPoint("LEFT", dealtCardsFramePlayer1H1, 286, -7)
dealtCardsFramePlayer1H1.player1H1CardImage4:SetBlendMode("BLEND")
dealtCardsFramePlayer1H1.player1H1CardImage4:SetDrawLayer("ARTWORK")

dealtCardsFramePlayer1H1.player1H1CardImage5 = dealtCardsFramePlayer1H1:CreateTexture(nil, "OVERLAY")
dealtCardsFramePlayer1H1.player1H1CardImage5:SetSize(85, 170)
dealtCardsFramePlayer1H1.player1H1CardImage5:SetPoint("LEFT", dealtCardsFramePlayer1H1, 378, -7)
dealtCardsFramePlayer1H1.player1H1CardImage5:SetBlendMode("BLEND")
dealtCardsFramePlayer1H1.player1H1CardImage5:SetDrawLayer("ARTWORK")

dealtCardsFramePlayer1H1.player1H1CardImage6 = dealtCardsFramePlayer1H1:CreateTexture(nil, "OVERLAY")
dealtCardsFramePlayer1H1.player1H1CardImage6:SetSize(85, 170)
dealtCardsFramePlayer1H1.player1H1CardImage6:SetPoint("LEFT", dealtCardsFramePlayer1H1, 470, -7)
dealtCardsFramePlayer1H1.player1H1CardImage6:SetBlendMode("BLEND")
dealtCardsFramePlayer1H1.player1H1CardImage6:SetDrawLayer("ARTWORK")

dealtCardsFramePlayer1H1.player1H1CardImage7 = dealtCardsFramePlayer1H1:CreateTexture(nil, "OVERLAY")
dealtCardsFramePlayer1H1.player1H1CardImage7:SetSize(85, 170)
dealtCardsFramePlayer1H1.player1H1CardImage7:SetPoint("LEFT", dealtCardsFramePlayer1H1, 562, -7)
dealtCardsFramePlayer1H1.player1H1CardImage7:SetBlendMode("BLEND")
dealtCardsFramePlayer1H1.player1H1CardImage7:SetDrawLayer("ARTWORK")

dealtCardsFramePlayer1H1.playerFirstCardText = dealtCardsFramePlayer1H1:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFramePlayer1H1.playerFirstCardText:SetPoint("LEFT", dealtCardsFramePlayer1H1, 23, -80)
dealtCardsFramePlayer1H1.playerFirstCardText:SetJustifyH("CENTER")
dealtCardsFramePlayer1H1.playerFirstCardText:SetText("1st Card")
dealtCardsFramePlayer1H1.playerFirstCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFramePlayer1H1.playerFirstCardText:Hide()

dealtCardsFramePlayer1H1.playerSecondCardText = dealtCardsFramePlayer1H1:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFramePlayer1H1.playerSecondCardText:SetPoint("LEFT", dealtCardsFramePlayer1H1, 112, -80)
dealtCardsFramePlayer1H1.playerSecondCardText:SetJustifyH("CENTER")
dealtCardsFramePlayer1H1.playerSecondCardText:SetText("2nd Card")
dealtCardsFramePlayer1H1.playerSecondCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFramePlayer1H1.playerSecondCardText:Hide()

dealtCardsFramePlayer1H1.playerThirdCardText = dealtCardsFramePlayer1H1:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFramePlayer1H1.playerThirdCardText:SetPoint("LEFT", dealtCardsFramePlayer1H1, 207, -80)
dealtCardsFramePlayer1H1.playerThirdCardText:SetJustifyH("CENTER")
dealtCardsFramePlayer1H1.playerThirdCardText:SetText("3rd Card")
dealtCardsFramePlayer1H1.playerThirdCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFramePlayer1H1.playerThirdCardText:Hide()

dealtCardsFramePlayer1H1.playerFourthCardText = dealtCardsFramePlayer1H1:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFramePlayer1H1.playerFourthCardText:SetPoint("LEFT", dealtCardsFramePlayer1H1, 299, -80)
dealtCardsFramePlayer1H1.playerFourthCardText:SetJustifyH("CENTER")
dealtCardsFramePlayer1H1.playerFourthCardText:SetText("4th Card")
dealtCardsFramePlayer1H1.playerFourthCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFramePlayer1H1.playerFourthCardText:Hide()

dealtCardsFramePlayer1H1.playerFifthCardText = dealtCardsFramePlayer1H1:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFramePlayer1H1.playerFifthCardText:SetPoint("LEFT", dealtCardsFramePlayer1H1, 392, -80)
dealtCardsFramePlayer1H1.playerFifthCardText:SetJustifyH("CENTER")
dealtCardsFramePlayer1H1.playerFifthCardText:SetText("5th Card")
dealtCardsFramePlayer1H1.playerFifthCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFramePlayer1H1.playerFifthCardText:Hide()

dealtCardsFramePlayer1H1.playerSixthCardText = dealtCardsFramePlayer1H1:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFramePlayer1H1.playerSixthCardText:SetPoint("LEFT", dealtCardsFramePlayer1H1, 483, -80)
dealtCardsFramePlayer1H1.playerSixthCardText:SetJustifyH("CENTER")
dealtCardsFramePlayer1H1.playerSixthCardText:SetText("6th Card")
dealtCardsFramePlayer1H1.playerSixthCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFramePlayer1H1.playerSixthCardText:Hide()

dealtCardsFramePlayer1H1.playerSeventhCardText = dealtCardsFramePlayer1H1:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFramePlayer1H1.playerSeventhCardText:SetPoint("LEFT", dealtCardsFramePlayer1H1, 576, -80)
dealtCardsFramePlayer1H1.playerSeventhCardText:SetJustifyH("CENTER")
dealtCardsFramePlayer1H1.playerSeventhCardText:SetText("7th Card")
dealtCardsFramePlayer1H1.playerSeventhCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFramePlayer1H1.playerSeventhCardText:Hide()







-- Player H2 Dealt Cards Frame
dealtCardsFramePlayer1H2= CreateFrame("Frame", "BlackjackDealtCardsFrame", UIParent, "InsetFrameTemplate")
dealtCardsFramePlayer1H2:SetSize(656, 200)
dealtCardsFramePlayer1H2:SetPoint("BOTTOM", playerFrame, 0, 5)
dealtCardsFramePlayer1H2:SetFrameStrata("HIGH")
dealtCardsFramePlayer1H2:SetFrameLevel(5)
dealtCardsFramePlayer1H2:Hide()

-- "Hand 1" button which displays Player's Hand 1 cards
dealtCardsFramePlayer1H2.playerH1CardsButton = CreateFrame("Button", nil, dealtCardsFramePlayer1H2, "GameMenuButtonTemplate")
dealtCardsFramePlayer1H2.playerH1CardsButton:SetPoint("TOPLEFT", dealtCardsFramePlayer1H2, 8, -8)
dealtCardsFramePlayer1H2.playerH1CardsButton:SetSize(75, 25)
dealtCardsFramePlayer1H2.playerH1CardsButton:SetText("Hand 1")
dealtCardsFramePlayer1H2.playerH1CardsButton:Hide()

-- "Hand 2" button which displays Player's Hand 2 cards
dealtCardsFramePlayer1H2.playerH2CardsButton = CreateFrame("Button", nil, dealtCardsFramePlayer1H2, "GameMenuButtonTemplate")
dealtCardsFramePlayer1H2.playerH2CardsButton:SetPoint("TOPLEFT", dealtCardsFramePlayer1H2, 84, -8)
dealtCardsFramePlayer1H2.playerH2CardsButton:SetSize(75, 25)
dealtCardsFramePlayer1H2.playerH2CardsButton:SetText("Hand 2")
dealtCardsFramePlayer1H2.playerH2CardsButton:Disable()
dealtCardsFramePlayer1H2.playerH2CardsButton:Hide()

-- "Dealer" button which displays Dealer's Hand cards
dealtCardsFramePlayer1H2.dealerCardsButton = CreateFrame("Button", nil, dealtCardsFramePlayer1H2, "GameMenuButtonTemplate")
dealtCardsFramePlayer1H2.dealerCardsButton:SetPoint("TOPLEFT", dealtCardsFramePlayer1H2, 160, -8)
dealtCardsFramePlayer1H2.dealerCardsButton:SetSize(75, 25)
dealtCardsFramePlayer1H2.dealerCardsButton:SetText("Dealer")
dealtCardsFramePlayer1H2.dealerCardsButton:Hide()

dealtCardsFramePlayer1H2.player1H2CardImage1 = dealtCardsFramePlayer1H2:CreateTexture(nil, "OVERLAY")
dealtCardsFramePlayer1H2.player1H2CardImage1:SetSize(85, 170)
dealtCardsFramePlayer1H2.player1H2CardImage1:SetPoint("LEFT", dealtCardsFramePlayer1H2, 10, -7)
dealtCardsFramePlayer1H2.player1H2CardImage1:SetBlendMode("BLEND")
dealtCardsFramePlayer1H2.player1H2CardImage1:SetDrawLayer("ARTWORK")

dealtCardsFramePlayer1H2.player1H2CardImage2 = dealtCardsFramePlayer1H2:CreateTexture(nil, "OVERLAY")
dealtCardsFramePlayer1H2.player1H2CardImage2:SetSize(85, 170)
dealtCardsFramePlayer1H2.player1H2CardImage2:SetPoint("LEFT", dealtCardsFramePlayer1H2, 102, -7)
dealtCardsFramePlayer1H2.player1H2CardImage2:SetBlendMode("BLEND")
dealtCardsFramePlayer1H2.player1H2CardImage2:SetDrawLayer("ARTWORK")

dealtCardsFramePlayer1H2.player1H2CardImage3 = dealtCardsFramePlayer1H2:CreateTexture(nil, "OVERLAY")
dealtCardsFramePlayer1H2.player1H2CardImage3:SetSize(85, 170)
dealtCardsFramePlayer1H2.player1H2CardImage3:SetPoint("LEFT", dealtCardsFramePlayer1H2, 194, -7)
dealtCardsFramePlayer1H2.player1H2CardImage3:SetBlendMode("BLEND")
dealtCardsFramePlayer1H2.player1H2CardImage3:SetDrawLayer("ARTWORK")

dealtCardsFramePlayer1H2.player1H2CardImage4 = dealtCardsFramePlayer1H2:CreateTexture(nil, "OVERLAY")
dealtCardsFramePlayer1H2.player1H2CardImage4:SetSize(85, 170)
dealtCardsFramePlayer1H2.player1H2CardImage4:SetPoint("LEFT", dealtCardsFramePlayer1H2, 286, -7)
dealtCardsFramePlayer1H2.player1H2CardImage4:SetBlendMode("BLEND")
dealtCardsFramePlayer1H2.player1H2CardImage4:SetDrawLayer("ARTWORK")

dealtCardsFramePlayer1H2.player1H2CardImage5 = dealtCardsFramePlayer1H2:CreateTexture(nil, "OVERLAY")
dealtCardsFramePlayer1H2.player1H2CardImage5:SetSize(85, 170)
dealtCardsFramePlayer1H2.player1H2CardImage5:SetPoint("LEFT", dealtCardsFramePlayer1H2, 378, -7)
dealtCardsFramePlayer1H2.player1H2CardImage5:SetBlendMode("BLEND")
dealtCardsFramePlayer1H2.player1H2CardImage5:SetDrawLayer("ARTWORK")

dealtCardsFramePlayer1H2.player1H2CardImage6 = dealtCardsFramePlayer1H2:CreateTexture(nil, "OVERLAY")
dealtCardsFramePlayer1H2.player1H2CardImage6:SetSize(85, 170)
dealtCardsFramePlayer1H2.player1H2CardImage6:SetPoint("LEFT", dealtCardsFramePlayer1H2, 470, -7)
dealtCardsFramePlayer1H2.player1H2CardImage6:SetBlendMode("BLEND")
dealtCardsFramePlayer1H2.player1H2CardImage6:SetDrawLayer("ARTWORK")

dealtCardsFramePlayer1H2.player1H2CardImage7 = dealtCardsFramePlayer1H2:CreateTexture(nil, "OVERLAY")
dealtCardsFramePlayer1H2.player1H2CardImage7:SetSize(85, 170)
dealtCardsFramePlayer1H2.player1H2CardImage7:SetPoint("LEFT", dealtCardsFramePlayer1H2, 562, -7)
dealtCardsFramePlayer1H2.player1H2CardImage7:SetBlendMode("BLEND")
dealtCardsFramePlayer1H2.player1H2CardImage7:SetDrawLayer("ARTWORK")

dealtCardsFramePlayer1H2.playerFirstCardText = dealtCardsFramePlayer1H2:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFramePlayer1H2.playerFirstCardText:SetPoint("LEFT", dealtCardsFramePlayer1H2, 23, -80)
dealtCardsFramePlayer1H2.playerFirstCardText:SetJustifyH("CENTER")
dealtCardsFramePlayer1H2.playerFirstCardText:SetText("1st Card")
dealtCardsFramePlayer1H2.playerFirstCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFramePlayer1H2.playerFirstCardText:Hide()

dealtCardsFramePlayer1H2.playerSecondCardText = dealtCardsFramePlayer1H2:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFramePlayer1H2.playerSecondCardText:SetPoint("LEFT", dealtCardsFramePlayer1H2, 112, -80)
dealtCardsFramePlayer1H2.playerSecondCardText:SetJustifyH("CENTER")
dealtCardsFramePlayer1H2.playerSecondCardText:SetText("2nd Card")
dealtCardsFramePlayer1H2.playerSecondCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFramePlayer1H2.playerSecondCardText:Hide()

dealtCardsFramePlayer1H2.playerThirdCardText = dealtCardsFramePlayer1H2:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFramePlayer1H2.playerThirdCardText:SetPoint("LEFT", dealtCardsFramePlayer1H2, 207, -80)
dealtCardsFramePlayer1H2.playerThirdCardText:SetJustifyH("CENTER")
dealtCardsFramePlayer1H2.playerThirdCardText:SetText("3rd Card")
dealtCardsFramePlayer1H2.playerThirdCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFramePlayer1H2.playerThirdCardText:Hide()

dealtCardsFramePlayer1H2.playerFourthCardText = dealtCardsFramePlayer1H2:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFramePlayer1H2.playerFourthCardText:SetPoint("LEFT", dealtCardsFramePlayer1H2, 299, -80)
dealtCardsFramePlayer1H2.playerFourthCardText:SetJustifyH("CENTER")
dealtCardsFramePlayer1H2.playerFourthCardText:SetText("4th Card")
dealtCardsFramePlayer1H2.playerFourthCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFramePlayer1H2.playerFourthCardText:Hide()

dealtCardsFramePlayer1H2.playerFifthCardText = dealtCardsFramePlayer1H2:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFramePlayer1H2.playerFifthCardText:SetPoint("LEFT", dealtCardsFramePlayer1H2, 392, -80)
dealtCardsFramePlayer1H2.playerFifthCardText:SetJustifyH("CENTER")
dealtCardsFramePlayer1H2.playerFifthCardText:SetText("5th Card")
dealtCardsFramePlayer1H2.playerFifthCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFramePlayer1H2.playerFifthCardText:Hide()

dealtCardsFramePlayer1H2.playerSixthCardText = dealtCardsFramePlayer1H2:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFramePlayer1H2.playerSixthCardText:SetPoint("LEFT", dealtCardsFramePlayer1H2, 483, -80)
dealtCardsFramePlayer1H2.playerSixthCardText:SetJustifyH("CENTER")
dealtCardsFramePlayer1H2.playerSixthCardText:SetText("6th Card")
dealtCardsFramePlayer1H2.playerSixthCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFramePlayer1H2.playerSixthCardText:Hide()

dealtCardsFramePlayer1H2.playerSeventhCardText = dealtCardsFramePlayer1H2:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFramePlayer1H2.playerSeventhCardText:SetPoint("LEFT", dealtCardsFramePlayer1H2, 576, -80)
dealtCardsFramePlayer1H2.playerSeventhCardText:SetJustifyH("CENTER")
dealtCardsFramePlayer1H2.playerSeventhCardText:SetText("7th Card")
dealtCardsFramePlayer1H2.playerSeventhCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFramePlayer1H2.playerSeventhCardText:Hide()








-- Dealer Dealt Cards Frame
dealtCardsFrameDealer= CreateFrame("Frame", "BlackjackDealtCardsFrame", UIParent, "InsetFrameTemplate")
dealtCardsFrameDealer:SetSize(656, 200)
dealtCardsFrameDealer:SetPoint("BOTTOM", playerFrame, 0, 5)
dealtCardsFrameDealer:SetFrameStrata("HIGH")
dealtCardsFrameDealer:SetFrameLevel(5)
dealtCardsFrameDealer:Hide()

-- "Player" button which displays Player's Main Hand cards
dealtCardsFrameDealer.playerCardsButton = CreateFrame("Button", nil, dealtCardsFrameDealer, "GameMenuButtonTemplate")
dealtCardsFrameDealer.playerCardsButton:SetPoint("TOPLEFT", dealtCardsFrameDealer, 8, -8)
dealtCardsFrameDealer.playerCardsButton:SetSize(75, 25)
dealtCardsFrameDealer.playerCardsButton:SetText("Player")
dealtCardsFrameDealer.playerCardsButton:Hide()

-- "Dealer" button which displays Dealer's Hand cards
dealtCardsFrameDealer.dealerCardsButton = CreateFrame("Button", nil, dealtCardsFrameDealer, "GameMenuButtonTemplate")
dealtCardsFrameDealer.dealerCardsButton:SetPoint("TOPLEFT", dealtCardsFrameDealer, 84, -8)
dealtCardsFrameDealer.dealerCardsButton:SetSize(75, 25)
dealtCardsFrameDealer.dealerCardsButton:SetText("Dealer")
dealtCardsFrameDealer.dealerCardsButton:Disable()
dealtCardsFrameDealer.dealerCardsButton:Hide()

dealtCardsFrameDealer.notStartedYetText = dealtCardsFrameDealer:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFrameDealer.notStartedYetText:SetPoint("CENTER", dealtCardsFrameDealer, 0, 0)
dealtCardsFrameDealer.notStartedYetText:SetJustifyH("CENTER")
dealtCardsFrameDealer.notStartedYetText:SetText("The round hasn't started yet")
dealtCardsFrameDealer.notStartedYetText:SetFont("Fonts\\FRIZQT__.TTF", 20, "OUTLINE")
dealtCardsFrameDealer.notStartedYetText:Hide()

dealtCardsFrameDealer.dealerCardImage1 = dealtCardsFrameDealer:CreateTexture(nil, "OVERLAY")
dealtCardsFrameDealer.dealerCardImage1:SetSize(85, 170)
dealtCardsFrameDealer.dealerCardImage1:SetPoint("LEFT", dealtCardsFrameDealer, 10, -7)
dealtCardsFrameDealer.dealerCardImage1:SetBlendMode("BLEND")
dealtCardsFrameDealer.dealerCardImage1:SetDrawLayer("ARTWORK")

dealtCardsFrameDealer.dealerCardImage2 = dealtCardsFrameDealer:CreateTexture(nil, "OVERLAY")
dealtCardsFrameDealer.dealerCardImage2:SetSize(85, 170)
dealtCardsFrameDealer.dealerCardImage2:SetPoint("LEFT", dealtCardsFrameDealer, 102, -7)
dealtCardsFrameDealer.dealerCardImage2:SetBlendMode("BLEND")
dealtCardsFrameDealer.dealerCardImage2:SetDrawLayer("ARTWORK")

dealtCardsFrameDealer.dealerCardImage3 = dealtCardsFrameDealer:CreateTexture(nil, "OVERLAY")
dealtCardsFrameDealer.dealerCardImage3:SetSize(85, 170)
dealtCardsFrameDealer.dealerCardImage3:SetPoint("LEFT", dealtCardsFrameDealer, 194, -7)
dealtCardsFrameDealer.dealerCardImage3:SetBlendMode("BLEND")
dealtCardsFrameDealer.dealerCardImage3:SetDrawLayer("ARTWORK")

dealtCardsFrameDealer.dealerCardImage4 = dealtCardsFrameDealer:CreateTexture(nil, "OVERLAY")
dealtCardsFrameDealer.dealerCardImage4:SetSize(85, 170)
dealtCardsFrameDealer.dealerCardImage4:SetPoint("LEFT", dealtCardsFrameDealer, 286, -7)
dealtCardsFrameDealer.dealerCardImage4:SetBlendMode("BLEND")
dealtCardsFrameDealer.dealerCardImage4:SetDrawLayer("ARTWORK")

dealtCardsFrameDealer.dealerCardImage5 = dealtCardsFrameDealer:CreateTexture(nil, "OVERLAY")
dealtCardsFrameDealer.dealerCardImage5:SetSize(85, 170)
dealtCardsFrameDealer.dealerCardImage5:SetPoint("LEFT", dealtCardsFrameDealer, 378, -7)
dealtCardsFrameDealer.dealerCardImage5:SetBlendMode("BLEND")
dealtCardsFrameDealer.dealerCardImage5:SetDrawLayer("ARTWORK")

dealtCardsFrameDealer.dealerCardImage6 = dealtCardsFrameDealer:CreateTexture(nil, "OVERLAY")
dealtCardsFrameDealer.dealerCardImage6:SetSize(85, 170)
dealtCardsFrameDealer.dealerCardImage6:SetPoint("LEFT", dealtCardsFrameDealer, 470, -7)
dealtCardsFrameDealer.dealerCardImage6:SetBlendMode("BLEND")
dealtCardsFrameDealer.dealerCardImage6:SetDrawLayer("ARTWORK")

dealtCardsFrameDealer.dealerCardImage7 = dealtCardsFrameDealer:CreateTexture(nil, "OVERLAY")
dealtCardsFrameDealer.dealerCardImage7:SetSize(85, 170)
dealtCardsFrameDealer.dealerCardImage7:SetPoint("LEFT", dealtCardsFrameDealer, 562, -7)
dealtCardsFrameDealer.dealerCardImage7:SetBlendMode("BLEND")
dealtCardsFrameDealer.dealerCardImage7:SetDrawLayer("ARTWORK")

dealtCardsFrameDealer.dealerFirstCardText = dealtCardsFrameDealer:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFrameDealer.dealerFirstCardText:SetPoint("LEFT", dealtCardsFrameDealer, 23, -80)
dealtCardsFrameDealer.dealerFirstCardText:SetJustifyH("CENTER")
dealtCardsFrameDealer.dealerFirstCardText:SetText("1st Card")
dealtCardsFrameDealer.dealerFirstCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFrameDealer.dealerFirstCardText:Hide()

dealtCardsFrameDealer.dealerSecondCardText = dealtCardsFrameDealer:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFrameDealer.dealerSecondCardText:SetPoint("LEFT", dealtCardsFrameDealer, 112, -80)
dealtCardsFrameDealer.dealerSecondCardText:SetJustifyH("CENTER")
dealtCardsFrameDealer.dealerSecondCardText:SetText("2nd Card")
dealtCardsFrameDealer.dealerSecondCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFrameDealer.dealerSecondCardText:Hide()

dealtCardsFrameDealer.dealerThirdCardText = dealtCardsFrameDealer:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFrameDealer.dealerThirdCardText:SetPoint("LEFT", dealtCardsFrameDealer, 207, -80)
dealtCardsFrameDealer.dealerThirdCardText:SetJustifyH("CENTER")
dealtCardsFrameDealer.dealerThirdCardText:SetText("3rd Card")
dealtCardsFrameDealer.dealerThirdCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFrameDealer.dealerThirdCardText:Hide()

dealtCardsFrameDealer.dealerFourthCardText = dealtCardsFrameDealer:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFrameDealer.dealerFourthCardText:SetPoint("LEFT", dealtCardsFrameDealer, 299, -80)
dealtCardsFrameDealer.dealerFourthCardText:SetJustifyH("CENTER")
dealtCardsFrameDealer.dealerFourthCardText:SetText("4th Card")
dealtCardsFrameDealer.dealerFourthCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFrameDealer.dealerFourthCardText:Hide()

dealtCardsFrameDealer.dealerFifthCardText = dealtCardsFrameDealer:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFrameDealer.dealerFifthCardText:SetPoint("LEFT", dealtCardsFrameDealer, 392, -80)
dealtCardsFrameDealer.dealerFifthCardText:SetJustifyH("CENTER")
dealtCardsFrameDealer.dealerFifthCardText:SetText("5th Card")
dealtCardsFrameDealer.dealerFifthCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFrameDealer.dealerFifthCardText:Hide()

dealtCardsFrameDealer.dealerSixthCardText = dealtCardsFrameDealer:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFrameDealer.dealerSixthCardText:SetPoint("LEFT", dealtCardsFrameDealer, 483, -80)
dealtCardsFrameDealer.dealerSixthCardText:SetJustifyH("CENTER")
dealtCardsFrameDealer.dealerSixthCardText:SetText("6th Card")
dealtCardsFrameDealer.dealerSixthCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFrameDealer.dealerSixthCardText:Hide()

dealtCardsFrameDealer.dealerSeventhCardText = dealtCardsFrameDealer:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFrameDealer.dealerSeventhCardText:SetPoint("LEFT", dealtCardsFrameDealer, 576, -80)
dealtCardsFrameDealer.dealerSeventhCardText:SetJustifyH("CENTER")
dealtCardsFrameDealer.dealerSeventhCardText:SetText("7th Card")
dealtCardsFrameDealer.dealerSeventhCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFrameDealer.dealerSeventhCardText:Hide()







-- Dealer Dealt Cards Frame
dealtCardsFrameDealerSplit= CreateFrame("Frame", "BlackjackDealtCardsFrame", UIParent, "InsetFrameTemplate")
dealtCardsFrameDealerSplit:SetSize(656, 200)
dealtCardsFrameDealerSplit:SetPoint("BOTTOM", playerFrame, 0, 5)
dealtCardsFrameDealerSplit:SetFrameStrata("HIGH")
dealtCardsFrameDealerSplit:SetFrameLevel(5)
dealtCardsFrameDealerSplit:Hide()

-- "Hand 1" button which displays Player's Hand 1 cards
dealtCardsFrameDealerSplit.playerH1CardsButton = CreateFrame("Button", nil, dealtCardsFrameDealerSplit, "GameMenuButtonTemplate")
dealtCardsFrameDealerSplit.playerH1CardsButton:SetPoint("TOPLEFT", dealtCardsFrameDealerSplit, 8, -8)
dealtCardsFrameDealerSplit.playerH1CardsButton:SetSize(75, 25)
dealtCardsFrameDealerSplit.playerH1CardsButton:SetText("Hand 1")
dealtCardsFrameDealerSplit.playerH1CardsButton:Hide()

-- "Hand 2" button which displays Player's Hand 2 cards
dealtCardsFrameDealerSplit.playerH2CardsButton = CreateFrame("Button", nil, dealtCardsFrameDealerSplit, "GameMenuButtonTemplate")
dealtCardsFrameDealerSplit.playerH2CardsButton:SetPoint("TOPLEFT", dealtCardsFrameDealerSplit, 84, -8)
dealtCardsFrameDealerSplit.playerH2CardsButton:SetSize(75, 25)
dealtCardsFrameDealerSplit.playerH2CardsButton:SetText("Hand 2")
dealtCardsFrameDealerSplit.playerH2CardsButton:Hide()

-- "Dealer" button which displays Dealer's Hand cards
dealtCardsFrameDealerSplit.dealerCardsButton = CreateFrame("Button", nil, dealtCardsFrameDealerSplit, "GameMenuButtonTemplate")
dealtCardsFrameDealerSplit.dealerCardsButton:SetPoint("TOPLEFT", dealtCardsFrameDealerSplit, 160, -8)
dealtCardsFrameDealerSplit.dealerCardsButton:SetSize(75, 25)
dealtCardsFrameDealerSplit.dealerCardsButton:SetText("Dealer")
dealtCardsFrameDealerSplit.dealerCardsButton:Disable()
dealtCardsFrameDealerSplit.dealerCardsButton:Hide()

dealtCardsFrameDealerSplit.notStartedYetText = dealtCardsFrameDealerSplit:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFrameDealerSplit.notStartedYetText:SetPoint("CENTER", dealtCardsFrameDealerSplit, 0, 0)
dealtCardsFrameDealerSplit.notStartedYetText:SetJustifyH("CENTER")
dealtCardsFrameDealerSplit.notStartedYetText:SetText("The round hasn't started yet")
dealtCardsFrameDealerSplit.notStartedYetText:SetFont("Fonts\\FRIZQT__.TTF", 20, "OUTLINE")
dealtCardsFrameDealerSplit.notStartedYetText:Hide()

dealtCardsFrameDealerSplit.dealerCardImage1 = dealtCardsFrameDealerSplit:CreateTexture(nil, "OVERLAY")
dealtCardsFrameDealerSplit.dealerCardImage1:SetSize(85, 170)
dealtCardsFrameDealerSplit.dealerCardImage1:SetPoint("LEFT", dealtCardsFrameDealerSplit, 10, -7)
dealtCardsFrameDealerSplit.dealerCardImage1:SetBlendMode("BLEND")
dealtCardsFrameDealerSplit.dealerCardImage1:SetDrawLayer("ARTWORK")

dealtCardsFrameDealerSplit.dealerCardImage2 = dealtCardsFrameDealerSplit:CreateTexture(nil, "OVERLAY")
dealtCardsFrameDealerSplit.dealerCardImage2:SetSize(85, 170)
dealtCardsFrameDealerSplit.dealerCardImage2:SetPoint("LEFT", dealtCardsFrameDealerSplit, 102, -7)
dealtCardsFrameDealerSplit.dealerCardImage2:SetBlendMode("BLEND")
dealtCardsFrameDealerSplit.dealerCardImage2:SetDrawLayer("ARTWORK")

dealtCardsFrameDealerSplit.dealerCardImage3 = dealtCardsFrameDealerSplit:CreateTexture(nil, "OVERLAY")
dealtCardsFrameDealerSplit.dealerCardImage3:SetSize(85, 170)
dealtCardsFrameDealerSplit.dealerCardImage3:SetPoint("LEFT", dealtCardsFrameDealerSplit, 194, -7)
dealtCardsFrameDealerSplit.dealerCardImage3:SetBlendMode("BLEND")
dealtCardsFrameDealerSplit.dealerCardImage3:SetDrawLayer("ARTWORK")

dealtCardsFrameDealerSplit.dealerCardImage4 = dealtCardsFrameDealerSplit:CreateTexture(nil, "OVERLAY")
dealtCardsFrameDealerSplit.dealerCardImage4:SetSize(85, 170)
dealtCardsFrameDealerSplit.dealerCardImage4:SetPoint("LEFT", dealtCardsFrameDealerSplit, 286, -7)
dealtCardsFrameDealerSplit.dealerCardImage4:SetBlendMode("BLEND")
dealtCardsFrameDealerSplit.dealerCardImage4:SetDrawLayer("ARTWORK")

dealtCardsFrameDealerSplit.dealerCardImage5 = dealtCardsFrameDealerSplit:CreateTexture(nil, "OVERLAY")
dealtCardsFrameDealerSplit.dealerCardImage5:SetSize(85, 170)
dealtCardsFrameDealerSplit.dealerCardImage5:SetPoint("LEFT", dealtCardsFrameDealerSplit, 378, -7)
dealtCardsFrameDealerSplit.dealerCardImage5:SetBlendMode("BLEND")
dealtCardsFrameDealerSplit.dealerCardImage5:SetDrawLayer("ARTWORK")

dealtCardsFrameDealerSplit.dealerCardImage6 = dealtCardsFrameDealerSplit:CreateTexture(nil, "OVERLAY")
dealtCardsFrameDealerSplit.dealerCardImage6:SetSize(85, 170)
dealtCardsFrameDealerSplit.dealerCardImage6:SetPoint("LEFT", dealtCardsFrameDealerSplit, 470, -7)
dealtCardsFrameDealerSplit.dealerCardImage6:SetBlendMode("BLEND")
dealtCardsFrameDealerSplit.dealerCardImage6:SetDrawLayer("ARTWORK")

dealtCardsFrameDealerSplit.dealerCardImage7 = dealtCardsFrameDealerSplit:CreateTexture(nil, "OVERLAY")
dealtCardsFrameDealerSplit.dealerCardImage7:SetSize(85, 170)
dealtCardsFrameDealerSplit.dealerCardImage7:SetPoint("LEFT", dealtCardsFrameDealerSplit, 562, -7)
dealtCardsFrameDealerSplit.dealerCardImage7:SetBlendMode("BLEND")
dealtCardsFrameDealerSplit.dealerCardImage7:SetDrawLayer("ARTWORK")

dealtCardsFrameDealerSplit.dealerFirstCardText = dealtCardsFrameDealerSplit:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFrameDealerSplit.dealerFirstCardText:SetPoint("LEFT", dealtCardsFrameDealerSplit, 23, -80)
dealtCardsFrameDealerSplit.dealerFirstCardText:SetJustifyH("CENTER")
dealtCardsFrameDealerSplit.dealerFirstCardText:SetText("1st Card")
dealtCardsFrameDealerSplit.dealerFirstCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFrameDealerSplit.dealerFirstCardText:Hide()

dealtCardsFrameDealerSplit.dealerSecondCardText = dealtCardsFrameDealerSplit:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFrameDealerSplit.dealerSecondCardText:SetPoint("LEFT", dealtCardsFrameDealerSplit, 112, -80)
dealtCardsFrameDealerSplit.dealerSecondCardText:SetJustifyH("CENTER")
dealtCardsFrameDealerSplit.dealerSecondCardText:SetText("2nd Card")
dealtCardsFrameDealerSplit.dealerSecondCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFrameDealerSplit.dealerSecondCardText:Hide()

dealtCardsFrameDealerSplit.dealerThirdCardText = dealtCardsFrameDealerSplit:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFrameDealerSplit.dealerThirdCardText:SetPoint("LEFT", dealtCardsFrameDealerSplit, 207, -80)
dealtCardsFrameDealerSplit.dealerThirdCardText:SetJustifyH("CENTER")
dealtCardsFrameDealerSplit.dealerThirdCardText:SetText("3rd Card")
dealtCardsFrameDealerSplit.dealerThirdCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFrameDealerSplit.dealerThirdCardText:Hide()

dealtCardsFrameDealerSplit.dealerFourthCardText = dealtCardsFrameDealerSplit:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFrameDealerSplit.dealerFourthCardText:SetPoint("LEFT", dealtCardsFrameDealerSplit, 299, -80)
dealtCardsFrameDealerSplit.dealerFourthCardText:SetJustifyH("CENTER")
dealtCardsFrameDealerSplit.dealerFourthCardText:SetText("4th Card")
dealtCardsFrameDealerSplit.dealerFourthCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFrameDealerSplit.dealerFourthCardText:Hide()

dealtCardsFrameDealerSplit.dealerFifthCardText = dealtCardsFrameDealerSplit:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFrameDealerSplit.dealerFifthCardText:SetPoint("LEFT", dealtCardsFrameDealerSplit, 392, -80)
dealtCardsFrameDealerSplit.dealerFifthCardText:SetJustifyH("CENTER")
dealtCardsFrameDealerSplit.dealerFifthCardText:SetText("5th Card")
dealtCardsFrameDealerSplit.dealerFifthCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFrameDealerSplit.dealerFifthCardText:Hide()

dealtCardsFrameDealerSplit.dealerSixthCardText = dealtCardsFrameDealerSplit:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFrameDealerSplit.dealerSixthCardText:SetPoint("LEFT", dealtCardsFrameDealerSplit, 483, -80)
dealtCardsFrameDealerSplit.dealerSixthCardText:SetJustifyH("CENTER")
dealtCardsFrameDealerSplit.dealerSixthCardText:SetText("6th Card")
dealtCardsFrameDealerSplit.dealerSixthCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFrameDealerSplit.dealerSixthCardText:Hide()

dealtCardsFrameDealerSplit.dealerSeventhCardText = dealtCardsFrameDealerSplit:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
dealtCardsFrameDealerSplit.dealerSeventhCardText:SetPoint("LEFT", dealtCardsFrameDealerSplit, 576, -80)
dealtCardsFrameDealerSplit.dealerSeventhCardText:SetJustifyH("CENTER")
dealtCardsFrameDealerSplit.dealerSeventhCardText:SetText("7th Card")
dealtCardsFrameDealerSplit.dealerSeventhCardText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
dealtCardsFrameDealerSplit.dealerSeventhCardText:Hide()














-- >> CHAT WINDOW <<
-- >> CHAT WINDOW <<
-- >> CHAT WINDOW <<

local chatWindowHeight = 180
local totalHeight = 168
local lineHeight = 10

-- Create the chat window frame
chatWindowFrame = CreateFrame("Frame", "BlackjackChatWindowFrame", UIParent, "InsetFrameTemplate")
chatWindowFrame:SetSize(306, 200)
chatWindowFrame:SetPoint("BOTTOMRIGHT", playerFrame, -5, 5)
chatWindowFrame:SetFrameStrata("HIGH")
chatWindowFrame:SetFrameLevel(5)
chatWindowFrame:Hide()

-- Setting a title
chatWindowFrame.title = chatWindowFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
chatWindowFrame.title:SetPoint("TOP", chatWindowFrame, 0, -7)
chatWindowFrame.title:SetText("Chat Log")

-- Create the scroll frame
chatWindowFrame.ScrollFrame = CreateFrame("ScrollFrame", nil, chatWindowFrame, "UIPanelScrollFrameTemplate")
chatWindowFrame.ScrollFrame:SetPoint("TOPLEFT", chatWindowFrame, "TOPLEFT", 10, -27)
chatWindowFrame.ScrollFrame:SetPoint("BOTTOMRIGHT", chatWindowFrame, "BOTTOMRIGHT", -10, 9)
chatWindowFrame.ScrollFrame:SetClipsChildren(true)

-- Create the child frame for scrolling content
local child = CreateFrame("Frame", nil, chatWindowFrame.ScrollFrame)
child:SetSize(288, chatWindowHeight)

child.bg = child:CreateTexture(nil, "BACKGROUND")
child.bg:SetAllPoints(true)

local function AddMessageToScrollFrame(message, sender)
    -- Create a new font string for the message
    local newMessage = child:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
    newMessage:SetJustifyH("LEFT")
    
    -- Check the sender and set text color accordingly
    local textColor
    if sender == "Blackjackk-Earthshaker" then
        textColor = {0.961, 0.294, 0.271}  -- Reddish color for Blackjackk-Earthshaker
    elseif string.find(message, "Blackjackk rolls") then
        textColor = {0.969, 0.969, 0.451}  -- Yellow color for /roll command
    else
        textColor = {0.961, 0.451, 0.208}  -- Default color for other senders
    end

    newMessage:SetTextColor(unpack(textColor))

    -- Replace specific tags with ">>"
    local replacements = {
        ["{square}"] = ">>",
        ["{star}"] = ">>",
        ["{cross}"] = ">>",
        ["{triangle}"] = ">>",
        ["{skull}"] = ">>",
        ["{circle}"] = ">>",
        ["{diamond}"] = ">>",
    }

    for tag, replacement in pairs(replacements) do
        message = string.gsub(message, tag, replacement)
    end

    newMessage:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")

    -- Calculate the maximum width for a line
    local maxWidth = child:GetWidth() - 16  -- Adjusted for left margin (8) and right margin (8)

    -- Split the message into words
    local words = {strsplit(" ", message)}
    local lines = {""}
    local currentLine = 1

    for i, word in ipairs(words) do
        -- Check if adding the word exceeds the maximum width
        local testString = lines[currentLine] == "" and word or lines[currentLine] .. " " .. word
        newMessage:SetText(testString)
        if newMessage:GetWidth() <= maxWidth then
            -- If the word fits, add it to the current line
            lines[currentLine] = testString
        else
            -- If the word exceeds the width, start a new line
            currentLine = currentLine + 1
            lines[currentLine] = word
        end
    end

    -- Position the new message below the previous messages
    for i, line in ipairs(lines) do
        local formattedLine = line

        -- Skip adding "•" for continuation lines
        if i == 1 then
            if string.find(line, ">>") then
                formattedLine = line:gsub("•", "")
            else
                formattedLine = "• " .. line
            end
        end

        newMessage:SetText(formattedLine)
        newMessage:SetPoint("TOPLEFT", 0, -totalHeight)

        -- Update the total height with the height of the new message and spacing
        totalHeight = totalHeight + newMessage:GetHeight() + 1

        -- Set the height of the scroll child
        child:SetHeight(totalHeight)

        -- Calculate the maximum scroll range
        local maxScroll = totalHeight - chatWindowHeight - 10
        maxScroll = math.max(0, maxScroll)  -- Ensure maxScroll is not negative

        -- Set the scroll frame scroll range to the total height
        chatWindowFrame.ScrollFrame:SetVerticalScroll(maxScroll)

        -- Create a new font string for the next line
        newMessage = child:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
        newMessage:SetJustifyH("LEFT")
        newMessage:SetTextColor(unpack(textColor))
        newMessage:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
    end

    -- Always scroll to the bottom to show the latest messages
    chatWindowFrame.ScrollFrame:UpdateScrollChildRect()

    local newValue = chatWindowFrame.ScrollFrame:GetVerticalScrollRange()
    chatWindowFrame.ScrollFrame:SetVerticalScroll(newValue)
end

-- Set the child frame as the scroll child
chatWindowFrame.ScrollFrame:SetScrollChild(child)

chatWindowFrame.ScrollFrame:SetScript("OnMouseWheel", function(self, delta)
    local scrollValue = self:GetVerticalScroll()
    local newValue = scrollValue - (delta * lineHeight)

    if (newValue < 0) then
        newValue = 0
    elseif (newValue > self:GetVerticalScrollRange()) then
        newValue = self:GetVerticalScrollRange()
    end

    self:SetVerticalScroll(newValue)
end)


























-- >> SIDEBET NOTIFICATION WINDOWS <<
-- >> SIDEBET NOTIFICATION WINDOWS <<
-- >> SIDEBET NOTIFICATION WINDOWS <<

-- Creating the PP sideBetWinFrame
sideBetWinFramePP = CreateFrame("Frame", "BlackjackPayoutsFrame", UIParent, "BasicFrameTemplateWithInset")
sideBetWinFramePP:SetSize(325, 180)
sideBetWinFramePP:SetPoint("TOPLEFT", playerFrame, 0, 0)
sideBetWinFramePP:SetFrameStrata("HIGH")
sideBetWinFramePP:SetFrameLevel(7)
sideBetWinFramePP:Hide()

-- Setting a title
sideBetWinFramePP.title = sideBetWinFramePP:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
sideBetWinFramePP.title:SetPoint("TOP", sideBetWinFramePP, 0, -5)
sideBetWinFramePP.title:SetText("Side Bet Notification")
sideBetWinFramePP.title:Hide()

sideBetWinFramePP.PPtext = sideBetWinFramePP:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
sideBetWinFramePP.PPtext:SetPoint("TOPLEFT", sideBetWinFramePP, 5, -5)
sideBetWinFramePP.PPtext:SetJustifyH("CENTER")
sideBetWinFramePP.PPtext:SetText("PP")
sideBetWinFramePP.PPtext:SetTextColor(1, 0.298, 0.298)
sideBetWinFramePP.PPtext:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
sideBetWinFramePP.PPtext:Hide()

sideBetWinFramePP.MixedPairText = sideBetWinFramePP:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
sideBetWinFramePP.MixedPairText:SetPoint("TOP", sideBetWinFramePP, 0, -31)
sideBetWinFramePP.MixedPairText:SetJustifyH("CENTER")
sideBetWinFramePP.MixedPairText:SetText("You hit a Mixed Pair!\nPayout is 5:1")
sideBetWinFramePP.MixedPairText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
sideBetWinFramePP.MixedPairText:Hide()

sideBetWinFramePP.ColouredPairText = sideBetWinFramePP:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
sideBetWinFramePP.ColouredPairText:SetPoint("TOP", sideBetWinFramePP, 0, -31)
sideBetWinFramePP.ColouredPairText:SetJustifyH("CENTER")
sideBetWinFramePP.ColouredPairText:SetText("You hit a Coloured Pair!\nPayout is 10:1")
sideBetWinFramePP.ColouredPairText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
sideBetWinFramePP.ColouredPairText:Hide()

sideBetWinFramePP.PerfectPairText = sideBetWinFramePP:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
sideBetWinFramePP.PerfectPairText:SetPoint("TOP", sideBetWinFramePP, 0, -31)
sideBetWinFramePP.PerfectPairText:SetJustifyH("CENTER")
sideBetWinFramePP.PerfectPairText:SetText("You hit a Perfect Pair!\nPayout is 30:1")
sideBetWinFramePP.PerfectPairText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
sideBetWinFramePP.PerfectPairText:Hide()

sideBetWinFramePP.player1PPCardImage1 = sideBetWinFramePP:CreateTexture(nil, "OVERLAY")
sideBetWinFramePP.player1PPCardImage1:SetSize(72, 144)
sideBetWinFramePP.player1PPCardImage1:SetPoint("CENTER", sideBetWinFramePP, -40, -23)
sideBetWinFramePP.player1PPCardImage1:SetBlendMode("BLEND")
sideBetWinFramePP.player1PPCardImage1:SetDrawLayer("ARTWORK")
sideBetWinFramePP.player1PPCardImage1:Hide()

sideBetWinFramePP.player1PPCardImage2 = sideBetWinFramePP:CreateTexture(nil, "OVERLAY")
sideBetWinFramePP.player1PPCardImage2:SetSize(72, 144)
sideBetWinFramePP.player1PPCardImage2:SetPoint("CENTER", sideBetWinFramePP, 40, -23)
sideBetWinFramePP.player1PPCardImage2:SetBlendMode("BLEND")
sideBetWinFramePP.player1PPCardImage2:SetDrawLayer("ARTWORK")
sideBetWinFramePP.player1PPCardImage2:Hide()

sideBetWinFramePP.player2PPCardImage1 = sideBetWinFramePP:CreateTexture(nil, "OVERLAY")
sideBetWinFramePP.player2PPCardImage1:SetSize(72, 144)
sideBetWinFramePP.player2PPCardImage1:SetPoint("CENTER", sideBetWinFramePP, -40, -23)
sideBetWinFramePP.player2PPCardImage1:SetBlendMode("BLEND")
sideBetWinFramePP.player2PPCardImage1:SetDrawLayer("ARTWORK")
sideBetWinFramePP.player2PPCardImage1:Hide()

sideBetWinFramePP.player2PPCardImage2 = sideBetWinFramePP:CreateTexture(nil, "OVERLAY")
sideBetWinFramePP.player2PPCardImage2:SetSize(72, 144)
sideBetWinFramePP.player2PPCardImage2:SetPoint("CENTER", sideBetWinFramePP, 40, -23)
sideBetWinFramePP.player2PPCardImage2:SetBlendMode("BLEND")
sideBetWinFramePP.player2PPCardImage2:SetDrawLayer("ARTWORK")
sideBetWinFramePP.player2PPCardImage2:Hide()
















-- Creating the 21+3 sideBetWinFrame
sideBetWinFrame213 = CreateFrame("Frame", "BlackjackPayoutsFrame", UIParent, "BasicFrameTemplateWithInset")
sideBetWinFrame213:SetSize(325, 180)
sideBetWinFrame213:SetPoint("TOPLEFT", playerFrame, 0, -180)
sideBetWinFrame213:SetFrameStrata("HIGH")
sideBetWinFrame213:SetFrameLevel(7)
sideBetWinFrame213:Hide()

-- Setting a title
sideBetWinFrame213.title = sideBetWinFrame213:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
sideBetWinFrame213.title:SetPoint("TOP", sideBetWinFrame213, 0, -5)
sideBetWinFrame213.title:SetText("Side Bet Notification")
sideBetWinFrame213.title:Hide()

sideBetWinFrame213.t213text = sideBetWinFrame213:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
sideBetWinFrame213.t213text:SetPoint("TOPLEFT", sideBetWinFrame213, 5, -5)
sideBetWinFrame213.t213text:SetJustifyH("CENTER")
sideBetWinFrame213.t213text:SetText("21+3")
sideBetWinFrame213.t213text:SetTextColor(1, 0.298, 0.298)
sideBetWinFrame213.t213text:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
sideBetWinFrame213.t213text:Hide()

sideBetWinFrame213.FlushText = sideBetWinFrame213:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
sideBetWinFrame213.FlushText:SetPoint("TOP", sideBetWinFrame213, 0, -31)
sideBetWinFrame213.FlushText:SetJustifyH("CENTER")
sideBetWinFrame213.FlushText:SetText("You hit a Flush!\nPayout is 5:1")
sideBetWinFrame213.FlushText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
sideBetWinFrame213.FlushText:Hide()

sideBetWinFrame213.StraightText = sideBetWinFrame213:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
sideBetWinFrame213.StraightText:SetPoint("TOP", sideBetWinFrame213, 0, -31)
sideBetWinFrame213.StraightText:SetJustifyH("CENTER")
sideBetWinFrame213.StraightText:SetText("You hit a Straight!\nPayout is 10:1")
sideBetWinFrame213.StraightText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
sideBetWinFrame213.StraightText:Hide()

sideBetWinFrame213.ThreeOfAKindText = sideBetWinFrame213:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
sideBetWinFrame213.ThreeOfAKindText:SetPoint("TOP", sideBetWinFrame213, 0, -31)
sideBetWinFrame213.ThreeOfAKindText:SetJustifyH("CENTER")
sideBetWinFrame213.ThreeOfAKindText:SetText("You hit a Three of a Kind!\nPayout is 30:1")
sideBetWinFrame213.ThreeOfAKindText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
sideBetWinFrame213.ThreeOfAKindText:Hide()

sideBetWinFrame213.StraightFlushText = sideBetWinFrame213:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
sideBetWinFrame213.StraightFlushText:SetPoint("TOP", sideBetWinFrame213, 0, -31)
sideBetWinFrame213.StraightFlushText:SetJustifyH("CENTER")
sideBetWinFrame213.StraightFlushText:SetText("You hit a Straight Flush!\nPayout is 40:1")
sideBetWinFrame213.StraightFlushText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
sideBetWinFrame213.StraightFlushText:Hide()

sideBetWinFrame213.SuitedThreeOfAKindText = sideBetWinFrame213:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
sideBetWinFrame213.SuitedThreeOfAKindText:SetPoint("TOP", sideBetWinFrame213, 0, -31)
sideBetWinFrame213.SuitedThreeOfAKindText:SetJustifyH("CENTER")
sideBetWinFrame213.SuitedThreeOfAKindText:SetText("You hit a Suited Three of a Kind!\nPayout is 100:1")
sideBetWinFrame213.SuitedThreeOfAKindText:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
sideBetWinFrame213.SuitedThreeOfAKindText:Hide()

sideBetWinFrame213.player1213CardImage1 = sideBetWinFrame213:CreateTexture(nil, "OVERLAY")
sideBetWinFrame213.player1213CardImage1:SetSize(72, 144)
sideBetWinFrame213.player1213CardImage1:SetPoint("CENTER", sideBetWinFrame213, -100, -23)
sideBetWinFrame213.player1213CardImage1:SetBlendMode("BLEND")
sideBetWinFrame213.player1213CardImage1:SetDrawLayer("ARTWORK")
sideBetWinFrame213.player1213CardImage1:Hide()

sideBetWinFrame213.player1213CardImage2 = sideBetWinFrame213:CreateTexture(nil, "OVERLAY")
sideBetWinFrame213.player1213CardImage2:SetSize(72, 144)
sideBetWinFrame213.player1213CardImage2:SetPoint("CENTER", sideBetWinFrame213, -20, -23)
sideBetWinFrame213.player1213CardImage2:SetBlendMode("BLEND")
sideBetWinFrame213.player1213CardImage2:SetDrawLayer("ARTWORK")
sideBetWinFrame213.player1213CardImage2:Hide()

sideBetWinFrame213.dealer213CardImage1 = sideBetWinFrame213:CreateTexture(nil, "OVERLAY")
sideBetWinFrame213.dealer213CardImage1:SetSize(72, 144)
sideBetWinFrame213.dealer213CardImage1:SetPoint("CENTER", sideBetWinFrame213, 100, -23)
sideBetWinFrame213.dealer213CardImage1:SetBlendMode("BLEND")
sideBetWinFrame213.dealer213CardImage1:SetDrawLayer("ARTWORK")
sideBetWinFrame213.dealer213CardImage1:Hide()

sideBetWinFrame213.player2213CardImage1 = sideBetWinFrame213:CreateTexture(nil, "OVERLAY")
sideBetWinFrame213.player2213CardImage1:SetSize(72, 144)
sideBetWinFrame213.player2213CardImage1:SetPoint("CENTER", sideBetWinFrame213, -100, -23)
sideBetWinFrame213.player2213CardImage1:SetBlendMode("BLEND")
sideBetWinFrame213.player2213CardImage1:SetDrawLayer("ARTWORK")
sideBetWinFrame213.player2213CardImage1:Hide()

sideBetWinFrame213.player2213CardImage2 = sideBetWinFrame213:CreateTexture(nil, "OVERLAY")
sideBetWinFrame213.player2213CardImage2:SetSize(72, 144)
sideBetWinFrame213.player2213CardImage2:SetPoint("CENTER", sideBetWinFrame213, -20, -23)
sideBetWinFrame213.player2213CardImage2:SetBlendMode("BLEND")
sideBetWinFrame213.player2213CardImage2:SetDrawLayer("ARTWORK")
sideBetWinFrame213.player2213CardImage2:Hide()

sideBetWinFrame213.player2213CardImage3 = sideBetWinFrame213:CreateTexture(nil, "OVERLAY")
sideBetWinFrame213.player2213CardImage3:SetSize(72, 144)
sideBetWinFrame213.player2213CardImage3:SetPoint("CENTER", sideBetWinFrame213, 100, -23)
sideBetWinFrame213.player2213CardImage3:SetBlendMode("BLEND")
sideBetWinFrame213.player2213CardImage3:SetDrawLayer("ARTWORK")
sideBetWinFrame213.player2213CardImage3:Hide()

sideBetWinFrame213.PlusSymbol = sideBetWinFrame213:CreateTexture(nil, "OVERLAY")
sideBetWinFrame213.PlusSymbol:SetSize(32, 32)
sideBetWinFrame213.PlusSymbol:SetPoint("CENTER", sideBetWinFrame213, 40, -23)
sideBetWinFrame213.PlusSymbol:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\PlusSymbol.tga")
sideBetWinFrame213.PlusSymbol:SetBlendMode("BLEND")
sideBetWinFrame213.PlusSymbol:SetDrawLayer("ARTWORK")
sideBetWinFrame213.PlusSymbol:Hide()

function player1MixedPairNotification()
    sideBetWinFramePP:Show()
    sideBetWinFramePP.title:Show()
    sideBetWinFramePP.PPtext:Show()
    sideBetWinFramePP.MixedPairText:Show()
    sideBetWinFramePP.player1PPCardImage1:Show()
    sideBetWinFramePP.player1PPCardImage2:Show()
end

function player1ColouredPairNotification()
    sideBetWinFramePP:Show()
    sideBetWinFramePP.title:Show()
    sideBetWinFramePP.PPtext:Show()
    sideBetWinFramePP.ColouredPairText:Show()
    sideBetWinFramePP.player1PPCardImage1:Show()
    sideBetWinFramePP.player1PPCardImage2:Show()
end

function player1PerfectPairNotification()
    sideBetWinFramePP:Show()
    sideBetWinFramePP.title:Show()
    sideBetWinFramePP.PPtext:Show()
    sideBetWinFramePP.PerfectPairText:Show()
    sideBetWinFramePP.player1PPCardImage1:Show()
    sideBetWinFramePP.player1PPCardImage2:Show()
end

function player1SuitedThreeOfAKindNotification()

    sideBetWinFrame213:Show()
    sideBetWinFrame213.title:Show()
    sideBetWinFrame213.t213text:Show()
    sideBetWinFrame213.SuitedThreeOfAKindText:Show()
    sideBetWinFrame213.player1213CardImage1:Show()
    sideBetWinFrame213.player1213CardImage2:Show()
    sideBetWinFrame213.dealer213CardImage1:Show()
    sideBetWinFrame213.PlusSymbol:Show()

end

function player1StraightFlushNotification()

    sideBetWinFrame213:Show()
    sideBetWinFrame213.title:Show()
    sideBetWinFrame213.t213text:Show()
    sideBetWinFrame213.StraightFlushText:Show()
    sideBetWinFrame213.player1213CardImage1:Show()
    sideBetWinFrame213.player1213CardImage2:Show()
    sideBetWinFrame213.dealer213CardImage1:Show()
    sideBetWinFrame213.PlusSymbol:Show()

end

function player1ThreeOfAKindNotification()

    sideBetWinFrame213:Show()
    sideBetWinFrame213.title:Show()
    sideBetWinFrame213.t213text:Show()
    sideBetWinFrame213.ThreeOfAKindText:Show()
    sideBetWinFrame213.player1213CardImage1:Show()
    sideBetWinFrame213.player1213CardImage2:Show()
    sideBetWinFrame213.dealer213CardImage1:Show()
    sideBetWinFrame213.PlusSymbol:Show()

end

function player1StraightNotification()

    sideBetWinFrame213:Show()
    sideBetWinFrame213.title:Show()
    sideBetWinFrame213.t213text:Show()
    sideBetWinFrame213.StraightText:Show()
    sideBetWinFrame213.player1213CardImage1:Show()
    sideBetWinFrame213.player1213CardImage2:Show()
    sideBetWinFrame213.dealer213CardImage1:Show()
    sideBetWinFrame213.PlusSymbol:Show()

end

function player1FlushNotification()

    sideBetWinFrame213:Show()
    sideBetWinFrame213.title:Show()
    sideBetWinFrame213.t213text:Show()
    sideBetWinFrame213.FlushText:Show()
    sideBetWinFrame213.player1213CardImage1:Show()
    sideBetWinFrame213.player1213CardImage2:Show()
    sideBetWinFrame213.dealer213CardImage1:Show()
    sideBetWinFrame213.PlusSymbol:Show()

end

function player2MixedPairNotification()
    sideBetWinFramePP:Show()
    sideBetWinFramePP.title:Show()
    sideBetWinFramePP.PPtext:Show()
    sideBetWinFramePP.MixedPairText:Show()
    sideBetWinFramePP.player2PPCardImage1:Show()
    sideBetWinFramePP.player2PPCardImage2:Show()
end

function player2ColouredPairNotification()
    sideBetWinFramePP:Show()
    sideBetWinFramePP.title:Show()
    sideBetWinFramePP.PPtext:Show()
    sideBetWinFramePP.ColouredPairText:Show()
    sideBetWinFramePP.player2PPCardImage1:Show()
    sideBetWinFramePP.player2PPCardImage2:Show()
end

function player2PerfectPairNotification()
    sideBetWinFramePP:Show()
    sideBetWinFramePP.title:Show()
    sideBetWinFramePP.PPtext:Show()
    sideBetWinFramePP.PerfectPairText:Show()
    sideBetWinFramePP.player2PPCardImage1:Show()
    sideBetWinFramePP.player2PPCardImage2:Show()
end

function player2SuitedThreeOfAKindNotification()
    sideBetWinFrame213:Show()
    sideBetWinFrame213.title:Show()
    sideBetWinFrame213.t213text:Show()
    sideBetWinFrame213.SuitedThreeOfAKindText:Show()
    sideBetWinFrame213.player2213CardImage1:Show()
    sideBetWinFrame213.player2213CardImage2:Show()
    sideBetWinFrame213.dealer213CardImage1:Show()
    sideBetWinFrame213.PlusSymbol:Show()
end

function player2StraightFlushNotification()
    sideBetWinFrame213:Show()
    sideBetWinFrame213.title:Show()
    sideBetWinFrame213.t213text:Show()
    sideBetWinFrame213.StraightFlushText:Show()
    sideBetWinFrame213.player2213CardImage1:Show()
    sideBetWinFrame213.player2213CardImage2:Show()
    sideBetWinFrame213.dealer213CardImage1:Show()
    sideBetWinFrame213.PlusSymbol:Show()
end

function player2ThreeOfAKindNotification()
    sideBetWinFrame213:Show()
    sideBetWinFrame213.title:Show()
    sideBetWinFrame213.t213text:Show()
    sideBetWinFrame213.ThreeOfAKindText:Show()
    sideBetWinFrame213.player2213CardImage1:Show()
    sideBetWinFrame213.player2213CardImage2:Show()
    sideBetWinFrame213.dealer213CardImage1:Show()
    sideBetWinFrame213.PlusSymbol:Show()
end

function player2StraightNotification()
    sideBetWinFrame213:Show()
    sideBetWinFrame213.title:Show()
    sideBetWinFrame213.t213text:Show()
    sideBetWinFrame213.StraightText:Show()
    sideBetWinFrame213.player2213CardImage1:Show()
    sideBetWinFrame213.player2213CardImage2:Show()
    sideBetWinFrame213.dealer213CardImage1:Show()
    sideBetWinFrame213.PlusSymbol:Show()
end

function player2FlushNotification()
    sideBetWinFrame213:Show()
    sideBetWinFrame213.title:Show()
    sideBetWinFrame213.t213text:Show()
    sideBetWinFrame213.FlushText:Show()
    sideBetWinFrame213.player2213CardImage1:Show()
    sideBetWinFrame213.player2213CardImage2:Show()
    sideBetWinFrame213.dealer213CardImage1:Show()
    sideBetWinFrame213.PlusSymbol:Show()
end














playerFrame:SetScript("OnHide", function(self)
    bankrollFrame:Hide()
    rebetFrame:Hide()
    historyFrame:Hide()
    rulesFrame:Hide()
    payoutsFrame:Hide()
    sideBetWinFramePP:Hide()
    sideBetWinFrame213:Hide()
    dealtCardsFrameDealer:Hide()
    dealtCardsFramePlayer:Hide()
    chatWindowFrame:Hide()
end)

function resetHistory()
    player1totalBetAmount = 0
    player2totalBetAmount = 0
    player1totalWin = 0
    player2totalWin = 0
    player1totalLoss = 0
    player2totalLoss = 0
    player1totalProfit = 0
    player2totalProfit = 0
    historyFrame.player1totalWageredAmount:SetText("0 G")
    historyFrame.player2totalWageredAmount:SetText("0 G")
    historyFrame.player1totalWonAmount:SetText("0 G")
    historyFrame.player2totalWonAmount:SetText("0 G")
    historyFrame.player1totalLostAmount:SetText("0 G")
    historyFrame.player2totalLostAmount:SetText("0 G")
    historyFrame.player1ProfitAmount:SetText("0 G")
    historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
    historyFrame.player2ProfitAmount:SetText("0 G")
    historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
end

local function PlayerFrameHide()
    playerFrame:Hide()
    historyFrame:Hide()
    rulesFrame:Hide()
    rebetFrame:Hide()
    payoutsFrame:Hide()
    sideBetWinFramePP:Hide()
    initialFrame.joinButton:Disable()
    cashDeskFrame.joinButtonCashDesk:Disable()
    initialFrame:Show()
end
















playerFrame.player1CardTotalText = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.player1CardTotalText:SetPoint("BOTTOM", playerFrame, "BOTTOM", 385, 368)
playerFrame.player1CardTotalText:SetFont("Fonts\\FRIZQT__.TTF", 28, "OUTLINE")
playerFrame.player1CardTotalText:SetText("")

playerFrame.player1SplitHand1CardTotalText = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.player1SplitHand1CardTotalText:SetPoint("BOTTOM", playerFrame, "BOTTOM", 410, 395)
playerFrame.player1SplitHand1CardTotalText:SetFont("Fonts\\FRIZQT__.TTF", 22, "OUTLINE")
playerFrame.player1SplitHand1CardTotalText:SetText("")

playerFrame.player1SplitHand2CardTotalText = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.player1SplitHand2CardTotalText:SetPoint("BOTTOM", playerFrame, "BOTTOM", 372, 355)
playerFrame.player1SplitHand2CardTotalText:SetFont("Fonts\\FRIZQT__.TTF", 22, "OUTLINE")
playerFrame.player1SplitHand2CardTotalText:SetText("")

playerFrame.player2CardTotalText = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.player2CardTotalText:SetPoint("BOTTOM", playerFrame, "BOTTOM", 210, 230)
playerFrame.player2CardTotalText:SetFont("Fonts\\FRIZQT__.TTF", 28, "OUTLINE") -- Adjust the font and size as needed
playerFrame.player2CardTotalText:SetText("")

playerFrame.player3CardTotalText = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.player3CardTotalText:SetPoint("BOTTOM", playerFrame, "BOTTOM", 4, 180)
playerFrame.player3CardTotalText:SetFont("Fonts\\FRIZQT__.TTF", 28, "OUTLINE") -- Adjust the font and size as needed
playerFrame.player3CardTotalText:SetText("")

playerFrame.player4CardTotalText = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.player4CardTotalText:SetPoint("BOTTOM", playerFrame, "BOTTOM", -210, 230)
playerFrame.player4CardTotalText:SetFont("Fonts\\FRIZQT__.TTF", 28, "OUTLINE") -- Adjust the font and size as needed
playerFrame.player4CardTotalText:SetText("")

playerFrame.player5CardTotalText = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.player5CardTotalText:SetPoint("BOTTOM", playerFrame, "BOTTOM", -385, 368)
playerFrame.player5CardTotalText:SetFont("Fonts\\FRIZQT__.TTF", 28, "OUTLINE") -- Adjust the font and size as needed
playerFrame.player5CardTotalText:SetText("")

playerFrame.dealerCardTotalText = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.dealerCardTotalText:SetPoint("TOP", playerFrame, "TOP", -65, -148)
playerFrame.dealerCardTotalText:SetFont("Fonts\\FRIZQT__.TTF", 28, "OUTLINE") -- Adjust the font and size as needed
playerFrame.dealerCardTotalText:SetText("")


















-- >>> PLAYER 1 <<<
-- >>> PLAYER 1 <<<
-- >>> PLAYER 1 <<<

-- Buttons for Player 1
-- Hit
playerFrame.player1HitButton = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.player1HitButton:SetPoint("BOTTOM", playerFrame, 419, 275)
playerFrame.player1HitButton:SetSize(65, 30)
playerFrame.player1HitButton:SetText("Hit")
playerFrame.player1HitButton:Disable()
-- Stand
playerFrame.player1StandButton = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.player1StandButton:SetPoint("BOTTOM", playerFrame, 485, 275)
playerFrame.player1StandButton:SetSize(65, 30)
playerFrame.player1StandButton:SetText("Stand")
playerFrame.player1StandButton:Disable()
-- Double
playerFrame.player1DoubleButton = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.player1DoubleButton:SetPoint("BOTTOM", playerFrame, 419, 245)
playerFrame.player1DoubleButton:SetSize(65, 30)
playerFrame.player1DoubleButton:SetText("Double")
playerFrame.player1DoubleButton:Disable()
-- Split
playerFrame.player1SplitButton = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.player1SplitButton:SetPoint("BOTTOM", playerFrame, 485, 245)
playerFrame.player1SplitButton:SetSize(65, 30)
playerFrame.player1SplitButton:SetText("Split")
playerFrame.player1SplitButton:Disable()
-- Insurance Yes
playerFrame.player1InsuranceYesButton = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.player1InsuranceYesButton:SetPoint("BOTTOM", playerFrame, 387, 215)
playerFrame.player1InsuranceYesButton:SetSize(55, 30)
playerFrame.player1InsuranceYesButton:SetText("Yes")
playerFrame.player1InsuranceYesButton:Disable()
-- Insurance No
playerFrame.player1InsuranceNoButton = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.player1InsuranceNoButton:SetPoint("BOTTOM", playerFrame, 515, 215)
playerFrame.player1InsuranceNoButton:SetSize(55, 30)
playerFrame.player1InsuranceNoButton:SetText("No")
playerFrame.player1InsuranceNoButton:Disable()
-- Hit (Split H1)
playerFrame.player1HitButtonSplitH1 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.player1HitButtonSplitH1:SetPoint("BOTTOM", playerFrame, 485, 275)
playerFrame.player1HitButtonSplitH1:SetSize(65, 30)
playerFrame.player1HitButtonSplitH1:SetText("Hit")
playerFrame.player1HitButtonSplitH1:Disable()
-- Stand (Split H1)
playerFrame.player1StandButtonSplitH1 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.player1StandButtonSplitH1:SetPoint("BOTTOM", playerFrame, 485, 245)
playerFrame.player1StandButtonSplitH1:SetSize(65, 30)
playerFrame.player1StandButtonSplitH1:SetText("Stand")
playerFrame.player1StandButtonSplitH1:Disable()
-- Double (Split H1)
playerFrame.player1DoubleButtonSplitH1 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.player1DoubleButtonSplitH1:SetPoint("BOTTOM", playerFrame, 485, 215)
playerFrame.player1DoubleButtonSplitH1:SetSize(65, 30)
playerFrame.player1DoubleButtonSplitH1:SetText("Double")
playerFrame.player1DoubleButtonSplitH1:Disable()
-- Hit (Split H2)
playerFrame.player1HitButtonSplitH2 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.player1HitButtonSplitH2:SetPoint("BOTTOM", playerFrame, 419, 275)
playerFrame.player1HitButtonSplitH2:SetSize(65, 30)
playerFrame.player1HitButtonSplitH2:SetText("Hit")
playerFrame.player1HitButtonSplitH2:Disable()
-- Stand (Split H2)
playerFrame.player1StandButtonSplitH2 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.player1StandButtonSplitH2:SetPoint("BOTTOM", playerFrame, 419, 245)
playerFrame.player1StandButtonSplitH2:SetSize(65, 30)
playerFrame.player1StandButtonSplitH2:SetText("Stand")
playerFrame.player1StandButtonSplitH2:Disable()
-- Double (Split H2)
playerFrame.player1DoubleButtonSplitH2 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.player1DoubleButtonSplitH2:SetPoint("BOTTOM", playerFrame, 419, 215)
playerFrame.player1DoubleButtonSplitH2:SetSize(65, 30)
playerFrame.player1DoubleButtonSplitH2:SetText("Double")
playerFrame.player1DoubleButtonSplitH2:Disable()
-- Main Bet Confirm
player1ConfirmMainBetButton = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
player1ConfirmMainBetButton:SetPoint("BOTTOM", playerFrame, 485, 335)
player1ConfirmMainBetButton:SetSize(65, 30)
player1ConfirmMainBetButton:SetText("Bet")
-- Perfect Pairs Confirm
player1ConfirmPPBetButton = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
player1ConfirmPPBetButton:SetPoint("BOTTOM", playerFrame, 309, 335)
player1ConfirmPPBetButton:SetSize(43, 25)
player1ConfirmPPBetButton:SetText("Bet")
-- 21+3 Confirm
player1Confirm213BetButton = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
player1Confirm213BetButton:SetPoint("BOTTOM", playerFrame, 385, 470)
player1Confirm213BetButton:SetSize(43, 25)
player1Confirm213BetButton:SetText("Bet")
-- Wagers for Player 1
-- Main Bet
player1MainBetEditBox = CreateFrame("EditBox", nil, playerFrame, "InputBoxTemplate")
player1MainBetEditBox:SetSize(55, 30)
player1MainBetEditBox:SetPoint("BOTTOM", playerFrame, 422, 335)
player1MainBetEditBox:SetAutoFocus(false)
player1MainBetEditBox:SetNumeric(true)
player1MainBetEditBox:Hide()
-- Split Hand 1
player1SplitH1EditBox = CreateFrame("EditBox", nil, playerFrame, "InputBoxTemplate")
player1SplitH1EditBox:SetSize(55, 30)
player1SplitH1EditBox:SetPoint("BOTTOM", playerFrame, 487, 335)
player1SplitH1EditBox:SetAutoFocus(false)
player1SplitH1EditBox:SetNumeric(true)
player1SplitH1EditBox:ClearFocus()
player1SplitH1EditBox:Disable()
-- Split Hand 2
player1SplitH2EditBox = CreateFrame("EditBox", nil, playerFrame, "InputBoxTemplate")
player1SplitH2EditBox:SetSize(55, 30)
player1SplitH2EditBox:SetPoint("BOTTOM", playerFrame, 422, 335)
player1SplitH2EditBox:SetAutoFocus(false)
player1SplitH2EditBox:SetNumeric(true)
player1SplitH2EditBox:ClearFocus()
player1SplitH2EditBox:Disable()
-- Perfect Pairs
player1PPBetEditBox = CreateFrame("EditBox", nil, playerFrame, "InputBoxTemplate")
player1PPBetEditBox:SetSize(35, 30)
player1PPBetEditBox:SetPoint("BOTTOM", playerFrame, 312, 355)
player1PPBetEditBox:SetAutoFocus(false)
player1PPBetEditBox:SetNumeric(true)
-- 21+3
player1213BetEditBox = CreateFrame("EditBox", nil, playerFrame, "InputBoxTemplate")
player1213BetEditBox:SetSize(35, 30)
player1213BetEditBox:SetPoint("BOTTOM", playerFrame, 388, 490)
player1213BetEditBox:SetAutoFocus(false)
player1213BetEditBox:SetNumeric(true)
-- Labels for Player 1
-- Main Bet
playerFrame.player1MainBetTitle = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.player1MainBetTitle:SetPoint("BOTTOM", playerFrame, 421, 362)
playerFrame.player1MainBetTitle:SetJustifyH("CENTER")
playerFrame.player1MainBetTitle:SetText("Main Bet")
playerFrame.player1MainBetTitle:SetFont("Fonts\\FRIZQT__.TTF", 8, "OUTLINE")
-- Split Hand 1
playerFrame.player1SplitH1Title = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.player1SplitH1Title:SetPoint("BOTTOM", playerFrame, 486, 362)
playerFrame.player1SplitH1Title:SetJustifyH("CENTER")
playerFrame.player1SplitH1Title:SetText("Hand 1")
playerFrame.player1SplitH1Title:SetFont("Fonts\\FRIZQT__.TTF", 8, "OUTLINE")
-- Split Hand 2
playerFrame.player1SplitH2Title = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.player1SplitH2Title:SetPoint("BOTTOM", playerFrame, 421, 362)
playerFrame.player1SplitH2Title:SetJustifyH("CENTER")
playerFrame.player1SplitH2Title:SetText("Hand 2")
playerFrame.player1SplitH2Title:SetFont("Fonts\\FRIZQT__.TTF", 8, "OUTLINE")
-- Main Bet Amount
player1MainBetAmount = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
player1MainBetAmount:SetPoint("CENTER", playerFrame, 338, 100)
player1MainBetAmount:SetJustifyH("CENTER")
player1MainBetAmount:SetFont("Fonts\\FRIZQT__.TTF", 8, "OUTLINE")
-- Split Hand 1 Amount
player1SplitH1BetAmount = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
player1SplitH1BetAmount:SetPoint("CENTER", playerFrame, 355, 115)
player1SplitH1BetAmount:SetJustifyH("CENTER")
player1SplitH1BetAmount:SetFont("Fonts\\FRIZQT__.TTF", 8, "OUTLINE")
-- Split Hand 2 Amount
player1SplitH2BetAmount = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
player1SplitH2BetAmount:SetPoint("CENTER", playerFrame, 327, 91)
player1SplitH2BetAmount:SetJustifyH("CENTER")
player1SplitH2BetAmount:SetFont("Fonts\\FRIZQT__.TTF", 8, "OUTLINE")
-- Perfect Pairs
playerFrame.player1PPBetTitle = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.player1PPBetTitle:SetPoint("BOTTOM", playerFrame, 276, 353)
playerFrame.player1PPBetTitle:SetJustifyH("CENTER")
playerFrame.player1PPBetTitle:SetText("PP")
playerFrame.player1PPBetTitle:SetFont("Fonts\\FRIZQT__.TTF", 15, "OUTLINE")
-- Perfect Pairs Amount
player1PPBetAmount = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
player1PPBetAmount:SetPoint("CENTER", playerFrame, 275, 60)
player1PPBetAmount:SetJustifyH("CENTER")
player1PPBetAmount:SetFont("Fonts\\FRIZQT__.TTF", 8, "OUTLINE")
-- 21+3
playerFrame.player1213BetTitle = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.player1213BetTitle:SetPoint("BOTTOM", playerFrame, 430, 488)
playerFrame.player1213BetTitle:SetJustifyH("CENTER")
playerFrame.player1213BetTitle:SetText("21+3")
playerFrame.player1213BetTitle:SetFont("Fonts\\FRIZQT__.TTF", 15, "OUTLINE")
-- 21+3 Amount
player1213BetAmount = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
player1213BetAmount:SetPoint("CENTER", playerFrame, 345, 156)
player1213BetAmount:SetJustifyH("CENTER")
player1213BetAmount:SetFont("Fonts\\FRIZQT__.TTF", 8, "OUTLINE")
-- Insurance Amount
playerFrame.player1InsuranceBetAmount = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.player1InsuranceBetAmount:SetPoint("BOTTOM", playerFrame, 541, 372)
playerFrame.player1InsuranceBetAmount:SetJustifyH("CENTER")
playerFrame.player1InsuranceBetAmount:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
-- Player Name
playerFrame.player1Name = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.player1Name:SetPoint("BOTTOM", playerFrame, 452, 311)
playerFrame.player1Name:SetText(UnitName("player"))
playerFrame.player1Name:SetFont("Fonts\\FRIZQT__.TTF", 22, "OUTLINE")
-- Insurance
playerFrame.player1InsuranceTitle = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.player1InsuranceTitle:SetPoint("BOTTOM", playerFrame, 452, 229) 
playerFrame.player1InsuranceTitle:SetText("Insurance")
playerFrame.player1InsuranceTitle:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
-- Insurance (if available)
playerFrame.player1InsuranceSubtitle = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.player1InsuranceSubtitle:SetPoint("BOTTOM", playerFrame, 452, 219)
playerFrame.player1InsuranceSubtitle:SetText("(if available)")
playerFrame.player1InsuranceSubtitle:SetFont("Fonts\\FRIZQT__.TTF", 8, "OUTLINE")

-- Images for Player 1
-- Main Bet
playerFrame.player1MainBetCoins = playerFrame:CreateTexture(nil, "OVERLAY")
playerFrame.player1MainBetCoins:SetSize(128, 128)
playerFrame.player1MainBetCoins:SetPoint("CENTER", playerFrame, 355, 70)
playerFrame.player1MainBetCoins:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CoinsBet.tga")
playerFrame.player1MainBetCoins:SetBlendMode("BLEND")
playerFrame.player1MainBetCoins:SetDrawLayer("OVERLAY")
playerFrame.player1MainBetCoins:Hide()
-- Win
playerFrame.player1NormalWinCoins = playerFrame:CreateTexture(nil, "OVERLAY")
playerFrame.player1NormalWinCoins:SetSize(128, 128)
playerFrame.player1NormalWinCoins:SetPoint("CENTER", playerFrame, 355, 70)
playerFrame.player1NormalWinCoins:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CoinsWin.tga")
playerFrame.player1NormalWinCoins:SetBlendMode("BLEND")
playerFrame.player1NormalWinCoins:SetDrawLayer("OVERLAY")
playerFrame.player1NormalWinCoins:Hide()
-- Split Hand 2 Bet
playerFrame.player1SplitHand2Coins = playerFrame:CreateTexture(nil, "OVERLAY")
playerFrame.player1SplitHand2Coins:SetSize(128, 128)
playerFrame.player1SplitHand2Coins:SetPoint("CENTER", playerFrame, 345, 58)
playerFrame.player1SplitHand2Coins:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CoinsBet.tga")
playerFrame.player1SplitHand2Coins:SetBlendMode("BLEND")
playerFrame.player1SplitHand2Coins:SetDrawLayer("OVERLAY")
playerFrame.player1SplitHand2Coins:Hide()
-- Split Double Hand 2 Bet
playerFrame.player1SplitHand2DoubleCoins = playerFrame:CreateTexture(nil, "OVERLAY")
playerFrame.player1SplitHand2DoubleCoins:SetSize(128, 128)
playerFrame.player1SplitHand2DoubleCoins:SetPoint("CENTER", playerFrame, 345, 58)
playerFrame.player1SplitHand2DoubleCoins:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CoinsWin.tga")
playerFrame.player1SplitHand2DoubleCoins:SetBlendMode("BLEND")
playerFrame.player1SplitHand2DoubleCoins:SetDrawLayer("OVERLAY")
playerFrame.player1SplitHand2DoubleCoins:Hide()
-- Split Win Hand 2
playerFrame.player1SplitHand2NormalWinCoins = playerFrame:CreateTexture(nil, "OVERLAY")
playerFrame.player1SplitHand2NormalWinCoins:SetSize(128, 128)
playerFrame.player1SplitHand2NormalWinCoins:SetPoint("CENTER", playerFrame, 345, 58)
playerFrame.player1SplitHand2NormalWinCoins:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CoinsWin.tga")
playerFrame.player1SplitHand2NormalWinCoins:SetBlendMode("BLEND")
playerFrame.player1SplitHand2NormalWinCoins:SetDrawLayer("OVERLAY")
playerFrame.player1SplitHand2NormalWinCoins:Hide()
-- Split Hand 1 Bet
playerFrame.player1SplitHand1Coins = playerFrame:CreateTexture(nil, "OVERLAY")
playerFrame.player1SplitHand1Coins:SetSize(128, 128)
playerFrame.player1SplitHand1Coins:SetPoint("CENTER", playerFrame, 372, 83)
playerFrame.player1SplitHand1Coins:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CoinsBet.tga")
playerFrame.player1SplitHand1Coins:SetBlendMode("BLEND")
playerFrame.player1SplitHand1Coins:SetDrawLayer("OVERLAY")
playerFrame.player1SplitHand1Coins:Hide()
-- Split Double Hand 1 Bet
playerFrame.player1SplitHand1DoubleCoins = playerFrame:CreateTexture(nil, "OVERLAY")
playerFrame.player1SplitHand1DoubleCoins:SetSize(128, 128)
playerFrame.player1SplitHand1DoubleCoins:SetPoint("CENTER", playerFrame, 372, 83)
playerFrame.player1SplitHand1DoubleCoins:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CoinsWin.tga")
playerFrame.player1SplitHand1DoubleCoins:SetBlendMode("BLEND")
playerFrame.player1SplitHand1DoubleCoins:SetDrawLayer("OVERLAY")
playerFrame.player1SplitHand1DoubleCoins:Hide()
-- Split Win Hand 1
playerFrame.player1SplitHand1NormalWinCoins = playerFrame:CreateTexture(nil, "OVERLAY")
playerFrame.player1SplitHand1NormalWinCoins:SetSize(128, 128)
playerFrame.player1SplitHand1NormalWinCoins:SetPoint("CENTER", playerFrame, 372, 83)
playerFrame.player1SplitHand1NormalWinCoins:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CoinsWin.tga")
playerFrame.player1SplitHand1NormalWinCoins:SetBlendMode("BLEND")
playerFrame.player1SplitHand1NormalWinCoins:SetDrawLayer("OVERLAY")
playerFrame.player1SplitHand1NormalWinCoins:Hide()
-- Blackjack Win
playerFrame.player1BJWinCoins = playerFrame:CreateTexture(nil, "OVERLAY")
playerFrame.player1BJWinCoins:SetSize(128, 128)
playerFrame.player1BJWinCoins:SetPoint("CENTER", playerFrame, 355, 70)
playerFrame.player1BJWinCoins:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CoinsBJWin.tga")
playerFrame.player1BJWinCoins:SetBlendMode("BLEND")
playerFrame.player1BJWinCoins:SetDrawLayer("OVERLAY")
playerFrame.player1BJWinCoins:Hide()
-- Split Win Hand 2
playerFrame.player1SplitHand2BJWinCoins = playerFrame:CreateTexture(nil, "OVERLAY")
playerFrame.player1SplitHand2BJWinCoins:SetSize(128, 128)
playerFrame.player1SplitHand2BJWinCoins:SetPoint("CENTER", playerFrame, 345, 58)
playerFrame.player1SplitHand2BJWinCoins:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CoinsBJWin.tga")
playerFrame.player1SplitHand2BJWinCoins:SetBlendMode("BLEND")
playerFrame.player1SplitHand2BJWinCoins:SetDrawLayer("OVERLAY")
playerFrame.player1SplitHand2BJWinCoins:Hide()
-- Split Win Hand 1
playerFrame.player1SplitHand1BJWinCoins = playerFrame:CreateTexture(nil, "OVERLAY")
playerFrame.player1SplitHand1BJWinCoins:SetSize(128, 128)
playerFrame.player1SplitHand1BJWinCoins:SetPoint("CENTER", playerFrame, 372, 83)
playerFrame.player1SplitHand1BJWinCoins:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CoinsBJWin.tga")
playerFrame.player1SplitHand1BJWinCoins:SetBlendMode("BLEND")
playerFrame.player1SplitHand1BJWinCoins:SetDrawLayer("OVERLAY")
playerFrame.player1SplitHand1BJWinCoins:Hide()
-- Double Bet
playerFrame.player1DoubleBetCoins = playerFrame:CreateTexture(nil, "OVERLAY")
playerFrame.player1DoubleBetCoins:SetSize(128, 128)
playerFrame.player1DoubleBetCoins:SetPoint("CENTER", playerFrame, 355, 70)
playerFrame.player1DoubleBetCoins:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CoinsWin.tga")
playerFrame.player1DoubleBetCoins:SetBlendMode("BLEND")
playerFrame.player1DoubleBetCoins:SetDrawLayer("OVERLAY")
playerFrame.player1DoubleBetCoins:Hide()
-- PP Bet
playerFrame.player1PPBetCoins = playerFrame:CreateTexture(nil, "OVERLAY")
playerFrame.player1PPBetCoins:SetSize(128, 128)
playerFrame.player1PPBetCoins:SetPoint("CENTER", playerFrame, 280, 40)
playerFrame.player1PPBetCoins:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CoinsHalfBet.tga")
playerFrame.player1PPBetCoins:SetBlendMode("BLEND")
playerFrame.player1PPBetCoins:SetDrawLayer("OVERLAY")
playerFrame.player1PPBetCoins:Hide()
-- 21+3 Bet
playerFrame.player1213BetCoins = playerFrame:CreateTexture(nil, "OVERLAY")
playerFrame.player1213BetCoins:SetSize(128, 128)
playerFrame.player1213BetCoins:SetPoint("CENTER", playerFrame, 350, 136)
playerFrame.player1213BetCoins:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CoinsHalfBet.tga")
playerFrame.player1213BetCoins:SetBlendMode("BLEND")
playerFrame.player1213BetCoins:SetDrawLayer("OVERLAY")
playerFrame.player1213BetCoins:Hide()
-- PP Win
playerFrame.player1PPWinCoins = playerFrame:CreateTexture(nil, "OVERLAY")
playerFrame.player1PPWinCoins:SetSize(128, 128)
playerFrame.player1PPWinCoins:SetPoint("CENTER", playerFrame, 292, 44)
playerFrame.player1PPWinCoins:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CoinsBet.tga")
playerFrame.player1PPWinCoins:SetBlendMode("BLEND")
playerFrame.player1PPWinCoins:SetDrawLayer("OVERLAY")
playerFrame.player1PPWinCoins:Hide()
-- 21+3 Win
playerFrame.player1213WinCoins = playerFrame:CreateTexture(nil, "OVERLAY")
playerFrame.player1213WinCoins:SetSize(128, 128)
playerFrame.player1213WinCoins:SetPoint("CENTER", playerFrame, 361, 141)
playerFrame.player1213WinCoins:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CoinsBet.tga")
playerFrame.player1213WinCoins:SetBlendMode("BLEND")
playerFrame.player1213WinCoins:SetDrawLayer("OVERLAY")
playerFrame.player1213WinCoins:Hide()

-- Insurance YES for Player 1
player1InsuranceYesIcon = playerFrame:CreateTexture(nil, "OVERLAY")
player1InsuranceYesIcon:SetSize(32, 32)
player1InsuranceYesIcon:SetPoint("CENTER", playerFrame, 539, -9)
player1InsuranceYesIcon:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\insuranceYes.tga")
player1InsuranceYesIcon:SetDrawLayer("ARTWORK")
player1InsuranceYesIcon:Hide()

-- Insurance NO for Player 1
player1InsuranceNoIcon = playerFrame:CreateTexture(nil, "OVERLAY")
player1InsuranceNoIcon:SetSize(32, 32)
player1InsuranceNoIcon:SetPoint("CENTER", playerFrame, 539, -9)
player1InsuranceNoIcon:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\insuranceNo.tga")
player1InsuranceNoIcon:SetDrawLayer("ARTWORK")
player1InsuranceNoIcon:Hide()

-- BJ Win Coins
local function player1PlaceCoinsBJWin(message)
    playerFrame.player1MainBetCoins:Hide()
    playerFrame.player1BJWinCoins:Show()
end

-- Regular Win Coins
local function player1PlaceCoinsRegularWin(message)
    playerFrame.player1MainBetCoins:Hide()
    playerFrame.player1DoubleBetCoins:Show()
end

-- Main Bet Coins
local function player1PlaceCoinsMainBet(message)
    playerFrame.player1MainBetCoins:Show()
end

-- Double Bet Coins
local function player1PlaceCoinsDoubleBet(message)
    playerFrame.player1MainBetCoins:Hide()
    playerFrame.player1DoubleBetCoins:Show()
end

-- Function to handle Player 1 Main Bet Text
local function player1PlaceTextMainBet(message)
    local player1HistoryMainBet = string.match(message, "(%d+)G")

        if player1HistoryMainBet then
            player1MainBetAmount:SetText(player1HistoryMainBet .. " G")
            player1MainBetAmount:Show()

            player1totalBetAmount = player1totalBetAmount + tonumber(player1HistoryMainBet)
            historyFrame.player1totalWageredAmount:SetText(player1totalBetAmount .. " G")
        else
    end
end

-- Player 1 Split Hand Bet Text
function player1SplitHand1BetText(Amount)
    player1MainBetAmount:Hide()
    player1MainBetAmount:SetText("")
    player1SplitH1BetAmount:SetText(Amount .. " G")
    player1SplitH1BetAmount:Show()
    player1SplitH2BetAmount:SetText(Amount .. " G")
    player1SplitH2BetAmount:Show()
end

-- Player 1 Split Bet Image
function player1PlaceSplitBet(message)
    playerFrame.player1MainBetCoins:Hide()
    playerFrame.player1SplitHand1Coins:Show()
    playerFrame.player1SplitHand2Coins:Show()
end

-- Player 1 Place Initial Card Images
function player1PlaceSplitCards(message)
    drawnCards[1]:Hide()
    drawnCards[3]:Hide()

    cardName1 = dealtCards[1]
    cardName2 = dealtCards[3]

    cardImageFile1 = nil
    cardImageFile2 = nil

    for filename, cardDescription in pairs(cardNames) do
        if cardDescription == cardName1 then
            cardImageFile1 = filename
            break
        end
    end

    for filename, cardDescription in pairs(cardNames) do
        if cardDescription == cardName2 then
            cardImageFile2 = filename
            break
        end
    end

    player1NewCardImage1 = CreateFrame("Frame", nil, playerFrame)
    player1NewCardImage1:SetSize(32, 64)
    player1NewCardImage1:SetPoint("BOTTOM", playerFrame, 302, 454)
    player1NewCardImage1.texture = player1NewCardImage1:CreateTexture()
    player1NewCardImage1.texture:SetAllPoints()
    player1NewCardImage1.texture:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. cardImageFile1)
    player1NewCardImage1:Show()

    player1NewCardImage2 = CreateFrame("Frame", nil, playerFrame)
    player1NewCardImage2:SetSize(32, 64)
    player1NewCardImage2:SetPoint("BOTTOM", playerFrame, 265, 435)
    player1NewCardImage2.texture = player1NewCardImage2:CreateTexture()
    player1NewCardImage2.texture:SetAllPoints()
    player1NewCardImage2.texture:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. cardImageFile2)
    player1NewCardImage2:Show()

    turn = 8 -- Player 1: 2nd Card (Split H1)

end

-- Player 1 Split Function
function player1HandleSplit(message)
    player1PlaceSplitBet()
    local player1MainBetAmountValue = tonumber(string.match(player1MainBetAmount:GetText(), "%d+"))
    if player1MainBetAmountValue then
        player1SplitHand1BetText(player1MainBetAmountValue)
    end 

    -- Players: 1
    if Player1Active and not Player2Active and not Player2Active and not Player2Active and not Player2Active then
        player1PlaceSplitCards()
    end

    -- A,A
    if playerFrame.player1CardTotalText:GetText() == "2 or 12" then
        playerFrame.player1SplitHand1CardTotalText:SetText("1 or 11")
        playerFrame.player1SplitHand1CardTotalText:Show()
        playerFrame.player1SplitHand2CardTotalText:SetText("1 or 11")
        playerFrame.player1SplitHand2CardTotalText:Show()
    -- 2,2
    elseif playerFrame.player1CardTotalText:GetText() == "4" then
        playerFrame.player1SplitHand1CardTotalText:SetText("2")
        playerFrame.player1SplitHand1CardTotalText:Show()
        playerFrame.player1SplitHand2CardTotalText:SetText("2")
        playerFrame.player1SplitHand2CardTotalText:Show()
    -- 3,3
    elseif playerFrame.player1CardTotalText:GetText() == "6" then
        playerFrame.player1SplitHand1CardTotalText:SetText("3")
        playerFrame.player1SplitHand1CardTotalText:Show()
        playerFrame.player1SplitHand2CardTotalText:SetText("3")
        playerFrame.player1SplitHand2CardTotalText:Show()
    -- 4,4
    elseif playerFrame.player1CardTotalText:GetText() == "8" then
        playerFrame.player1SplitHand1CardTotalText:SetText("4")
        playerFrame.player1SplitHand1CardTotalText:Show()
        playerFrame.player1SplitHand2CardTotalText:SetText("4")
        playerFrame.player1SplitHand2CardTotalText:Show()
    -- 5,5
    elseif playerFrame.player1CardTotalText:GetText() == "10" then
        playerFrame.player1SplitHand1CardTotalText:SetText("5")
        playerFrame.player1SplitHand1CardTotalText:Show()
        playerFrame.player1SplitHand2CardTotalText:SetText("5")
        playerFrame.player1SplitHand2CardTotalText:Show()
    -- 6,6
    elseif playerFrame.player1CardTotalText:GetText() == "12" then
        playerFrame.player1SplitHand1CardTotalText:SetText("6")
        playerFrame.player1SplitHand1CardTotalText:Show()
        playerFrame.player1SplitHand2CardTotalText:SetText("6")
        playerFrame.player1SplitHand2CardTotalText:Show()
    -- 7,7
    elseif playerFrame.player1CardTotalText:GetText() == "14" then
        playerFrame.player1SplitHand1CardTotalText:SetText("7")
        playerFrame.player1SplitHand1CardTotalText:Show()
        playerFrame.player1SplitHand2CardTotalText:SetText("7")
        playerFrame.player1SplitHand2CardTotalText:Show()
    -- 8,8
    elseif playerFrame.player1CardTotalText:GetText() == "16" then
        playerFrame.player1SplitHand1CardTotalText:SetText("8")
        playerFrame.player1SplitHand1CardTotalText:Show()
        playerFrame.player1SplitHand2CardTotalText:SetText("8")
        playerFrame.player1SplitHand2CardTotalText:Show()
    -- 9,9
    elseif playerFrame.player1CardTotalText:GetText() == "18" then
        playerFrame.player1SplitHand1CardTotalText:SetText("9")
        playerFrame.player1SplitHand1CardTotalText:Show()
        playerFrame.player1SplitHand2CardTotalText:SetText("9")
        playerFrame.player1SplitHand2CardTotalText:Show()
    -- 10,10
    elseif playerFrame.player1CardTotalText:GetText() == "20" then
        playerFrame.player1SplitHand1CardTotalText:SetText("10")
        playerFrame.player1SplitHand1CardTotalText:Show()
        playerFrame.player1SplitHand2CardTotalText:SetText("10")
        playerFrame.player1SplitHand2CardTotalText:Show()
    end

    playerFrame.player1CardTotalText:SetText("")
    playerFrame.player1CardTotalText:Hide()

    player1totalBetAmount = player1totalBetAmount + tonumber(player1MainBetAmountValue)
    historyFrame.player1totalWageredAmount:SetText(player1totalBetAmount .. " G")

    player1TotalBankrollAmount = player1TotalBankrollAmount - tonumber(player1MainBetAmountValue)
    bankrollFrame.player1TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
    cashDeskFrame.player1TotalBankroll:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
     
    player1SplitToggle = true

    if dealtCardsFramePlayer:IsShown() then
        dealtCardsFramePlayer:Hide()
        dealtCardsFramePlayer.playerCardsButton:Hide()
        dealtCardsFramePlayer.dealerCardsButton:Hide()
        dealtCardsFramePlayer1H1:Show()
        dealtCardsFramePlayer1H1.playerH1CardsButton:Show()
        dealtCardsFramePlayer1H1.playerH2CardsButton:Show()
        dealtCardsFramePlayer1H1.dealerCardsButton:Show()
    elseif dealtCardsFrameDealer:IsShown() then
        dealtCardsFrameDealer:Hide()
        dealtCardsFrameDealer.playerCardsButton:Hide()
        dealtCardsFrameDealer.dealerCardsButton:Hide()
        dealtCardsFramePlayer:Hide()
        dealtCardsFramePlayer.playerCardsButton:Hide()
        dealtCardsFramePlayer.dealerCardsButton:Hide()
        dealtCardsFramePlayer1H1:Show()
        dealtCardsFramePlayer1H1.playerH1CardsButton:Show()
        dealtCardsFramePlayer1H1.playerH2CardsButton:Show()
        dealtCardsFramePlayer1H1.dealerCardsButton:Show()
    end

end

-- Function to handle Player 1 PP Bet Image
local function player1PlaceCoinsPPBet(message)
    playerFrame.player1PPBetCoins:Show()
end

-- Function to handle Player 1 PP Bet Text
local function player1PlaceTextPPBet(message)
    local player1HistoryPPBet = string.match(message, "(%d+)G")

        if player1HistoryPPBet then
            player1PPBetAmount:SetText(player1HistoryPPBet .. " G")
            player1PPBetAmount:Show()

            player1totalBetAmount = player1totalBetAmount + tonumber(player1HistoryPPBet)
            historyFrame.player1totalWageredAmount:SetText(player1totalBetAmount .. " G")
        else
    end
end

-- Function to handle Player 1 21+3 Bet Image
local function player1PlaceCoins213Bet(message)
    playerFrame.player1213BetCoins:Show()
end

-- Function to handle Player 1 21+3 Bet Text
local function player1PlaceText213Bet(message)
    local player1History213Bet = string.match(message, "(%d+)G")

        if player1History213Bet then
            player1213BetAmount:SetText(player1History213Bet .. " G")
            player1213BetAmount:Show()

            player1totalBetAmount = player1totalBetAmount + tonumber(player1History213Bet)
            historyFrame.player1totalWageredAmount:SetText(player1totalBetAmount .. " G")
        else
    end
end

local function player1PreloadBet()
    PlaySoundFile(soundFilePaths[43])
    player1MainBet = tonumber(player1PreloadEditBoxMainBet:GetText())
    player1PPBet = tonumber(player1PreloadEditBoxPPBet:GetText())
    player1213Bet = tonumber(player1PreloadEditBox213Bet:GetText())

    if player1MainBet and not player1PPBet and not player1213Bet then
        player1TotalRebetAmount = player1MainBet
    elseif player1MainBet and player1PPBet and not player1213Bet then
        player1TotalRebetAmount = player1MainBet + player1PPBet
    elseif player1MainBet and player1PPBet and player1213Bet then
        player1TotalRebetAmount = player1MainBet + player1PPBet + player1213Bet
    end

    player1currentBankroll = tonumber(string.match(bankrollFrame.player1TotalBankrollTableDisplay:GetText(), "%d+"))

    if player1currentBankroll - player1TotalRebetAmount < 0 then
        print("You do not have enough gold in your bankroll to place that bet. Please visit the Cash Desk.")
    else
        if player1MainBet and player1MainBet >= minBetMain and player1MainBet <= maxBetMain then
            -- Valid bet amount, send the message with the bet
            SendChatMessage("[P1] Placing a " ..player1MainBet.. "G main bet.", "RAID")
            -- Disable the edit box and button
            player1PreloadEditBoxMainBet:SetFocus(false)
            player1PreloadEditBoxMainBet:ClearFocus()
            player1MainBetEditBox:SetText("")
            player1MainBetEditBox:SetText(player1MainBet)
            player1MainBetEditBox:SetFocus(false)
            player1MainBetEditBox:ClearFocus()
            player1MainBetEditBox:Disable()
            player1ConfirmMainBetButton:Disable()
        end
        
        if player1PPBet and player1PPBet >= minBetPP and player1PPBet <= maxBetPP then
            -- Valid bet amount, send the message with the bet
            SendChatMessage("[P1] Placing a " ..player1PPBet.. "G side bet on Perfect Pairs.", "RAID")
            -- Disable the edit box and button
            player1PreloadEditBoxPPBet:SetFocus(false)
            player1PreloadEditBoxPPBet:ClearFocus()
            player1PPBetEditBox:SetText("")
            player1PPBetEditBox:SetText(player1PPBet)
            player1PPBetEditBox:SetFocus(false)
            player1PPBetEditBox:ClearFocus()
            player1PPBetEditBox:Disable()
            player1ConfirmPPBetButton:Disable()
        end
        
        if player1213Bet and player1213Bet >= minBet213 and player1213Bet <= maxBet213 then
            -- Valid bet amount, send the message with the bet
            SendChatMessage("[P1] Placing a " ..player1213Bet.. "G side bet on 21+3.", "RAID")
            -- Disable the edit box and button
            player1PreloadEditBox213Bet:SetFocus(false)
            player1PreloadEditBox213Bet:ClearFocus()
            player1213BetEditBox:SetText("")
            player1213BetEditBox:SetText(player1213Bet)
            player1213BetEditBox:SetFocus(false)
            player1213BetEditBox:ClearFocus()
            player1213BetEditBox:Disable()
            player1Confirm213BetButton:Disable()
        end
    
        player1PreloadBetButton:Disable()

        player1TotalBankrollAmount = player1TotalBankrollAmount - tonumber(player1TotalRebetAmount)
        bankrollFrame.player1TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
        cashDeskFrame.player1TotalBankroll:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")

    end

end

-- Function to handle the Player 1 Main "Bet" button click
local function player1ConfirmMainBetClick()
    player1MainBet = tonumber(player1MainBetEditBox:GetText())
    player1currentBankroll = tonumber(string.match(bankrollFrame.player1TotalBankrollTableDisplay:GetText(), "%d+"))

    if player1MainBet and player1MainBet >= minBetMain and player1MainBet <= maxBetMain then
        if player1currentBankroll - player1MainBet < 0 then
            print("You do not have enough gold in your bankroll to place that bet. Please visit the Cash Desk.")
        else
            -- Valid bet amount, send the message with the bet
            SendChatMessage("[P1] Placing a " ..player1MainBet.. "G main bet.", "RAID")
            -- Disable the edit box and button
            player1MainBetEditBox:SetFocus(false)
            player1MainBetEditBox:ClearFocus()
            player1MainBetEditBox:Disable()
            player1ConfirmMainBetButton:Disable()

            player1PreloadBetButton:Disable()

            PlaySoundFile(soundFilePaths[43]) 

            player1TotalBankrollAmount = player1TotalBankrollAmount - tonumber(player1MainBet)
            bankrollFrame.player1TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
            cashDeskFrame.player1TotalBankroll:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")

        end
    else
        print("Invalid bet amount. Please enter a value between " .. minBetMain .. "G and " .. maxBetMain .. "G.")
    end

end

-- Function to handle the Player 1 PP "Bet" button click
local function player1ConfirmPPBetClick()
    player1PPBet = tonumber(player1PPBetEditBox:GetText()) -- Get the entered bet amount
    player1currentBankroll = tonumber(string.match(bankrollFrame.player1TotalBankrollTableDisplay:GetText(), "%d+"))

    if player1PPBet and player1PPBet >= minBetPP and player1PPBet <= maxBetPP then
        if player1currentBankroll - player1PPBet < 0 then
            print("You do not have enough gold in your bankroll to place that bet. Please visit the Cash Desk.")
        else
            if player1MainBetEditBox:GetText() == "" then
                print("You must place a minimum 'Main Bet' of 50G before placing this side bet")
            else
                -- Valid bet amount, send the message with the bet
                SendChatMessage("[P1] Placing a " ..player1PPBet.. "G side bet on Perfect Pairs.", "RAID")
                -- Disable the edit box and button
                player1PPBetEditBox:SetFocus(false)
                player1PPBetEditBox:ClearFocus()
                player1PPBetEditBox:Disable()
                player1ConfirmPPBetButton:Disable()

                player1PreloadBetButton:Disable()

                PlaySoundFile(soundFilePaths[43])

                player1TotalBankrollAmount = player1TotalBankrollAmount - tonumber(player1PPBet)
                bankrollFrame.player1TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
                cashDeskFrame.player1TotalBankroll:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")

            end
        end
    else
        print("Invalid bet amount. Please enter a value between " .. minBetPP .. "G and " .. maxBetPP .. "G.")
    end

end

-- Function to handle the Player 1 21+3 "Bet" button click
local function player1Confirm213BetClick()
    player1213Bet = tonumber(player1213BetEditBox:GetText()) -- Get the entered bet amount
    player1currentBankroll = tonumber(string.match(bankrollFrame.player1TotalBankrollTableDisplay:GetText(), "%d+"))

    if player1213Bet and player1213Bet >= minBet213 and player1213Bet <= maxBet213 then
        if player1currentBankroll - player1213Bet < 0 then
            print("You do not have enough gold in your bankroll to place that bet. Please visit the Cash Desk.")
        else
            if player1MainBetEditBox:GetText() == "" then
                print("You must place a minimum 'Main Bet' of 50G before placing this side bet")
            else
                -- Valid bet amount, send the message with the bet
                SendChatMessage("[P1] Placing a " ..player1213Bet.. "G side bet on 21+3.", "RAID")
                -- Disable the edit box and button
                player1213BetEditBox:SetFocus(false)
                player1213BetEditBox:ClearFocus()
                player1213BetEditBox:Disable()
                player1Confirm213BetButton:Disable()

                player1PreloadBetButton:Disable()

                PlaySoundFile(soundFilePaths[43])

                player1TotalBankrollAmount = player1TotalBankrollAmount - tonumber(player1213Bet)
                bankrollFrame.player1TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
                cashDeskFrame.player1TotalBankroll:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")

            end
        end
    else
        print("Invalid bet amount. Please enter a value between " .. minBet213 .. "G and " .. maxBet213 .. "G.")
    end
 
end

-- Player 1 Main "Bet" button
player1ConfirmMainBetButton:SetScript("OnClick", player1ConfirmMainBetClick)

-- Player 1 PP "Bet" button
player1ConfirmPPBetButton:SetScript("OnClick", player1ConfirmPPBetClick)

-- Player 1 21+3 "Bet" button
player1Confirm213BetButton:SetScript("OnClick", player1Confirm213BetClick)

-- Player 1 "Bet All" Preload button
player1PreloadBetButton:SetScript("OnClick", player1PreloadBet)

local function player1SessionWinAnnouncement()
    if player1SessionWin >= 1000 then
        local chatFrame = SELECTED_DOCK_FRAME
            ChatFrame_OpenChat("/me", chatFrame)
            local editBox = _G[chatFrame:GetName().."EditBox"]
            editBox:SetText("")
            editBox:Insert("/me has won " .. player1SessionWin .. "g from a hand of Blackjack.")
            ChatEdit_SendText(editBox)
            ChatEdit_DeactivateChat(editBox)
    else
        print("")
    end
end

player1HotstreakImage1 = playerFrame:CreateTexture(nil, "OVERLAY")
player1HotstreakImage1:SetSize(36, 36)
player1HotstreakImage1:SetPoint("CENTER", playerFrame, 483, 25)
player1HotstreakImage1:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\Hotstreak1.tga")
player1HotstreakImage1:SetDrawLayer("OVERLAY")
player1HotstreakImage1:Hide()

player1HotstreakImage2 = playerFrame:CreateTexture(nil, "OVERLAY")
player1HotstreakImage2:SetSize(36, 36)
player1HotstreakImage2:SetPoint("CENTER", playerFrame, 483, 25)
player1HotstreakImage2:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\Hotstreak2.tga")
player1HotstreakImage2:SetDrawLayer("OVERLAY")
player1HotstreakImage2:Hide()

player1HotstreakImage3 = playerFrame:CreateTexture(nil, "OVERLAY")
player1HotstreakImage3:SetSize(36, 36)
player1HotstreakImage3:SetPoint("CENTER", playerFrame, 483, 25)
player1HotstreakImage3:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\Hotstreak3.tga")
player1HotstreakImage3:SetDrawLayer("OVERLAY")
player1HotstreakImage3:Hide()

player1HotstreakImage4 = playerFrame:CreateTexture(nil, "OVERLAY")
player1HotstreakImage4:SetSize(36, 36)
player1HotstreakImage4:SetPoint("CENTER", playerFrame, 483, 25)
player1HotstreakImage4:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\Hotstreak4.tga")
player1HotstreakImage4:SetDrawLayer("OVERLAY")
player1HotstreakImage4:Hide()

player1HotstreakImage5 = playerFrame:CreateTexture(nil, "OVERLAY")
player1HotstreakImage5:SetSize(36, 36)
player1HotstreakImage5:SetPoint("CENTER", playerFrame, 483, 25)
player1HotstreakImage5:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\Hotstreak5.tga")
player1HotstreakImage5:SetDrawLayer("OVERLAY")
player1HotstreakImage5:Hide()

player1HotstreakImage6 = playerFrame:CreateTexture(nil, "OVERLAY")
player1HotstreakImage6:SetSize(36, 36)
player1HotstreakImage6:SetPoint("CENTER", playerFrame, 483, 25)
player1HotstreakImage6:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\Hotstreak6.tga")
player1HotstreakImage6:SetDrawLayer("OVERLAY")
player1HotstreakImage6:Hide()

player1HotstreakImage7 = playerFrame:CreateTexture(nil, "OVERLAY")
player1HotstreakImage7:SetSize(36, 36)
player1HotstreakImage7:SetPoint("CENTER", playerFrame, 483, 25)
player1HotstreakImage7:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\Hotstreak7.tga")
player1HotstreakImage7:SetDrawLayer("OVERLAY")
player1HotstreakImage7:Hide()

player1HotstreakImage8 = playerFrame:CreateTexture(nil, "OVERLAY")
player1HotstreakImage8:SetSize(36, 36)
player1HotstreakImage8:SetPoint("CENTER", playerFrame, 483, 25)
player1HotstreakImage8:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\Hotstreak8.tga")
player1HotstreakImage8:SetDrawLayer("OVERLAY")
player1HotstreakImage8:Hide()

player1HotstreakImage9 = playerFrame:CreateTexture(nil, "OVERLAY")
player1HotstreakImage9:SetSize(36, 36)
player1HotstreakImage9:SetPoint("CENTER", playerFrame, 483, 25)
player1HotstreakImage9:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\Hotstreak9.tga")
player1HotstreakImage9:SetDrawLayer("OVERLAY")
player1HotstreakImage9:Hide()

player1HotstreakImage10 = playerFrame:CreateTexture(nil, "OVERLAY")
player1HotstreakImage10:SetSize(36, 36)
player1HotstreakImage10:SetPoint("CENTER", playerFrame, 483, 25)
player1HotstreakImage10:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\Hotstreak10.tga")
player1HotstreakImage10:SetDrawLayer("OVERLAY")
player1HotstreakImage10:Hide()

player1HotstreakImage11 = playerFrame:CreateTexture(nil, "OVERLAY")
player1HotstreakImage11:SetSize(36, 36)
player1HotstreakImage11:SetPoint("CENTER", playerFrame, 483, 25)
player1HotstreakImage11:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\Hotstreak11.tga")
player1HotstreakImage11:SetDrawLayer("OVERLAY")
player1HotstreakImage11:Hide()

player1HotstreakImage12 = playerFrame:CreateTexture(nil, "OVERLAY")
player1HotstreakImage12:SetSize(36, 36)
player1HotstreakImage12:SetPoint("CENTER", playerFrame, 483, 25)
player1HotstreakImage12:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\Hotstreak12.tga")
player1HotstreakImage12:SetDrawLayer("OVERLAY")
player1HotstreakImage12:Hide()

player1HotstreakImage13 = playerFrame:CreateTexture(nil, "OVERLAY")
player1HotstreakImage13:SetSize(36, 36)
player1HotstreakImage13:SetPoint("CENTER", playerFrame, 483, 25)
player1HotstreakImage13:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\Hotstreak13.tga")
player1HotstreakImage13:SetDrawLayer("OVERLAY")
player1HotstreakImage13:Hide()

player1HotstreakImage14 = playerFrame:CreateTexture(nil, "OVERLAY")
player1HotstreakImage14:SetSize(36, 36)
player1HotstreakImage14:SetPoint("CENTER", playerFrame, 483, 25)
player1HotstreakImage14:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\Hotstreak14.tga")
player1HotstreakImage14:SetDrawLayer("OVERLAY")
player1HotstreakImage14:Hide()

player1HotstreakImage15 = playerFrame:CreateTexture(nil, "OVERLAY")
player1HotstreakImage15:SetSize(36, 36)
player1HotstreakImage15:SetPoint("CENTER", playerFrame, 483, 25)
player1HotstreakImage15:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\Hotstreak15.tga")
player1HotstreakImage15:SetDrawLayer("OVERLAY")
player1HotstreakImage15:Hide()




local function player1HotStreakCheck()
    if player1Hotstreak == 0 then
        player1HotstreakImage1:Hide()
        player1HotstreakImage2:Hide()
        player1HotstreakImage3:Hide()
        player1HotstreakImage4:Hide()
        player1HotstreakImage5:Hide()
        player1HotstreakImage6:Hide()
        player1HotstreakImage7:Hide()
        player1HotstreakImage8:Hide()
        player1HotstreakImage9:Hide()
        player1HotstreakImage10:Hide()
        player1HotstreakImage11:Hide()
        player1HotstreakImage12:Hide()
        player1HotstreakImage13:Hide()
        player1HotstreakImage14:Hide()
        player1HotstreakImage15:Hide()
    elseif player1Hotstreak == 1 then
        player1HotstreakImage1:Show()
    elseif player1Hotstreak == 2 then
        player1HotstreakImage1:Hide()
        player1HotstreakImage2:Show()
    elseif player1Hotstreak == 3 then
        player1HotstreakImage1:Hide()
        player1HotstreakImage2:Hide()
        player1HotstreakImage3:Show()
    elseif player1Hotstreak == 4 then
        player1HotstreakImage2:Hide()
        player1HotstreakImage3:Hide()
        player1HotstreakImage4:Show()
    elseif player1Hotstreak == 5 then
        player1HotstreakImage3:Hide()
        player1HotstreakImage4:Hide()
        player1HotstreakImage5:Show()
    elseif player1Hotstreak == 6 then
        player1HotstreakImage4:Hide()
        player1HotstreakImage5:Hide()
        player1HotstreakImage6:Show()
    elseif player1Hotstreak == 7 then
        player1HotstreakImage5:Hide()
        player1HotstreakImage6:Hide()
        player1HotstreakImage7:Show()
    elseif player1Hotstreak == 8 then
        player1HotstreakImage6:Hide()
        player1HotstreakImage7:Hide()
        player1HotstreakImage8:Show()
    elseif player1Hotstreak == 9 then
        player1HotstreakImage7:Hide()
        player1HotstreakImage8:Hide()
        player1HotstreakImage9:Show()
    elseif player1Hotstreak == 10 then
        player1HotstreakImage8:Hide()
        player1HotstreakImage9:Hide()
        player1HotstreakImage10:Show()
    elseif player1Hotstreak == 11 then
        player1HotstreakImage9:Hide()
        player1HotstreakImage10:Hide()
        player1HotstreakImage11:Show()
    elseif player1Hotstreak == 12 then
        player1HotstreakImage10:Hide()
        player1HotstreakImage11:Hide()
        player1HotstreakImage12:Show()
    elseif player1Hotstreak == 13 then
        player1HotstreakImage11:Hide()
        player1HotstreakImage12:Hide()
        player1HotstreakImage13:Show()
    elseif player1Hotstreak == 14 then
        player1HotstreakImage12:Hide()
        player1HotstreakImage13:Hide()
        player1HotstreakImage14:Show()
    elseif player1Hotstreak == 15 then
        player1HotstreakImage13:Hide()
        player1HotstreakImage14:Hide()
        player1HotstreakImage15:Show()
    end
end
























-- >>> PLAYER 2 <<<
-- >>> PLAYER 2 <<<
-- >>> PLAYER 2 <<<

-- Insurance YES for Player 2
insuranceYesIcon2 = playerFrame:CreateTexture(nil, "OVERLAY")
insuranceYesIcon2:SetSize(32, 32)
insuranceYesIcon2:SetPoint("CENTER", playerFrame, 342, -158)
insuranceYesIcon2:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\insuranceYes.tga")
insuranceYesIcon2:SetDrawLayer("ARTWORK")
insuranceYesIcon2:Hide()


-- Insurance NO for Player 2
insuranceNoIcon2 = playerFrame:CreateTexture(nil, "OVERLAY")
insuranceNoIcon2:SetSize(32, 32)
insuranceNoIcon2:SetPoint("CENTER", playerFrame, 342, -158)
insuranceNoIcon2:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\insuranceNo.tga")
insuranceNoIcon2:SetDrawLayer("ARTWORK")
insuranceNoIcon2:Hide()




-- Buttons for Player 2
-- Hit
playerFrame.player2HitButton = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.player2HitButton:SetPoint("BOTTOM", playerFrame, 222, 127)
playerFrame.player2HitButton:SetSize(65, 30)
playerFrame.player2HitButton:SetText("Hit")
playerFrame.player2HitButton:Disable()
-- Stand
playerFrame.player2StandButton = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.player2StandButton:SetPoint("BOTTOM", playerFrame, 288, 127)
playerFrame.player2StandButton:SetSize(65, 30)
playerFrame.player2StandButton:SetText("Stand")
playerFrame.player2StandButton:Disable()
-- Double
playerFrame.player2DoubleButton = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.player2DoubleButton:SetPoint("BOTTOM", playerFrame, 222, 97)
playerFrame.player2DoubleButton:SetSize(65, 30)
playerFrame.player2DoubleButton:SetText("Double")
playerFrame.player2DoubleButton:Disable()
-- Split
playerFrame.player2SplitButton = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.player2SplitButton:SetPoint("BOTTOM", playerFrame, 288, 97)
playerFrame.player2SplitButton:SetSize(65, 30)
playerFrame.player2SplitButton:SetText("Split")
playerFrame.player2SplitButton:Disable()
-- Insurance Yes
playerFrame.player2InsuranceYesButton = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.player2InsuranceYesButton:SetPoint("BOTTOM", playerFrame, 190, 67)
playerFrame.player2InsuranceYesButton:SetSize(55, 30)
playerFrame.player2InsuranceYesButton:SetText("Yes")
playerFrame.player2InsuranceYesButton:Disable()
-- Insurance No
playerFrame.player2InsuranceNoButton = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.player2InsuranceNoButton:SetPoint("BOTTOM", playerFrame, 318, 67)
playerFrame.player2InsuranceNoButton:SetSize(55, 30)
playerFrame.player2InsuranceNoButton:SetText("No")
playerFrame.player2InsuranceNoButton:Disable()
-- Main Bet Confirm
player2ConfirmMainBetButton = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
player2ConfirmMainBetButton:SetPoint("BOTTOM", playerFrame, 288, 187)
player2ConfirmMainBetButton:SetSize(65, 30)
player2ConfirmMainBetButton:SetText("Bet")
-- Perfect Pairs Confirm
player2ConfirmPPBetButton = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
player2ConfirmPPBetButton:SetPoint("BOTTOM", playerFrame, 129, 244)
player2ConfirmPPBetButton:SetSize(43, 25)
player2ConfirmPPBetButton:SetText("Bet")
-- 21+3 Confirm
player2Confirm213BetButton = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
player2Confirm213BetButton:SetPoint("BOTTOM", playerFrame, 245, 295)
player2Confirm213BetButton:SetSize(43, 25)
player2Confirm213BetButton:SetText("Bet")

-- Wagers for Player 2
-- Main Bet
player2MainBetEditBox = CreateFrame("EditBox", nil, playerFrame, "InputBoxTemplate")
player2MainBetEditBox:SetSize(55, 30)
player2MainBetEditBox:SetPoint("BOTTOM", playerFrame, 225, 187)
player2MainBetEditBox:SetAutoFocus(false)
player2MainBetEditBox:SetNumeric(true)
-- Perfect Pairs
local player2PPBetEditBox = CreateFrame("EditBox", nil, playerFrame, "InputBoxTemplate")
player2PPBetEditBox:SetSize(35, 30)
player2PPBetEditBox:SetPoint("BOTTOM", playerFrame, 132, 264)
player2PPBetEditBox:SetAutoFocus(false)
player2PPBetEditBox:SetNumeric(true)
-- 21+3
local player2213BetEditBox = CreateFrame("EditBox", nil, playerFrame, "InputBoxTemplate")
player2213BetEditBox:SetSize(35, 30)
player2213BetEditBox:SetPoint("BOTTOM", playerFrame, 247, 315)
player2213BetEditBox:SetAutoFocus(false)
player2213BetEditBox:SetNumeric(true)

-- Labels for Player 2
-- Main Bet
playerFrame.mainBet2 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.mainBet2:SetPoint("BOTTOM", playerFrame, 224, 214)
playerFrame.mainBet2:SetJustifyH("CENTER")
playerFrame.mainBet2:SetText("Main Bet")
playerFrame.mainBet2:SetFont("Fonts\\FRIZQT__.TTF", 8, "OUTLINE")
-- Main Bet Amount
player2MainBetAmount = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
player2MainBetAmount:SetPoint("CENTER", playerFrame, 189, -16)
player2MainBetAmount:SetJustifyH("CENTER")
player2MainBetAmount:SetFont("Fonts\\FRIZQT__.TTF", 8, "OUTLINE")
-- Perfect Pairs
playerFrame.ppBet2 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.ppBet2:SetPoint("BOTTOM", playerFrame, 96, 262)
playerFrame.ppBet2:SetJustifyH("CENTER")
playerFrame.ppBet2:SetText("PP")
playerFrame.ppBet2:SetFont("Fonts\\FRIZQT__.TTF", 15, "OUTLINE")
-- Perfect Pairs Amount
player2PPBetAmount = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
player2PPBetAmount:SetPoint("CENTER", playerFrame, 123, -23)
player2PPBetAmount:SetJustifyH("CENTER")
player2PPBetAmount:SetFont("Fonts\\FRIZQT__.TTF", 8, "OUTLINE")
-- 21+3
playerFrame.t213Bet2 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.t213Bet2:SetPoint("BOTTOM", playerFrame, 290, 312)
playerFrame.t213Bet2:SetJustifyH("CENTER")
playerFrame.t213Bet2:SetText("21+3")
playerFrame.t213Bet2:SetFont("Fonts\\FRIZQT__.TTF", 15, "OUTLINE")
-- 21+3 Amount
player2213BetAmount = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
player2213BetAmount:SetPoint("CENTER", playerFrame, 231, 29)
player2213BetAmount:SetJustifyH("CENTER")
player2213BetAmount:SetFont("Fonts\\FRIZQT__.TTF", 8, "OUTLINE")
-- Insurance Amount
playerFrame.player2InsuranceBetAmount = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.player2InsuranceBetAmount:SetPoint("CENTER", playerFrame, 346, -131)
playerFrame.player2InsuranceBetAmount:SetJustifyH("CENTER")
playerFrame.player2InsuranceBetAmount:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
-- Player Name
playerFrame.player2Name = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.player2Name:SetPoint("BOTTOM", playerFrame, 255, 163)
playerFrame.player2Name:SetText(UnitName("player"))
playerFrame.player2Name:SetFont("Fonts\\FRIZQT__.TTF", 22, "OUTLINE")
-- Insurance Bet
playerFrame.insuranceBet2 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.insuranceBet2:SetPoint("BOTTOM", playerFrame, 255, 81)
playerFrame.insuranceBet2:SetText("Insurance")
playerFrame.insuranceBet2:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
-- Insurance (if available)
playerFrame.insuranceIfAvailable2 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.insuranceIfAvailable2:SetPoint("BOTTOM", playerFrame, 255, 71)
playerFrame.insuranceIfAvailable2:SetText("(if available)")
playerFrame.insuranceIfAvailable2:SetFont("Fonts\\FRIZQT__.TTF", 8, "OUTLINE")

-- Images for Player 2
-- Main Bet
playerFrame.coinsMainBet2 = playerFrame:CreateTexture(nil, "OVERLAY")
playerFrame.coinsMainBet2:SetSize(128, 128)
playerFrame.coinsMainBet2:SetPoint("CENTER", playerFrame, 206, -47)
playerFrame.coinsMainBet2:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CoinsBet.tga")
playerFrame.coinsMainBet2:SetBlendMode("BLEND")
playerFrame.coinsMainBet2:SetDrawLayer("OVERLAY")
playerFrame.coinsMainBet2:Hide()
-- Blackjack Win
playerFrame.coinsBJWin2 = playerFrame:CreateTexture(nil, "OVERLAY")
playerFrame.coinsBJWin2:SetSize(128, 128)
playerFrame.coinsBJWin2:SetPoint("CENTER", playerFrame, 206, -47)
playerFrame.coinsBJWin2:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CoinsBJWin.tga")
playerFrame.coinsBJWin2:SetBlendMode("BLEND")
playerFrame.coinsBJWin2:SetDrawLayer("OVERLAY")
playerFrame.coinsBJWin2:Hide()
-- Double Bet
playerFrame.coinsDoubleBet2 = playerFrame:CreateTexture(nil, "OVERLAY")
playerFrame.coinsDoubleBet2:SetSize(128, 128)
playerFrame.coinsDoubleBet2:SetPoint("CENTER", playerFrame, 206, -47)
playerFrame.coinsDoubleBet2:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CoinsWin.tga")
playerFrame.coinsDoubleBet2:SetBlendMode("BLEND")
playerFrame.coinsDoubleBet2:SetDrawLayer("OVERLAY")
playerFrame.coinsDoubleBet2:Hide()
-- PP Bet
playerFrame.player2CoinsPPBet = playerFrame:CreateTexture(nil, "OVERLAY")
playerFrame.player2CoinsPPBet:SetSize(128, 128)
playerFrame.player2CoinsPPBet:SetPoint("CENTER", playerFrame, 127, -42)
playerFrame.player2CoinsPPBet:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CoinsHalfBet.tga")
playerFrame.player2CoinsPPBet:SetBlendMode("BLEND")
playerFrame.player2CoinsPPBet:SetDrawLayer("OVERLAY")
playerFrame.player2CoinsPPBet:Hide()
-- 21+3 Bet
playerFrame.player2Coins213Bet = playerFrame:CreateTexture(nil, "OVERLAY")
playerFrame.player2Coins213Bet:SetSize(128, 128)
playerFrame.player2Coins213Bet:SetPoint("CENTER", playerFrame, 235, 8)
playerFrame.player2Coins213Bet:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CoinsHalfBet.tga")
playerFrame.player2Coins213Bet:SetBlendMode("BLEND")
playerFrame.player2Coins213Bet:SetDrawLayer("OVERLAY")
playerFrame.player2Coins213Bet:Hide()
-- PP Win
playerFrame.player2CoinsPPWin = playerFrame:CreateTexture(nil, "OVERLAY")
playerFrame.player2CoinsPPWin:SetSize(128, 128)
playerFrame.player2CoinsPPWin:SetPoint("CENTER", playerFrame, 138, -36)
playerFrame.player2CoinsPPWin:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CoinsBet.tga")
playerFrame.player2CoinsPPWin:SetBlendMode("BLEND")
playerFrame.player2CoinsPPWin:SetDrawLayer("OVERLAY")
playerFrame.player2CoinsPPWin:Hide()
-- 21+3 Win
playerFrame.player2Coins213Win = playerFrame:CreateTexture(nil, "OVERLAY")
playerFrame.player2Coins213Win:SetSize(128, 128)
playerFrame.player2Coins213Win:SetPoint("CENTER", playerFrame, 246, 16)
playerFrame.player2Coins213Win:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CoinsBet.tga")
playerFrame.player2Coins213Win:SetBlendMode("BLEND")
playerFrame.player2Coins213Win:SetDrawLayer("OVERLAY")
playerFrame.player2Coins213Win:Hide()

-- Function to handle Player 2 Double Bet Image
local function player2PlaceBetsBJWin(message)
    playerFrame.coinsMainBet2:Hide()
    playerFrame.coinsBJWin2:Show()
end

-- Function to handle Player 2 Double Bet Image
local function player2PlaceBetsRegularWin(message)
    playerFrame.coinsMainBet2:Hide()
    playerFrame.coinsDoubleBet2:Show()
end

-- Function to handle Player 2 Double Bet Image
local function PlaceBetsMain2Double(message)
    playerFrame.coinsMainBet2:Hide()
    playerFrame.coinsDoubleBet2:Show()
end

-- Function to handle Player 2 Main Bet Image
local function PlaceBetsMain2(message)
    playerFrame.coinsMainBet2:Show()
end

-- Function to handle Player 2 Main Bet Text
local function player2PlaceMainBetText(message)
    local player2HistoryMainBet = string.match(message, "(%d+)G")

        if player2HistoryMainBet then
            player2MainBetAmount:SetText(player2HistoryMainBet .. " G")
            player2MainBetAmount:Show()

            player2totalBetAmount = player2totalBetAmount + tonumber(player2HistoryMainBet)
            historyFrame.player2totalWageredAmount:SetText(player2totalBetAmount .. " G")
        else
    end
end

-- Function to handle Player 2 PP Bet Image
local function PlaceBetsPP2(message)
    playerFrame.player2CoinsPPBet:Show()
end

-- Function to handle Player 2 PP Bet Text
local function player2PlacePPBetText(message)
    local player2HistoryPPBet = string.match(message, "(%d+)G")

        if player2HistoryPPBet then
            player2PPBetAmount:SetText(player2HistoryPPBet .. " G")
            player2PPBetAmount:Show()

            player2totalBetAmount = player2totalBetAmount + tonumber(player2HistoryPPBet)
            historyFrame.player2totalWageredAmount:SetText(player2totalBetAmount .. " G")
        else
    end   
end

-- Function to handle Player 2 21+3 Bet Image
local function PlaceBets2132(message)
    playerFrame.player2Coins213Bet:Show()
end

-- Function to handle Player 2 21+3 Bet Text
local function player2Place213BetText(message)
    local player2History213Bet = string.match(message, "(%d+)G")

        if player2History213Bet then
            player2213BetAmount:SetText(player2History213Bet .. " G")
            player2213BetAmount:Show()

            player2totalBetAmount = player2totalBetAmount + tonumber(player2History213Bet)
            historyFrame.player2totalWageredAmount:SetText(player2totalBetAmount .. " G")
        else
    end
end

local function player2PreloadBet()
    PlaySoundFile(soundFilePaths[43])
    player2MainBet = tonumber(player2PreloadEditBoxMainBet:GetText())
    player2PPBet = tonumber(player2PreloadEditBoxPPBet:GetText())
    player2213Bet = tonumber(player2PreloadEditBox213Bet:GetText())

    if player2MainBet and not player2PPBet and not player2213Bet then
        player2TotalRebetAmount = player2MainBet
    elseif player2MainBet and player2PPBet and not player2213Bet then
        player2TotalRebetAmount = player2MainBet + player2PPBet
    elseif player2MainBet and player2PPBet and player2213Bet then
        player2TotalRebetAmount = player2MainBet + player2PPBet + player2213Bet
    end

    player2currentBankroll = tonumber(string.match(bankrollFrame.player2TotalBankrollTableDisplay:GetText(), "%d+"))

    if player2currentBankroll < player2TotalRebetAmount then
        print("You do not have enough gold in your bankroll to place that bet. Please visit the Cash Desk.")
    else

        if player2MainBet and player2MainBet >= minBetMain and player2MainBet <= maxBetMain then
            -- Valid bet amount, send the message with the bet
            SendChatMessage("[P2] Placing a " ..player2MainBet.. "G main bet.", "RAID")
            -- Disable the edit box and button
            player2PreloadEditBoxMainBet:SetFocus(false)
            player2PreloadEditBoxMainBet:ClearFocus()

            player2MainBetEditBox:SetText(player2MainBet)
            player2MainBetEditBox:SetFocus(false)
            player2MainBetEditBox:ClearFocus()
            player2MainBetEditBox:Disable()
            player2ConfirmMainBetButton:Disable()
        end
        
        if player2PPBet and player2PPBet >= minBetPP and player2PPBet <= maxBetPP then
            -- Valid bet amount, send the message with the bet
            SendChatMessage("[P2] Placing a " ..player2PPBet.. "G side bet on Perfect Pairs.", "RAID")
            -- Disable the edit box and button
            player2PreloadEditBoxPPBet:SetFocus(false)
            player2PreloadEditBoxPPBet:ClearFocus()

            player2PPBetEditBox:SetText(player2PPBet)
            player2PPBetEditBox:SetFocus(false)
            player2PPBetEditBox:ClearFocus()
            player2PPBetEditBox:Disable()
            player2ConfirmPPBetButton:Disable()
        end
        
        if player2213Bet and player2213Bet >= minBet213 and player2213Bet <= maxBet213 then
            -- Valid bet amount, send the message with the bet
            SendChatMessage("[P2] Placing a " ..player2213Bet.. "G side bet on 21+3.", "RAID")
            -- Disable the edit box and button
            player2PreloadEditBox213Bet:SetFocus(false)
            player2PreloadEditBox213Bet:ClearFocus()

            player2213BetEditBox:SetText(player2213Bet)
            player2213BetEditBox:SetFocus(false)
            player2213BetEditBox:ClearFocus()
            player2213BetEditBox:Disable()
            player2Confirm213BetButton:Disable()
        end
    
        player2PreloadBetButton:Disable()

        player2TotalBankrollAmount = player2TotalBankrollAmount - tonumber(player2TotalRebetAmount)
        bankrollFrame.player2TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")
        cashDeskFrame.player2TotalBankroll:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")

    end

end

-- Function to handle the Player 2 Main "Bet" button click
local function player2ConfirmMainBetClick()
    player2MainBet = tonumber(player2MainBetEditBox:GetText())
    player2currentBankroll = tonumber(string.match(bankrollFrame.player2TotalBankrollTableDisplay:GetText(), "%d+"))

    if player2MainBet and player2MainBet >= minBetMain and player2MainBet <= maxBetMain then
        if player2currentBankroll < player2MainBet then
            print("You do not have enough gold in your bankroll to place that bet. Please visit the Cash Desk.")
        else
            -- Valid bet amount, send the message with the bet
            SendChatMessage("[P2] Placing a " ..player2MainBet.. "G main bet.", "RAID")
            -- Disable the edit box and button
            player2MainBetEditBox:SetFocus(false)
            player2MainBetEditBox:ClearFocus()
            player2MainBetEditBox:Disable()
            player2ConfirmMainBetButton:Disable()

            player2PreloadBetButton:Disable()

            PlaySoundFile(soundFilePaths[43]) 

            player2TotalBankrollAmount = player2TotalBankrollAmount - tonumber(player2MainBet)
            bankrollFrame.player2TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")
            cashDeskFrame.player2TotalBankroll:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")

        end
    else
        print("Invalid bet amount. Please enter a value between " .. minBetMain .. "G and " .. maxBetMain .. "G.")
    end

end

-- Function to handle the Player 2 PP "Bet" button click
local function player2ConfirmPPBetClick()
    player2PPBet = tonumber(player2PPBetEditBox:GetText()) -- Get the entered bet amount
    player2currentBankroll = tonumber(string.match(bankrollFrame.player2TotalBankrollTableDisplay:GetText(), "%d+"))

    if player2PPBet and player2PPBet >= minBetPP and player2PPBet <= maxBetPP then
        if player2currentBankroll < player2PPBet then
            print("You do not have enough gold in your bankroll to place that bet. Please visit the Cash Desk.")
        else
            -- Valid bet amount, send the message with the bet
            SendChatMessage("[P2] Placing a " ..player2PPBet.. "G side bet on Perfect Pairs.", "RAID")
            -- Disable the edit box and button
            player2PPBetEditBox:SetFocus(false)
            player2PPBetEditBox:ClearFocus()
            player2PPBetEditBox:Disable()
            player2ConfirmPPBetButton:Disable()

            player2PreloadBetButton:Disable()

            PlaySoundFile(soundFilePaths[43])

            player2TotalBankrollAmount = player2TotalBankrollAmount - tonumber(player2PPBet)
            bankrollFrame.player2TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")
            cashDeskFrame.player2TotalBankroll:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")

        end
    else
        print("Invalid bet amount. Please enter a value between " .. minBetPP .. "G and " .. maxBetPP .. "G.")
    end

end

-- Function to handle the Player 2 21+3 "Bet" button click
local function player2Confirm213BetClick()
    player2213Bet = tonumber(player2213BetEditBox:GetText()) -- Get the entered bet amount
    player2currentBankroll = tonumber(string.match(bankrollFrame.player2TotalBankrollTableDisplay:GetText(), "%d+"))

    if player2213Bet and player2213Bet >= minBet213 and player2213Bet <= maxBet213 then
        if player2currentBankroll < player2213Bet then
            print("You do not have enough gold in your bankroll to place that bet. Please visit the Cash Desk.")
        else
            -- Valid bet amount, send the message with the bet
            SendChatMessage("[P2] Placing a " ..player2213Bet.. "G side bet on 21+3.", "RAID")
            -- Disable the edit box and button
            player2213BetEditBox:SetFocus(false)
            player2213BetEditBox:ClearFocus()
            player2213BetEditBox:Disable()
            player2Confirm213BetButton:Disable()

            player2PreloadBetButton:Disable()

            PlaySoundFile(soundFilePaths[43])

            player2TotalBankrollAmount = player2TotalBankrollAmount - tonumber(player2213Bet)
            bankrollFrame.player2TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")
            cashDeskFrame.player2TotalBankroll:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")

        end
    else
        print("Invalid bet amount. Please enter a value between " .. minBet213 .. "G and " .. maxBet213 .. "G.")
    end
 
end

-- Player 2 Main "Bet" button
player2ConfirmMainBetButton:SetScript("OnClick", player2ConfirmMainBetClick)

-- Player 2 PP "Bet" button
player2ConfirmPPBetButton:SetScript("OnClick", player2ConfirmPPBetClick)

-- Player 2 21+3 "Bet" button
player2Confirm213BetButton:SetScript("OnClick", player2Confirm213BetClick)

-- Player 2 "Bet All" Preload button
player2PreloadBetButton:SetScript("OnClick", player2PreloadBet)
























-- Insurance YES for Player 3
insuranceYesIcon3 = playerFrame:CreateTexture(nil, "OVERLAY")
insuranceYesIcon3:SetSize(32, 32)
insuranceYesIcon3:SetPoint("CENTER", playerFrame, 87, -205)
insuranceYesIcon3:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\insuranceYes.tga")
insuranceYesIcon3:SetDrawLayer("ARTWORK")
insuranceYesIcon3:Hide()

-- Insurance NO for Player 3
insuranceNoIcon3 = playerFrame:CreateTexture(nil, "OVERLAY")
insuranceNoIcon3:SetSize(32, 32)
insuranceNoIcon3:SetPoint("CENTER", playerFrame, 87, -205)
insuranceNoIcon3:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\insuranceNo.tga")
insuranceNoIcon3:SetDrawLayer("ARTWORK")
insuranceNoIcon3:Hide()

-- Buttons for Player 3
-- Hit
playerFrame.hitButton3 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.hitButton3:SetPoint("BOTTOM", playerFrame, -33, 80)
playerFrame.hitButton3:SetSize(65, 30)
playerFrame.hitButton3:SetText("Hit")
playerFrame.hitButton3:Disable()
-- Stand
playerFrame.standButton3 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.standButton3:SetPoint("BOTTOM", playerFrame, 33, 80)
playerFrame.standButton3:SetSize(65, 30)
playerFrame.standButton3:SetText("Stand")
playerFrame.standButton3:Disable()
-- Double
playerFrame.doubleButton3 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.doubleButton3:SetPoint("BOTTOM", playerFrame, -33, 50)
playerFrame.doubleButton3:SetSize(65, 30)
playerFrame.doubleButton3:SetText("Double")
playerFrame.doubleButton3:Disable()
-- Split
playerFrame.splitButton3 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.splitButton3:SetPoint("BOTTOM", playerFrame, 33, 50)
playerFrame.splitButton3:SetSize(65, 30)
playerFrame.splitButton3:SetText("Split")
playerFrame.splitButton3:Disable()
-- Insurance Yes
playerFrame.insuranceYesButton3 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.insuranceYesButton3:SetPoint("BOTTOM", playerFrame, -65, 20)
playerFrame.insuranceYesButton3:SetSize(55, 30)
playerFrame.insuranceYesButton3:SetText("Yes")
playerFrame.insuranceYesButton3:Disable()
-- Insurance No
playerFrame.insuranceNoButton3 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.insuranceNoButton3:SetPoint("BOTTOM", playerFrame, 63, 20)
playerFrame.insuranceNoButton3:SetSize(55, 30)
playerFrame.insuranceNoButton3:SetText("No")
playerFrame.insuranceNoButton3:Disable()
-- Main Bet Confirm
local confirmBetButtonMain3 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
confirmBetButtonMain3:SetPoint("BOTTOM", playerFrame, 33, 140)
confirmBetButtonMain3:SetSize(65, 30)
confirmBetButtonMain3:SetText("Bet")
-- Perfect Pairs Confirm
local confirmBetButtonPP3 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
confirmBetButtonPP3:SetPoint("BOTTOM", playerFrame, -56, 232)
confirmBetButtonPP3:SetSize(43, 25)
confirmBetButtonPP3:SetText("Bet")
-- 21+3 Confirm
local confirmBetButton2133 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
confirmBetButton2133:SetPoint("BOTTOM", playerFrame, 64, 232)
confirmBetButton2133:SetSize(43, 25)
confirmBetButton2133:SetText("Bet")



-- Wagers for Player 3
-- Main Bet
local betEditBoxMain3 = CreateFrame("EditBox", nil, playerFrame, "InputBoxTemplate")
betEditBoxMain3:SetSize(55, 30)
betEditBoxMain3:SetPoint("BOTTOM", playerFrame, -30, 140)
betEditBoxMain3:SetAutoFocus(false)
betEditBoxMain3:SetNumeric(true)
-- Perfect Pairs
local betEditBoxPP3 = CreateFrame("EditBox", nil, playerFrame, "InputBoxTemplate")
betEditBoxPP3:SetSize(35, 30)
betEditBoxPP3:SetPoint("BOTTOM", playerFrame, -54, 252)
betEditBoxPP3:SetAutoFocus(false)
betEditBoxPP3:SetNumeric(true)
-- 21+3
local betEditBox2133 = CreateFrame("EditBox", nil, playerFrame, "InputBoxTemplate")
betEditBox2133:SetSize(35, 30)
betEditBox2133:SetPoint("BOTTOM", playerFrame, 66, 252)
betEditBox2133:SetAutoFocus(false)
betEditBox2133:SetNumeric(true)



-- Labels for Player 3
-- Main Bet
playerFrame.mainBet3 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.mainBet3:SetPoint("BOTTOM", playerFrame, -31, 167)
playerFrame.mainBet3:SetJustifyH("CENTER")
playerFrame.mainBet3:SetText("Main Bet")
playerFrame.mainBet3:SetFont("Fonts\\FRIZQT__.TTF", 8, "OUTLINE")
-- Main Bet Amount
mainBetAmount3 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
mainBetAmount3:SetPoint("CENTER", playerFrame, 6, -59)
mainBetAmount3:SetJustifyH("CENTER")
mainBetAmount3:SetFont("Fonts\\FRIZQT__.TTF", 8, "OUTLINE")
-- Perfect Pairs
playerFrame.ppBet3 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.ppBet3:SetPoint("BOTTOM", playerFrame, -90, 250)
playerFrame.ppBet3:SetJustifyH("CENTER")
playerFrame.ppBet3:SetText("PP")
playerFrame.ppBet3:SetFont("Fonts\\FRIZQT__.TTF", 15, "OUTLINE")
-- Perfect Pairs Amount
ppBetAmount3 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
ppBetAmount3:SetPoint("CENTER", playerFrame, -51, -35)
ppBetAmount3:SetJustifyH("CENTER")
ppBetAmount3:SetFont("Fonts\\FRIZQT__.TTF", 8, "OUTLINE")
-- 21+3
playerFrame.t213Bet3 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.t213Bet3:SetPoint("BOTTOM", playerFrame, 109, 250)
playerFrame.t213Bet3:SetJustifyH("CENTER")
playerFrame.t213Bet3:SetText("21+3")
playerFrame.t213Bet3:SetFont("Fonts\\FRIZQT__.TTF", 15, "OUTLINE")
-- 21+3 Amount
t213BetAmount3 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
t213BetAmount3:SetPoint("CENTER", playerFrame, 67, -36)
t213BetAmount3:SetJustifyH("CENTER")
t213BetAmount3:SetFont("Fonts\\FRIZQT__.TTF", 8, "OUTLINE")
-- Player Name
playerFrame.player3Name = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.player3Name:SetPoint("BOTTOM", playerFrame, 0, 116)
playerFrame.player3Name:SetText(UnitName("player"))
playerFrame.player3Name:SetFont("Fonts\\FRIZQT__.TTF", 22, "OUTLINE")
-- Insurance
playerFrame.insuranceBet3 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.insuranceBet3:SetPoint("BOTTOM", playerFrame, 0, 34)
playerFrame.insuranceBet3:SetText("Insurance")
playerFrame.insuranceBet3:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
-- Insurance (if available)
playerFrame.insuranceIfAvailable3 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.insuranceIfAvailable3:SetPoint("BOTTOM", playerFrame, 0, 24)
playerFrame.insuranceIfAvailable3:SetText("(if available)")
playerFrame.insuranceIfAvailable3:SetFont("Fonts\\FRIZQT__.TTF", 8, "OUTLINE")



-- Images for Player 3
-- Main Bet
playerFrame.coinsMainBet3 = playerFrame:CreateTexture(nil, "OVERLAY")
playerFrame.coinsMainBet3:SetSize(128, 128)
playerFrame.coinsMainBet3:SetPoint("CENTER", playerFrame, 23, -90)
playerFrame.coinsMainBet3:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CoinsBet.tga")
playerFrame.coinsMainBet3:SetBlendMode("BLEND")
playerFrame.coinsMainBet3:SetDrawLayer("OVERLAY")
playerFrame.coinsMainBet3:Hide()
-- PP Bet
playerFrame.coinsPPBet3 = playerFrame:CreateTexture(nil, "OVERLAY")
playerFrame.coinsPPBet3:SetSize(128, 128)
playerFrame.coinsPPBet3:SetPoint("CENTER", playerFrame, -47, -55)
playerFrame.coinsPPBet3:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CoinsHalfBet.tga")
playerFrame.coinsPPBet3:SetBlendMode("BLEND")
playerFrame.coinsPPBet3:SetDrawLayer("OVERLAY")
playerFrame.coinsPPBet3:Hide()
-- 21+3 Bet
playerFrame.coins213Bet3 = playerFrame:CreateTexture(nil, "OVERLAY")
playerFrame.coins213Bet3:SetSize(128, 128)
playerFrame.coins213Bet3:SetPoint("CENTER", playerFrame, 72, -56)
playerFrame.coins213Bet3:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CoinsHalfBet.tga")
playerFrame.coins213Bet3:SetBlendMode("BLEND")
playerFrame.coins213Bet3:SetDrawLayer("OVERLAY")
playerFrame.coins213Bet3:Hide()



-- Function to handle Player 3 Main Bet Image
local function PlaceBetsMain3(message)
    playerFrame.coinsMainBet3:Show()
end

-- Function to handle Player 3 Main Bet Text
local function PlaceBetsTextMain3(Amount)
    mainBetAmount3:SetText(Amount .. " G")
    mainBetAmount3:Show()
end

-- Function to handle Player 3 PP Bet Image
local function PlaceBetsPP3(message)
    playerFrame.coinsPPBet3:Show()
end

-- Function to handle Player 3 PP Bet Text
local function PlaceBetsTextPP3(Amount)
    ppBetAmount3:SetText(Amount .. " G")
    ppBetAmount3:Show()
end

-- Function to handle Player 3 21+3 Bet Image
local function PlaceBets2133(message)
    playerFrame.coins213Bet3:Show()
end

-- Function to handle Player 3 21+3 Bet Text
local function PlaceBetsText2133(Amount)
    t213BetAmount3:SetText(Amount .. " G")
    t213BetAmount3:Show()
end

-- Function to handle the Player 3 Main "Bet" button click
local function ConfirmBetClickMain3()
    betAmountMain3 = tonumber(betEditBoxMain3:GetText()) -- Get the entered bet amount
    if betAmountMain3 and betAmountMain3 >= minBetMain and betAmountMain3 <= maxBetMain then
        -- Valid bet amount, send the message with the bet
        SendChatMessage("[P3] Placing a " ..betAmountMain3.. "G main bet.", "RAID")
        -- Disable the edit box and button
        betEditBoxMain3:SetFocus(false)
        betEditBoxMain3:ClearFocus()
        betEditBoxMain3:Disable()
        confirmBetButtonMain3:Disable()
        PlaySoundFile(soundFilePaths[43])
    else
        print("Invalid bet amount. Please enter a value between " .. minBetMain .. "G and " .. maxBetMain .. "G.")
    end
end

-- Function to handle the Player 3 PP "Bet" button click
local function ConfirmBetClickPP3()
    betAmountPP3 = tonumber(betEditBoxPP3:GetText()) -- Get the entered bet amount
    if betAmountPP3 and betAmountPP3 >= minBetPP and betAmountPP3 <= maxBetPP then
        -- Valid bet amount, send the message with the bet
        SendChatMessage("[P3] Placing a " ..betAmountPP3.. "G side bet on Perfect Pairs.", "RAID")
        -- Disable the edit box and button
        betEditBoxPP3:SetFocus(false)
        betEditBoxPP3:ClearFocus()
        betEditBoxPP3:Disable()
        confirmBetButtonPP3:Disable()
        PlaySoundFile(soundFilePaths[43])
    else
        print("Invalid bet amount. Please enter a value between " .. minBetPP .. "G and " .. maxBetPP .. "G.")
    end
end

-- Function to handle the Player 3 21+3 "Bet" button click
local function ConfirmBetClick2133()
    betAmount2133 = tonumber(betEditBox2133:GetText()) -- Get the entered bet amount
    if betAmount2133 and betAmount2133 >= minBet213 and betAmount2133 <= maxBet213 then
        -- Valid bet amount, send the message with the bet
        SendChatMessage("[P3] Placing a " ..betAmount2133.. "G side bet on 21+3.", "RAID")
        -- Disable the edit box and button
        betEditBox2133:SetFocus(false)
        betEditBox2133:ClearFocus()
        betEditBox2133:Disable()
        confirmBetButton2133:Disable()
        PlaySoundFile(soundFilePaths[43])
    else
        print("Invalid bet amount. Please enter a value between " .. minBet213 .. "G and " .. maxBet213 .. "G.")
    end
end

-- Player 3 Main "Bet" button
confirmBetButtonMain3:SetScript("OnClick", ConfirmBetClickMain3)

-- Player 3 PP "Bet" button
confirmBetButtonPP3:SetScript("OnClick", ConfirmBetClickPP3)

-- Player 3 21+3 "Bet" button
confirmBetButton2133:SetScript("OnClick", ConfirmBetClick2133)
























-- Insurance YES for Player 4
insuranceYesIcon4 = playerFrame:CreateTexture(nil, "OVERLAY")
insuranceYesIcon4:SetSize(32, 32)
insuranceYesIcon4:SetPoint("CENTER", playerFrame, -340, -158)
insuranceYesIcon4:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\insuranceYes.tga")
insuranceYesIcon4:SetDrawLayer("ARTWORK")
insuranceYesIcon4:Hide()

-- Insurance NO for Player 4
insuranceYesIcon4 = playerFrame:CreateTexture(nil, "OVERLAY")
insuranceYesIcon4:SetSize(32, 32)
insuranceYesIcon4:SetPoint("CENTER", playerFrame, -340, -152)
insuranceYesIcon4:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\insuranceNo.tga")
insuranceYesIcon4:SetDrawLayer("ARTWORK")
insuranceYesIcon4:Hide()

-- Buttons for Player 4
-- Hit
playerFrame.hitButton4 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.hitButton4:SetPoint("BOTTOM", playerFrame, -288, 135)
playerFrame.hitButton4:SetSize(65, 30)
playerFrame.hitButton4:SetText("Hit")
playerFrame.hitButton4:Disable()
-- Stand
playerFrame.standButton4 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.standButton4:SetPoint("BOTTOM", playerFrame, -222, 135)
playerFrame.standButton4:SetSize(65, 30)
playerFrame.standButton4:SetText("Stand")
playerFrame.standButton4:Disable()
-- Double
playerFrame.doubleButton4 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.doubleButton4:SetPoint("BOTTOM", playerFrame, -288, 105)
playerFrame.doubleButton4:SetSize(65, 30)
playerFrame.doubleButton4:SetText("Double")
playerFrame.doubleButton4:Disable()
-- Split
playerFrame.splitButton4 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.splitButton4:SetPoint("BOTTOM", playerFrame, -222, 105)
playerFrame.splitButton4:SetSize(65, 30)
playerFrame.splitButton4:SetText("Split")
playerFrame.splitButton4:Disable()
-- Insurance Yes
playerFrame.insuranceYesButton4 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.insuranceYesButton4:SetPoint("BOTTOM", playerFrame, -320, 75)
playerFrame.insuranceYesButton4:SetSize(55, 30)
playerFrame.insuranceYesButton4:SetText("Yes")
playerFrame.insuranceYesButton4:Disable()
-- Insurance No
playerFrame.insuranceNoButton4 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.insuranceNoButton4:SetPoint("BOTTOM", playerFrame, -195, 75)
playerFrame.insuranceNoButton4:SetSize(55, 30)
playerFrame.insuranceNoButton4:SetText("No")
playerFrame.insuranceNoButton4:Disable()
-- Main Bet Confirm
local confirmBetButtonMain4 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
confirmBetButtonMain4:SetPoint("BOTTOM", playerFrame, -222, 195)
confirmBetButtonMain4:SetSize(65, 30)
confirmBetButtonMain4:SetText("Bet")
-- Perfect Pairs Confirm
local confirmBetButtonPP4 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
confirmBetButtonPP4:SetPoint("BOTTOM", playerFrame, -237, 295)
confirmBetButtonPP4:SetSize(43, 25)
confirmBetButtonPP4:SetText("Bet")
-- 21+3 Confirm
local confirmBetButton2134 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
confirmBetButton2134:SetPoint("BOTTOM", playerFrame, -121, 244)
confirmBetButton2134:SetSize(43, 25)
confirmBetButton2134:SetText("Bet")

-- Wagers for Player 4
-- Main Bet
local betEditBoxMain4 = CreateFrame("EditBox", nil, playerFrame, "InputBoxTemplate")
betEditBoxMain4:SetSize(55, 30)
betEditBoxMain4:SetPoint("BOTTOM", playerFrame, -284, 195)
betEditBoxMain4:SetAutoFocus(false)
betEditBoxMain4:SetNumeric(true)
-- Perfect Pairs
local betEditBoxPP4 = CreateFrame("EditBox", nil, playerFrame, "InputBoxTemplate")
betEditBoxPP4:SetSize(35, 30)
betEditBoxPP4:SetPoint("BOTTOM", playerFrame, -235, 315)
betEditBoxPP4:SetAutoFocus(false)
betEditBoxPP4:SetNumeric(true)
-- 21+3
local betEditBox2134 = CreateFrame("EditBox", nil, playerFrame, "InputBoxTemplate")
betEditBox2134:SetSize(35, 30)
betEditBox2134:SetPoint("BOTTOM", playerFrame, -119, 264)
betEditBox2134:SetAutoFocus(false)
betEditBox2134:SetNumeric(true)

-- Labels for Player 4
-- Main Bet
playerFrame.mainBet4 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.mainBet4:SetPoint("BOTTOM", playerFrame, -284, 222)
playerFrame.mainBet4:SetJustifyH("CENTER")
playerFrame.mainBet4:SetText("Main Bet")
playerFrame.mainBet4:SetFont("Fonts\\FRIZQT__.TTF", 8, "OUTLINE")
-- Main Bet Amount
mainBetAmount4 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
mainBetAmount4:SetPoint("CENTER", playerFrame, -179, -18)
mainBetAmount4:SetJustifyH("CENTER")
mainBetAmount4:SetFont("Fonts\\FRIZQT__.TTF", 8, "OUTLINE")
-- Perfect Pairs
playerFrame.ppBet4 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.ppBet4:SetPoint("BOTTOM", playerFrame, -270, 312)
playerFrame.ppBet4:SetJustifyH("CENTER")
playerFrame.ppBet4:SetText("PP")
playerFrame.ppBet4:SetFont("Fonts\\FRIZQT__.TTF", 15, "OUTLINE")
-- Perfect Pairs Amount
ppBetAmount4 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
ppBetAmount4:SetPoint("CENTER", playerFrame, -219, 26)
ppBetAmount4:SetJustifyH("CENTER")
ppBetAmount4:SetFont("Fonts\\FRIZQT__.TTF", 8, "OUTLINE")
-- 21+3
playerFrame.t213Bet4 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.t213Bet4:SetPoint("BOTTOM", playerFrame, -75, 259)
playerFrame.t213Bet4:SetJustifyH("CENTER")
playerFrame.t213Bet4:SetText("21+3")
playerFrame.t213Bet4:SetFont("Fonts\\FRIZQT__.TTF", 15, "OUTLINE")
-- 21+3 Amount
t213BetAmount4 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
t213BetAmount4:SetPoint("CENTER", playerFrame, -107, -25)
t213BetAmount4:SetJustifyH("CENTER")
t213BetAmount4:SetFont("Fonts\\FRIZQT__.TTF", 8, "OUTLINE")
-- Player Name
playerFrame.player4Name = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.player4Name:SetPoint("BOTTOM", playerFrame, -255, 171)
playerFrame.player4Name:SetText(UnitName("player"))
playerFrame.player4Name:SetFont("Fonts\\FRIZQT__.TTF", 22, "OUTLINE")
-- Insurance
playerFrame.insuranceBet4 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.insuranceBet4:SetPoint("BOTTOM", playerFrame, -255, 89)
playerFrame.insuranceBet4:SetText("Insurance")
playerFrame.insuranceBet4:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
-- Insurance (if available)
playerFrame.insuranceIfAvailable4 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.insuranceIfAvailable4:SetPoint("BOTTOM", playerFrame, -255, 79)
playerFrame.insuranceIfAvailable4:SetText("(if available)")
playerFrame.insuranceIfAvailable4:SetFont("Fonts\\FRIZQT__.TTF", 8, "OUTLINE")



-- Images for Player 4
-- Main Bet
playerFrame.coinsMainBet4 = playerFrame:CreateTexture(nil, "OVERLAY")
playerFrame.coinsMainBet4:SetSize(128, 128)
playerFrame.coinsMainBet4:SetPoint("CENTER", playerFrame, -163, -48)
playerFrame.coinsMainBet4:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CoinsBet.tga")
playerFrame.coinsMainBet4:SetBlendMode("BLEND")
playerFrame.coinsMainBet4:SetDrawLayer("OVERLAY")
playerFrame.coinsMainBet4:Hide()
-- PP Bet
playerFrame.coinsPPBet4 = playerFrame:CreateTexture(nil, "OVERLAY")
playerFrame.coinsPPBet4:SetSize(128, 128)
playerFrame.coinsPPBet4:SetPoint("CENTER", playerFrame, -215, 8)
playerFrame.coinsPPBet4:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CoinsHalfBet.tga")
playerFrame.coinsPPBet4:SetBlendMode("BLEND")
playerFrame.coinsPPBet4:SetDrawLayer("OVERLAY")
playerFrame.coinsPPBet4:Hide()
-- 21+3 Bet
playerFrame.coins213Bet4 = playerFrame:CreateTexture(nil, "OVERLAY")
playerFrame.coins213Bet4:SetSize(128, 128)
playerFrame.coins213Bet4:SetPoint("CENTER", playerFrame, -102, -44)
playerFrame.coins213Bet4:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CoinsHalfBet.tga")
playerFrame.coins213Bet4:SetBlendMode("BLEND")
playerFrame.coins213Bet4:SetDrawLayer("OVERLAY")
playerFrame.coins213Bet4:Hide()

-- Function to handle Player 4 Main Bet Image
local function PlaceBetsMain4(message)
    playerFrame.coinsMainBet4:Show()
end

-- Function to handle Player 4 Main Bet Text
local function PlaceBetsTextMain4(Amount)
    mainBetAmount4:SetText(Amount .. " G")
    mainBetAmount4:Show()
end

-- Function to handle Player 4 PP Bet Image
local function PlaceBetsPP4(message)
    playerFrame.coinsPPBet4:Show()
end

-- Function to handle Player 4 PP Bet Text
local function PlaceBetsTextPP4(Amount)
    ppBetAmount4:SetText(Amount .. " G")
    ppBetAmount4:Show()
end

-- Function to handle Player 4 21+3 Bet Image
local function PlaceBets2134(message)
    playerFrame.coins213Bet4:Show()
end

-- Function to handle Player 4 21+3 Bet Text
local function PlaceBetsText2134(Amount)
    t213BetAmount4:SetText(Amount .. " G")
    t213BetAmount4:Show()
end

-- Function to handle the Player 4 Main "Bet" button click
local function ConfirmBetClickMain4()
    betAmountMain4 = tonumber(betEditBoxMain4:GetText()) -- Get the entered bet amount
    if betAmountMain4 and betAmountMain4 >= minBetMain and betAmountMain4 <= maxBetMain then
        -- Valid bet amount, send the message with the bet
        SendChatMessage("[P4] Placing a " ..betAmountMain4.. "G main bet.", "RAID")
        -- Disable the edit box and button
        betEditBoxMain4:SetFocus(false)
        betEditBoxMain4:ClearFocus()
        betEditBoxMain4:Disable()
        confirmBetButtonMain4:Disable()
        PlaySoundFile(soundFilePaths[43])
    else
        print("Invalid bet amount. Please enter a value between " .. minBetMain .. "G and " .. maxBetMain .. "G.")
    end
end

-- Function to handle the Player 4 PP "Bet" button click
local function ConfirmBetClickPP4()
    betAmountPP4 = tonumber(betEditBoxPP4:GetText()) -- Get the entered bet amount
    if betAmountPP4 and betAmountPP4 >= minBetPP and betAmountPP4 <= maxBetPP then
        -- Valid bet amount, send the message with the bet
        SendChatMessage("[P4] Placing a " ..betAmountPP4.. "G side bet on Perfect Pairs.", "RAID")
        -- Disable the edit box and button
        betEditBoxPP4:SetFocus(false)
        betEditBoxPP4:ClearFocus()
        betEditBoxPP4:Disable()
        confirmBetButtonPP4:Disable()
        PlaySoundFile(soundFilePaths[43])
    else
        print("Invalid bet amount. Please enter a value between " .. minBetPP .. "G and " .. maxBetPP .. "G.")
    end
end

-- Function to handle the Player 4 21+3 "Bet" button click
local function ConfirmBetClick2134()
    betAmount2134 = tonumber(betEditBox2134:GetText()) -- Get the entered bet amount
    if betAmount2134 and betAmount2134 >= minBet213 and betAmount2134 <= maxBet213 then
        -- Valid bet amount, send the message with the bet
        SendChatMessage("[P4] Placing a " ..betAmount2134.. "G side bet on 21+3.", "RAID")
        -- Disable the edit box and button
        betEditBox2134:SetFocus(false)
        betEditBox2134:ClearFocus()
        betEditBox2134:Disable()
        confirmBetButton2134:Disable()
        PlaySoundFile(soundFilePaths[43])
    else
        print("Invalid bet amount. Please enter a value between " .. minBet213 .. "G and " .. maxBet213 .. "G.")
    end
end

-- Player 4 Main "Bet" button
confirmBetButtonMain4:SetScript("OnClick", ConfirmBetClickMain4)

-- Player 4 PP "Bet" button
confirmBetButtonPP4:SetScript("OnClick", ConfirmBetClickPP4)

-- Player 4 21+3 "Bet" button
confirmBetButton2134:SetScript("OnClick", ConfirmBetClick2134)






















-- Insurance YES for Player 5
insuranceYesIcon5 = playerFrame:CreateTexture(nil, "OVERLAY")
insuranceYesIcon5:SetSize(32, 32)
insuranceYesIcon5:SetPoint("CENTER", playerFrame, -523, -12)
insuranceYesIcon5:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\insuranceYes.tga")
insuranceYesIcon5:SetDrawLayer("ARTWORK")
insuranceYesIcon5:Hide()

-- Insurance NO for Player 5
insuranceNoIcon5 = playerFrame:CreateTexture(nil, "OVERLAY")
insuranceNoIcon5:SetSize(32, 32)
insuranceNoIcon5:SetPoint("CENTER", playerFrame, -523, -12)
insuranceNoIcon5:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\insuranceNo.tga")
insuranceNoIcon5:SetDrawLayer("ARTWORK")
insuranceNoIcon5:Hide()

-- Buttons for Player 5
-- Hit
playerFrame.hitButton5 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.hitButton5:SetPoint("BOTTOM", playerFrame, -472, 275)
playerFrame.hitButton5:SetSize(65, 30)
playerFrame.hitButton5:SetText("Hit")
playerFrame.hitButton5:Disable()
-- Stand
playerFrame.standButton5 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.standButton5:SetPoint("BOTTOM", playerFrame, -406, 275)
playerFrame.standButton5:SetSize(65, 30)
playerFrame.standButton5:SetText("Stand")
playerFrame.standButton5:Disable()
-- Double
playerFrame.doubleButton5 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.doubleButton5:SetPoint("BOTTOM", playerFrame, -472, 245)
playerFrame.doubleButton5:SetSize(65, 30)
playerFrame.doubleButton5:SetText("Double")
playerFrame.doubleButton5:Disable()
-- Split
playerFrame.splitButton5 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.splitButton5:SetPoint("BOTTOM", playerFrame, -406, 245)
playerFrame.splitButton5:SetSize(65, 30)
playerFrame.splitButton5:SetText("Split")
playerFrame.splitButton5:Disable()
-- Insurance Yes
playerFrame.insuranceYesButton5 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.insuranceYesButton5:SetPoint("BOTTOM", playerFrame, -505, 215)
playerFrame.insuranceYesButton5:SetSize(55, 30)
playerFrame.insuranceYesButton5:SetText("Yes")
playerFrame.insuranceYesButton5:Disable()
-- Insurance No
playerFrame.insuranceNoButton5 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
playerFrame.insuranceNoButton5:SetPoint("BOTTOM", playerFrame, -378, 215)
playerFrame.insuranceNoButton5:SetSize(55, 30)
playerFrame.insuranceNoButton5:SetText("No")
playerFrame.insuranceNoButton5:Disable()
-- Main Bet Confirm
local confirmBetButtonMain5 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
confirmBetButtonMain5:SetPoint("BOTTOM", playerFrame, -406, 334)
confirmBetButtonMain5:SetSize(65, 30)
confirmBetButtonMain5:SetText("Bet")
-- Perfect Pairs Confirm
local confirmBetButtonPP5 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
confirmBetButtonPP5:SetPoint("BOTTOM", playerFrame, -375, 468)
confirmBetButtonPP5:SetSize(43, 25)
confirmBetButtonPP5:SetText("Bet")
-- 21+3 Confirm
local confirmBetButton2135 = CreateFrame("Button", nil, playerFrame, "GameMenuButtonTemplate")
confirmBetButton2135:SetPoint("BOTTOM", playerFrame, -305, 335)
confirmBetButton2135:SetSize(43, 25)
confirmBetButton2135:SetText("Bet")

-- Wagers for Player 5
-- Main Bet
local betEditBoxMain5 = CreateFrame("EditBox", nil, playerFrame, "InputBoxTemplate")
betEditBoxMain5:SetSize(55, 30)
betEditBoxMain5:SetPoint("BOTTOM", playerFrame, -468, 334)
betEditBoxMain5:SetAutoFocus(false)
betEditBoxMain5:SetNumeric(true)
-- Perfect Pairs
local betEditBoxPP5 = CreateFrame("EditBox", nil, playerFrame, "InputBoxTemplate")
betEditBoxPP5:SetSize(35, 30)
betEditBoxPP5:SetPoint("BOTTOM", playerFrame, -373, 488)
betEditBoxPP5:SetAutoFocus(false)
betEditBoxPP5:SetNumeric(true)
-- 21+3
local betEditBox2135 = CreateFrame("EditBox", nil, playerFrame, "InputBoxTemplate")
betEditBox2135:SetSize(35, 30)
betEditBox2135:SetPoint("BOTTOM", playerFrame, -303, 355)
betEditBox2135:SetAutoFocus(false)
betEditBox2135:SetNumeric(true)

-- Labels for Player 5
-- Main Bet
playerFrame.mainBet5 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.mainBet5:SetPoint("BOTTOM", playerFrame, -468, 362)
playerFrame.mainBet5:SetJustifyH("CENTER")
playerFrame.mainBet5:SetText("Main Bet")
playerFrame.mainBet5:SetFont("Fonts\\FRIZQT__.TTF", 8, "OUTLINE")
-- Main Bet Amount
mainBetAmount5 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
mainBetAmount5:SetPoint("CENTER", playerFrame, -330, 97)
mainBetAmount5:SetJustifyH("CENTER")
mainBetAmount5:SetFont("Fonts\\FRIZQT__.TTF", 8, "OUTLINE")
-- Perfect Pairs
playerFrame.ppBet5 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.ppBet5:SetPoint("BOTTOM", playerFrame, -408, 483)
playerFrame.ppBet5:SetJustifyH("CENTER")
playerFrame.ppBet5:SetText("PP")
playerFrame.ppBet5:SetFont("Fonts\\FRIZQT__.TTF", 15, "OUTLINE")
-- Perfect Pairs Amount
ppBetAmount5 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
ppBetAmount5:SetPoint("CENTER", playerFrame, -328, 154)
ppBetAmount5:SetJustifyH("CENTER")
ppBetAmount5:SetFont("Fonts\\FRIZQT__.TTF", 8, "OUTLINE")
-- 21+3
playerFrame.t213Bet5 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.t213Bet5:SetPoint("BOTTOM", playerFrame, -261, 351)
playerFrame.t213Bet5:SetJustifyH("CENTER")
playerFrame.t213Bet5:SetText("21+3")
playerFrame.t213Bet5:SetFont("Fonts\\FRIZQT__.TTF", 15, "OUTLINE")
-- 21+3 Amount
t213BetAmount5 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
t213BetAmount5:SetPoint("CENTER", playerFrame, -263, 56)
t213BetAmount5:SetJustifyH("CENTER")
t213BetAmount5:SetFont("Fonts\\FRIZQT__.TTF", 8, "OUTLINE")
-- Player Name
playerFrame.player5Name = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.player5Name:SetPoint("BOTTOM", playerFrame, -439, 310)
playerFrame.player5Name:SetText(UnitName("player"))
playerFrame.player5Name:SetFont("Fonts\\FRIZQT__.TTF", 22, "OUTLINE")
-- Insurance
playerFrame.insuranceBet5 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.insuranceBet5:SetPoint("BOTTOM", playerFrame, -439, 228)
playerFrame.insuranceBet5:SetText("Insurance")
playerFrame.insuranceBet5:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
-- Insurance (if available)
playerFrame.insuranceIfAvailable5 = playerFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
playerFrame.insuranceIfAvailable5:SetPoint("BOTTOM", playerFrame, -439, 218)
playerFrame.insuranceIfAvailable5:SetText("(if available)")
playerFrame.insuranceIfAvailable5:SetFont("Fonts\\FRIZQT__.TTF", 8, "OUTLINE")

-- Images for Player 5
-- Main Bet
playerFrame.coinsMainBet5 = playerFrame:CreateTexture(nil, "OVERLAY")
playerFrame.coinsMainBet5:SetSize(128, 128)
playerFrame.coinsMainBet5:SetPoint("CENTER", playerFrame, -308, 68)
playerFrame.coinsMainBet5:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CoinsBet.tga")
playerFrame.coinsMainBet5:SetBlendMode("BLEND")
playerFrame.coinsMainBet5:SetDrawLayer("OVERLAY")
playerFrame.coinsMainBet5:Hide()
-- PP Bet
playerFrame.coinsPPBet5 = playerFrame:CreateTexture(nil, "OVERLAY")
playerFrame.coinsPPBet5:SetSize(128, 128)
playerFrame.coinsPPBet5:SetPoint("CENTER", playerFrame, -323, 136)
playerFrame.coinsPPBet5:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CoinsHalfBet.tga")
playerFrame.coinsPPBet5:SetBlendMode("BLEND")
playerFrame.coinsPPBet5:SetDrawLayer("OVERLAY")
playerFrame.coinsPPBet5:Hide()
-- 21+3 Bet
playerFrame.coins213Bet5 = playerFrame:CreateTexture(nil, "OVERLAY")
playerFrame.coins213Bet5:SetSize(128, 128)
playerFrame.coins213Bet5:SetPoint("CENTER", playerFrame, -258, 36)
playerFrame.coins213Bet5:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\CoinsHalfBet.tga")
playerFrame.coins213Bet5:SetBlendMode("BLEND")
playerFrame.coins213Bet5:SetDrawLayer("OVERLAY")
playerFrame.coins213Bet5:Hide()

-- Function to handle Player 5 Main Bet Image
local function PlaceBetsMain5(message)
    playerFrame.coinsMainBet5:Show()
end

-- Function to handle Player 5 Main Bet Text
local function PlaceBetsTextMain5(Amount)
    mainBetAmount5:SetText(Amount .. " G")
    mainBetAmount5:Show()
end

-- Function to handle Player 5 PP Bet Image
local function PlaceBetsPP5(message)
    playerFrame.coinsPPBet5:Show()
end

-- Function to handle Player 5 PP Bet Text
local function PlaceBetsTextPP5(Amount)
    ppBetAmount5:SetText(Amount .. " G")
    ppBetAmount5:Show()
end

-- Function to handle Player 5 21+3 Bet Image
local function PlaceBets2135(message)
    playerFrame.coins213Bet5:Show()
end

-- Function to handle Player 5 21+3 Bet Text
local function PlaceBetsText2135(Amount)
    t213BetAmount5:SetText(Amount .. " G")
    t213BetAmount5:Show()
end

-- Function to handle the Player 5 Main "Bet" button click
local function ConfirmBetClickMain5()
    betAmountMain5 = tonumber(betEditBoxMain5:GetText()) -- Get the entered bet amount
    if betAmountMain5 and betAmountMain5 >= minBetMain and betAmountMain5 <= maxBetMain then
        -- Valid bet amount, send the message with the bet
        SendChatMessage("[P5] Placing a " ..betAmountMain5.. "G main bet.", "RAID")
        -- Disable the edit box and button
        betEditBoxMain5:SetFocus(false)
        betEditBoxMain5:ClearFocus()
        betEditBoxMain5:Disable()
        confirmBetButtonMain5:Disable()
        PlaySoundFile(soundFilePaths[43])
    else
        print("Invalid bet amount. Please enter a value between " .. minBetMain .. "G and " .. maxBetMain .. "G.")
    end
end

-- Function to handle the Player 5 PP "Bet" button click
local function ConfirmBetClickPP5()
    betAmountPP5 = tonumber(betEditBoxPP5:GetText()) -- Get the entered bet amount
    if betAmountPP5 and betAmountPP5 >= minBetPP and betAmountPP5 <= maxBetPP then
        -- Valid bet amount, send the message with the bet
        SendChatMessage("[P5] Placing a " ..betAmountPP5.. "G side bet on Perfect Pairs.", "RAID")
        -- Disable the edit box and button
        betEditBoxPP5:SetFocus(false)
        betEditBoxPP5:ClearFocus()
        betEditBoxPP5:Disable()
        confirmBetButtonPP5:Disable()
        PlaySoundFile(soundFilePaths[43])
    else
        print("Invalid bet amount. Please enter a value between " .. minBetPP .. "G and " .. maxBetPP .. "G.")
    end
end

-- Function to handle the Player 5 21+3 "Bet" button click
local function ConfirmBetClick2135()
    betAmount2135 = tonumber(betEditBox2135:GetText()) -- Get the entered bet amount
    if betAmount2135 and betAmount2135 >= minBet213 and betAmount2135 <= maxBet213 then
        -- Valid bet amount, send the message with the bet
        SendChatMessage("[P5] Placing a " ..betAmount2135.. "G side bet on 21+3.", "RAID")
        -- Disable the edit box and button
        betEditBox2135:SetFocus(false)
        betEditBox2135:ClearFocus()
        betEditBox2135:Disable()
        confirmBetButton2135:Disable()
        PlaySoundFile(soundFilePaths[43])
    else
        print("Invalid bet amount. Please enter a value between " .. minBet213 .. "G and " .. maxBet213 .. "G.")
    end
end

-- Player 5 Main "Bet" button
confirmBetButtonMain5:SetScript("OnClick", ConfirmBetClickMain5)

-- Player 5 PP "Bet" button
confirmBetButtonPP5:SetScript("OnClick", ConfirmBetClickPP5)

-- Player 5 21+3 "Bet" button
confirmBetButton2135:SetScript("OnClick", ConfirmBetClick2135)























playerFrame:SetScript("OnMouseDown", function(self, button)
    if button == "LeftButton" then
        player1PreloadEditBoxMainBet:ClearFocus()
        player1PreloadEditBoxPPBet:ClearFocus()
        player1PreloadEditBox213Bet:ClearFocus()
        player1MainBetEditBox:ClearFocus()
        player1PPBetEditBox:ClearFocus()
        player1213BetEditBox:ClearFocus()
        player2PreloadEditBoxMainBet:ClearFocus()
        player2PreloadEditBoxPPBet:ClearFocus()
        player2PreloadEditBox213Bet:ClearFocus()
        player2MainBetEditBox:ClearFocus()
        player2PPBetEditBox:ClearFocus()
        player2213BetEditBox:ClearFocus()  
    end
end)

-- Check if the player is in the raid party
local function isPlayerInRaidParty(playerName, raidPartyMembers)
    for _, memberName in ipairs(raidPartyMembers) do
        if playerName == memberName then
            return true
        end
    end
    return false
end




















-- Set visibility for seat 1 (raidpartymember 2)
local function isPlayer1()
    playerFrame.player1HitButton:Show()
    playerFrame.player1StandButton:Show()
    playerFrame.player1DoubleButton:Show()
    playerFrame.player1SplitButton:Show()
    playerFrame.player1InsuranceYesButton:Show()
    playerFrame.player1InsuranceNoButton:Show()
    player1ConfirmMainBetButton:Show()
    player1ConfirmPPBetButton:Show()
    player1Confirm213BetButton:Show()
    player1MainBetEditBox:Show()
    player1213BetEditBox:Show()
    player1PPBetEditBox:Show()
    playerFrame.player1MainBetTitle:Show()
    playerFrame.player1PPBetTitle:Show()
    playerFrame.player1213BetTitle:Show()
    playerFrame.player1InsuranceTitle:Show()
    playerFrame.player1InsuranceSubtitle:Show()
    bankrollFrame.player1TotalBankrollTableDisplay:Show()
    playerFrame.player1SplitH1Title:Hide()
    playerFrame.player1SplitH2Title:Hide()
    player1SplitH1EditBox:Hide()
    player1SplitH2EditBox:Hide()
    playerFrame.player1HitButtonSplitH1:Hide()
    playerFrame.player1StandButtonSplitH1:Hide()
    playerFrame.player1DoubleButtonSplitH1:Hide()
    playerFrame.player1HitButtonSplitH2:Hide()
    playerFrame.player1StandButtonSplitH2:Hide()
    playerFrame.player1DoubleButtonSplitH2:Hide()
    bankrollFrame.player2TotalBankrollTableDisplay:Hide()
    bankrollFrame.player3TotalBankrollTableDisplay:Hide()
    bankrollFrame.player4TotalBankrollTableDisplay:Hide()
    bankrollFrame.player5TotalBankrollTableDisplay:Hide()
    playerFrame.player2HitButton:Hide()
    playerFrame.player2StandButton:Hide()
    playerFrame.player2DoubleButton:Hide()
    playerFrame.player2SplitButton:Hide()
    playerFrame.player2InsuranceYesButton:Hide()
    playerFrame.player2InsuranceNoButton:Hide()
    player2ConfirmMainBetButton:Hide()
    player2ConfirmPPBetButton:Hide()
    player2Confirm213BetButton:Hide()
    player2MainBetEditBox:Hide()
    player2213BetEditBox:Hide()
    player2PPBetEditBox:Hide()
    playerFrame.mainBet2:Hide()
    playerFrame.ppBet2:Hide()
    playerFrame.t213Bet2:Hide()
    playerFrame.insuranceBet2:Hide()
    playerFrame.insuranceIfAvailable2:Hide()
    playerFrame.hitButton3:Hide()
    playerFrame.standButton3:Hide()
    playerFrame.doubleButton3:Hide()
    playerFrame.splitButton3:Hide()
    playerFrame.insuranceYesButton3:Hide()
    playerFrame.insuranceNoButton3:Hide()
    confirmBetButtonMain3:Hide()
    confirmBetButtonPP3:Hide()
    confirmBetButton2133:Hide()
    betEditBoxMain3:Hide()
    betEditBox2133:Hide()
    betEditBoxPP3:Hide()
    playerFrame.mainBet3:Hide()
    playerFrame.ppBet3:Hide()
    playerFrame.t213Bet3:Hide()
    playerFrame.insuranceBet3:Hide()
    playerFrame.insuranceIfAvailable3:Hide()
    playerFrame.hitButton4:Hide()
    playerFrame.standButton4:Hide()
    playerFrame.doubleButton4:Hide()
    playerFrame.splitButton4:Hide()
    playerFrame.insuranceYesButton4:Hide()
    playerFrame.insuranceNoButton4:Hide()
    confirmBetButtonMain4:Hide()
    confirmBetButtonPP4:Hide()
    confirmBetButton2134:Hide()
    betEditBoxMain4:Hide()
    betEditBox2134:Hide()
    betEditBoxPP4:Hide()
    playerFrame.mainBet4:Hide()
    playerFrame.ppBet4:Hide()
    playerFrame.t213Bet4:Hide()
    playerFrame.insuranceBet4:Hide()
    playerFrame.insuranceIfAvailable4:Hide()
    playerFrame.hitButton5:Hide()
    playerFrame.standButton5:Hide()
    playerFrame.doubleButton5:Hide()
    playerFrame.splitButton5:Hide()
    playerFrame.insuranceYesButton5:Hide()
    playerFrame.insuranceNoButton5:Hide()
    confirmBetButtonMain5:Hide()
    confirmBetButtonPP5:Hide()
    confirmBetButton2135:Hide()
    betEditBoxMain5:Hide()
    betEditBox2135:Hide()
    betEditBoxPP5:Hide()
    playerFrame.mainBet5:Hide()
    playerFrame.ppBet5:Hide()
    playerFrame.t213Bet5:Hide()
    playerFrame.insuranceBet5:Hide()
    playerFrame.insuranceIfAvailable5:Hide()
    print("You're in Seat 1!")
end

function isPlayer1CashDesk()
    cashDeskFrame.player1TotalBankroll:Show()
    cashDeskFrame.player2TotalBankroll:Hide()
    cashDeskFrame.player3TotalBankroll:Hide()
    cashDeskFrame.player4TotalBankroll:Hide()
    cashDeskFrame.player5TotalBankroll:Hide()
end

-- Set visibility for seat 2 (raidpartymember 3)
local function isPlayer2()
    playerFrame.player2HitButton:Show()
    playerFrame.player2StandButton:Show()
    playerFrame.player2DoubleButton:Show()
    playerFrame.player2SplitButton:Show()
    playerFrame.player2InsuranceYesButton:Show()
    playerFrame.player2InsuranceNoButton:Show()
    player2ConfirmMainBetButton:Show()
    player2ConfirmPPBetButton:Show()
    player2Confirm213BetButton:Show()
    player2MainBetEditBox:Show()
    player2213BetEditBox:Show()
    player2PPBetEditBox:Show()
    playerFrame.mainBet2:Show()
    playerFrame.ppBet2:Show()
    playerFrame.t213Bet2:Show()
    playerFrame.insuranceBet2:Show()
    playerFrame.insuranceIfAvailable2:Show()
    bankrollFrame.player1TotalBankrollTableDisplay:Hide()
    bankrollFrame.player2TotalBankrollTableDisplay:Show()
    bankrollFrame.player3TotalBankrollTableDisplay:Hide()
    bankrollFrame.player4TotalBankrollTableDisplay:Hide()
    bankrollFrame.player5TotalBankrollTableDisplay:Hide()
    playerFrame.player1HitButton:Hide()
    playerFrame.player1StandButton:Hide()
    playerFrame.player1DoubleButton:Hide()
    playerFrame.player1SplitButton:Hide()
    playerFrame.player1InsuranceYesButton:Hide()
    playerFrame.player1InsuranceNoButton:Hide()
    player1ConfirmMainBetButton:Hide()
    player1ConfirmPPBetButton:Hide()
    player1Confirm213BetButton:Hide()
    player1MainBetEditBox:Hide()
    player1213BetEditBox:Hide()
    player1PPBetEditBox:Hide()
    playerFrame.player1MainBetTitle:Hide()
    playerFrame.player1PPBetTitle:Hide()
    playerFrame.player1213BetTitle:Hide()
    playerFrame.player1InsuranceTitle:Hide()
    playerFrame.player1InsuranceSubtitle:Hide()
    playerFrame.hitButton3:Hide()
    playerFrame.standButton3:Hide()
    playerFrame.doubleButton3:Hide()
    playerFrame.splitButton3:Hide()
    playerFrame.insuranceYesButton3:Hide()
    playerFrame.insuranceNoButton3:Hide()
    confirmBetButtonMain3:Hide()
    confirmBetButtonPP3:Hide()
    confirmBetButton2133:Hide()
    betEditBoxMain3:Hide()
    betEditBox2133:Hide()
    betEditBoxPP3:Hide()
    playerFrame.mainBet3:Hide()
    playerFrame.ppBet3:Hide()
    playerFrame.t213Bet3:Hide()
    playerFrame.insuranceBet3:Hide()
    playerFrame.insuranceIfAvailable3:Hide()
    playerFrame.hitButton4:Hide()
    playerFrame.standButton4:Hide()
    playerFrame.doubleButton4:Hide()
    playerFrame.splitButton4:Hide()
    playerFrame.insuranceYesButton4:Hide()
    playerFrame.insuranceNoButton4:Hide()
    confirmBetButtonMain4:Hide()
    confirmBetButtonPP4:Hide()
    confirmBetButton2134:Hide()
    betEditBoxMain4:Hide()
    betEditBox2134:Hide()
    betEditBoxPP4:Hide()
    playerFrame.mainBet4:Hide()
    playerFrame.ppBet4:Hide()
    playerFrame.t213Bet4:Hide()
    playerFrame.insuranceBet4:Hide()
    playerFrame.insuranceIfAvailable4:Hide()
    playerFrame.hitButton5:Hide()
    playerFrame.standButton5:Hide()
    playerFrame.doubleButton5:Hide()
    playerFrame.splitButton5:Hide()
    playerFrame.insuranceYesButton5:Hide()
    playerFrame.insuranceNoButton5:Hide()
    confirmBetButtonMain5:Hide()
    confirmBetButtonPP5:Hide()
    confirmBetButton2135:Hide()
    betEditBoxMain5:Hide()
    betEditBox2135:Hide()
    betEditBoxPP5:Hide()
    playerFrame.mainBet5:Hide()
    playerFrame.ppBet5:Hide()
    playerFrame.t213Bet5:Hide()
    playerFrame.insuranceBet5:Hide()
    playerFrame.insuranceIfAvailable5:Hide()
    print("You're in Seat 2!")
end

function isPlayer2CashDesk()
    cashDeskFrame.player1TotalBankroll:Hide()
    cashDeskFrame.player2TotalBankroll:Show()
    cashDeskFrame.player3TotalBankroll:Hide()
    cashDeskFrame.player4TotalBankroll:Hide()
    cashDeskFrame.player5TotalBankroll:Hide()
end

-- Set visibility for seat 3 (raidpartymember 4)
local function isPlayer3()
    playerFrame.hitButton3:Show()
    playerFrame.standButton3:Show()
    playerFrame.doubleButton3:Show()
    playerFrame.splitButton3:Show()
    playerFrame.insuranceYesButton3:Show()
    playerFrame.insuranceNoButton3:Show()
    confirmBetButtonMain3:Show()
    confirmBetButtonPP3:Show()
    confirmBetButton2133:Show()
    betEditBoxMain3:Show()
    betEditBox2133:Show()
    betEditBoxPP3:Show()
    playerFrame.mainBet3:Show()
    playerFrame.ppBet3:Show()
    playerFrame.t213Bet3:Show()
    playerFrame.insuranceBet3:Show()
    playerFrame.insuranceIfAvailable3:Show()
    bankrollFrame.player1TotalBankrollTableDisplay:Hide()
    bankrollFrame.player2TotalBankrollTableDisplay:Hide()
    bankrollFrame.player3TotalBankrollTableDisplay:Show()
    bankrollFrame.player4TotalBankrollTableDisplay:Hide()
    bankrollFrame.player5TotalBankrollTableDisplay:Hide()
    playerFrame.player1HitButton:Hide()
    playerFrame.player1StandButton:Hide()
    playerFrame.player1DoubleButton:Hide()
    playerFrame.player1SplitButton:Hide()
    playerFrame.player1InsuranceYesButton:Hide()
    playerFrame.player1InsuranceNoButton:Hide()
    player1ConfirmMainBetButton:Hide()
    player1ConfirmPPBetButton:Hide()
    player1Confirm213BetButton:Hide()
    player1MainBetEditBox:Hide()
    player1213BetEditBox:Hide()
    player1PPBetEditBox:Hide()
    playerFrame.player1MainBetTitle:Hide()
    playerFrame.player1PPBetTitle:Hide()
    playerFrame.player1213BetTitle:Hide()
    playerFrame.player1InsuranceTitle:Hide()
    playerFrame.player1InsuranceSubtitle:Hide()
    playerFrame.player2HitButton:Hide()
    playerFrame.player2StandButton:Hide()
    playerFrame.player2DoubleButton:Hide()
    playerFrame.player2SplitButton:Hide()
    playerFrame.player2InsuranceYesButton:Hide()
    playerFrame.player2InsuranceNoButton:Hide()
    player2ConfirmMainBetButton:Hide()
    player2ConfirmPPBetButton:Hide()
    player2Confirm213BetButton:Hide()
    player2MainBetEditBox:Hide()
    player2213BetEditBox:Hide()
    player2PPBetEditBox:Hide()
    playerFrame.mainBet2:Hide()
    playerFrame.ppBet2:Hide()
    playerFrame.t213Bet2:Hide()
    playerFrame.insuranceBet2:Hide()
    playerFrame.insuranceIfAvailable2:Hide()
    playerFrame.hitButton4:Hide()
    playerFrame.standButton4:Hide()
    playerFrame.doubleButton4:Hide()
    playerFrame.splitButton4:Hide()
    playerFrame.insuranceYesButton4:Hide()
    playerFrame.insuranceNoButton4:Hide()
    confirmBetButtonMain4:Hide()
    confirmBetButtonPP4:Hide()
    confirmBetButton2134:Hide()
    betEditBoxMain4:Hide()
    betEditBox2134:Hide()
    betEditBoxPP4:Hide()
    playerFrame.mainBet4:Hide()
    playerFrame.ppBet4:Hide()
    playerFrame.t213Bet4:Hide()
    playerFrame.insuranceBet4:Hide()
    playerFrame.insuranceIfAvailable4:Hide()
    playerFrame.hitButton5:Hide()
    playerFrame.standButton5:Hide()
    playerFrame.doubleButton5:Hide()
    playerFrame.splitButton5:Hide()
    playerFrame.insuranceYesButton5:Hide()
    playerFrame.insuranceNoButton5:Hide()
    confirmBetButtonMain5:Hide()
    confirmBetButtonPP5:Hide()
    confirmBetButton2135:Hide()
    betEditBoxMain5:Hide()
    betEditBox2135:Hide()
    betEditBoxPP5:Hide()
    playerFrame.mainBet5:Hide()
    playerFrame.ppBet5:Hide()
    playerFrame.t213Bet5:Hide()
    playerFrame.insuranceBet5:Hide()
    playerFrame.insuranceIfAvailable5:Hide()
    print("You're in Seat 3!")
end

function isPlayer3CashDesk()
    cashDeskFrame.player1TotalBankroll:Hide()
    cashDeskFrame.player2TotalBankroll:Hide()
    cashDeskFrame.player3TotalBankroll:Show()
    cashDeskFrame.player4TotalBankroll:Hide()
    cashDeskFrame.player5TotalBankroll:Hide()
end

-- Set visibility for seat 4 (raidpartymember 5)
local function isPlayer4()
    playerFrame.hitButton4:Show()
    playerFrame.standButton4:Show()
    playerFrame.doubleButton4:Show()
    playerFrame.splitButton4:Show()
    playerFrame.insuranceYesButton4:Show()
    playerFrame.insuranceNoButton4:Show()
    confirmBetButtonMain4:Show()
    confirmBetButtonPP4:Show()
    confirmBetButton2134:Show()
    betEditBoxMain4:Show()
    betEditBox2134:Show()
    betEditBoxPP4:Show()
    playerFrame.mainBet4:Show()
    playerFrame.ppBet4:Show()
    playerFrame.t213Bet4:Show()
    playerFrame.insuranceBet4:Show()
    playerFrame.insuranceIfAvailable4:Show()
    bankrollFrame.player1TotalBankrollTableDisplay:Hide()
    bankrollFrame.player2TotalBankrollTableDisplay:Hide()
    bankrollFrame.player3TotalBankrollTableDisplay:Hide()
    bankrollFrame.player4TotalBankrollTableDisplay:Show()
    bankrollFrame.player5TotalBankrollTableDisplay:Hide()
    playerFrame.player1HitButton:Hide()
    playerFrame.player1StandButton:Hide()
    playerFrame.player1DoubleButton:Hide()
    playerFrame.player1SplitButton:Hide()
    playerFrame.player1InsuranceYesButton:Hide()
    playerFrame.player1InsuranceNoButton:Hide()
    player1ConfirmMainBetButton:Hide()
    player1ConfirmPPBetButton:Hide()
    player1Confirm213BetButton:Hide()
    player1MainBetEditBox:Hide()
    player1213BetEditBox:Hide()
    player1PPBetEditBox:Hide()
    playerFrame.player1MainBetTitle:Hide()
    playerFrame.player1PPBetTitle:Hide()
    playerFrame.player1213BetTitle:Hide()
    playerFrame.player1InsuranceTitle:Hide()
    playerFrame.player1InsuranceSubtitle:Hide()
    playerFrame.player2HitButton:Hide()
    playerFrame.player2StandButton:Hide()
    playerFrame.player2DoubleButton:Hide()
    playerFrame.player2SplitButton:Hide()
    playerFrame.player2InsuranceYesButton:Hide()
    playerFrame.player2InsuranceNoButton:Hide()
    player2ConfirmMainBetButton:Hide()
    player2ConfirmPPBetButton:Hide()
    player2Confirm213BetButton:Hide()
    player2MainBetEditBox:Hide()
    player2213BetEditBox:Hide()
    player2PPBetEditBox:Hide()
    playerFrame.mainBet2:Hide()
    playerFrame.ppBet2:Hide()
    playerFrame.t213Bet2:Hide()
    playerFrame.insuranceBet2:Hide()
    playerFrame.insuranceIfAvailable2:Hide()
    playerFrame.hitButton3:Hide()
    playerFrame.standButton3:Hide()
    playerFrame.doubleButton3:Hide()
    playerFrame.splitButton3:Hide()
    playerFrame.insuranceYesButton3:Hide()
    playerFrame.insuranceNoButton3:Hide()
    confirmBetButtonMain3:Hide()
    confirmBetButtonPP3:Hide()
    confirmBetButton2133:Hide()
    betEditBoxMain3:Hide()
    betEditBox2133:Hide()
    betEditBoxPP3:Hide()
    playerFrame.mainBet3:Hide()
    playerFrame.ppBet3:Hide()
    playerFrame.t213Bet3:Hide()
    playerFrame.insuranceBet3:Hide()
    playerFrame.insuranceIfAvailable3:Hide()
    playerFrame.hitButton5:Hide()
    playerFrame.standButton5:Hide()
    playerFrame.doubleButton5:Hide()
    playerFrame.splitButton5:Hide()
    playerFrame.insuranceYesButton5:Hide()
    playerFrame.insuranceNoButton5:Hide()
    confirmBetButtonMain5:Hide()
    confirmBetButtonPP5:Hide()
    confirmBetButton2135:Hide()
    betEditBoxMain5:Hide()
    betEditBox2135:Hide()
    betEditBoxPP5:Hide()
    playerFrame.mainBet5:Hide()
    playerFrame.ppBet5:Hide()
    playerFrame.t213Bet5:Hide()
    playerFrame.insuranceBet5:Hide()
    playerFrame.insuranceIfAvailable5:Hide()
    print("You're in Seat 4!")
end

function isPlayer4CashDesk()
    cashDeskFrame.player1TotalBankroll:Hide()
    cashDeskFrame.player2TotalBankroll:Hide()
    cashDeskFrame.player3TotalBankroll:Hide()
    cashDeskFrame.player4TotalBankroll:Show()
    cashDeskFrame.player5TotalBankroll:Hide()
end

-- Set visibility for seat 5 (raidpartymember 6)
local function isPlayer5()
    playerFrame.hitButton5:Show()
    playerFrame.standButton5:Show()
    playerFrame.doubleButton5:Show()
    playerFrame.splitButton5:Show()
    playerFrame.insuranceYesButton5:Show()
    playerFrame.insuranceNoButton5:Show()
    confirmBetButtonMain5:Show()
    confirmBetButtonPP5:Show()
    confirmBetButton2135:Show()
    betEditBoxMain5:Show()
    betEditBox2135:Show()
    betEditBoxPP5:Show()
    playerFrame.mainBet5:Show()
    playerFrame.ppBet5:Show()
    playerFrame.t213Bet5:Show()
    playerFrame.insuranceBet5:Show()
    playerFrame.insuranceIfAvailable5:Show()
    bankrollFrame.player1TotalBankrollTableDisplay:Hide()
    bankrollFrame.player2TotalBankrollTableDisplay:Hide()
    bankrollFrame.player3TotalBankrollTableDisplay:Hide()
    bankrollFrame.player4TotalBankrollTableDisplay:Hide()
    bankrollFrame.player5TotalBankrollTableDisplay:Show()
    playerFrame.player1HitButton:Hide()
    playerFrame.player1StandButton:Hide()
    playerFrame.player1DoubleButton:Hide()
    playerFrame.player1SplitButton:Hide()
    playerFrame.player1InsuranceYesButton:Hide()
    playerFrame.player1InsuranceNoButton:Hide()
    player1ConfirmMainBetButton:Hide()
    player1ConfirmPPBetButton:Hide()
    player1Confirm213BetButton:Hide()
    player1MainBetEditBox:Hide()
    player1213BetEditBox:Hide()
    player1PPBetEditBox:Hide()
    playerFrame.player1MainBetTitle:Hide()
    playerFrame.player1PPBetTitle:Hide()
    playerFrame.player1213BetTitle:Hide()
    playerFrame.player1InsuranceTitle:Hide()
    playerFrame.player1InsuranceSubtitle:Hide()
    playerFrame.player2HitButton:Hide()
    playerFrame.player2StandButton:Hide()
    playerFrame.player2DoubleButton:Hide()
    playerFrame.player2SplitButton:Hide()
    playerFrame.player2InsuranceYesButton:Hide()
    playerFrame.player2InsuranceNoButton:Hide()
    player2ConfirmMainBetButton:Hide()
    player2ConfirmPPBetButton:Hide()
    player2Confirm213BetButton:Hide()
    player2MainBetEditBox:Hide()
    player2213BetEditBox:Hide()
    player2PPBetEditBox:Hide()
    playerFrame.mainBet2:Hide()
    playerFrame.ppBet2:Hide()
    playerFrame.t213Bet2:Hide()
    playerFrame.insuranceBet2:Hide()
    playerFrame.insuranceIfAvailable2:Hide()
    playerFrame.hitButton3:Hide()
    playerFrame.standButton3:Hide()
    playerFrame.doubleButton3:Hide()
    playerFrame.splitButton3:Hide()
    playerFrame.insuranceYesButton3:Hide()
    playerFrame.insuranceNoButton3:Hide()
    confirmBetButtonMain3:Hide()
    confirmBetButtonPP3:Hide()
    confirmBetButton2133:Hide()
    betEditBoxMain3:Hide()
    betEditBox2133:Hide()
    betEditBoxPP3:Hide()
    playerFrame.mainBet3:Hide()
    playerFrame.ppBet3:Hide()
    playerFrame.t213Bet3:Hide()
    playerFrame.insuranceBet3:Hide()
    playerFrame.insuranceIfAvailable3:Hide()
    playerFrame.hitButton4:Hide()
    playerFrame.standButton4:Hide()
    playerFrame.doubleButton4:Hide()
    playerFrame.splitButton4:Hide()
    playerFrame.insuranceYesButton4:Hide()
    playerFrame.insuranceNoButton4:Hide()
    confirmBetButtonMain4:Hide()
    confirmBetButtonPP4:Hide()
    confirmBetButton2134:Hide()
    betEditBoxMain4:Hide()
    betEditBox2134:Hide()
    betEditBoxPP4:Hide()
    playerFrame.mainBet4:Hide()
    playerFrame.ppBet4:Hide()
    playerFrame.t213Bet4:Hide()
    playerFrame.insuranceBet4:Hide()
    playerFrame.insuranceIfAvailable4:Hide()
    print("You're in Seat 5!")
end

function isPlayer5CashDesk()
    cashDeskFrame.player1TotalBankroll:Hide()
    cashDeskFrame.player2TotalBankroll:Hide()
    cashDeskFrame.player3TotalBankroll:Hide()
    cashDeskFrame.player4TotalBankroll:Hide()
    cashDeskFrame.player5TotalBankroll:Show()
end

-- Update player names in the playerFrame
playerFrame.player1Name:SetText(unitName1);
playerFrame.player2Name:SetText(unitName2);
playerFrame.player3Name:SetText(unitName3);
playerFrame.player4Name:SetText(unitName4);
playerFrame.player5Name:SetText(unitName5);

























local function UpdateTimerDisplay1(secondsRemaining)
    playerFrame.timerText1:SetText("Timer: " .. secondsRemaining .. " s remaining")
end

local function OnTimerUpdate1()
    countdownDuration = countdownDuration - 1

    if countdownDuration <= 0 then
        playerFrame.player1HitButton:Disable()
        playerFrame.player1StandButton:Disable()
        playerFrame.player1DoubleButton:Disable()
        if Player1Active == true and Player2Active == false and Player3Active == false and Player4Active == false and Player5Active == false then       -- Players: 1
            turn = 9
        elseif Player1Active == true and Player2Active == true and Player3Active == false and Player4Active == false and Player5Active == false then    -- Players: 1 2
            turn = 11
        elseif Player1Active == true and Player2Active == false and Player3Active == true and Player4Active == false and Player5Active == false then    -- Players: 1 3
            turn = 11
        elseif Player1Active == true and Player2Active == false and Player3Active == false and Player4Active == true and Player5Active == false then    -- Players: 1 4
            turn = 11
        elseif Player1Active == true and Player2Active == false and Player3Active == false and Player4Active == false and Player5Active == true then    -- Players: 1 5
            turn = 11
        elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == false and Player5Active == false then    -- Players: 1 2 3
            turn = 13
        elseif Player1Active == true and Player2Active == true and Player3Active == false and Player4Active == true and Player5Active == false then    -- Players: 1 2 4
            turn = 13
        elseif Player1Active == true and Player2Active == true and Player3Active == false and Player4Active == false and Player5Active == true then    -- Players: 1 2 5
            turn = 13
        elseif Player1Active == true and Player2Active == false and Player3Active == true and Player4Active == true and Player5Active == false then    -- Players: 1 3 4
            turn = 13
        elseif Player1Active == true and Player2Active == false and Player3Active == true and Player4Active == false and Player5Active == true then    -- Players: 1 3 5
            turn = 13
        elseif Player1Active == true and Player2Active == false and Player3Active == false and Player4Active == true and Player5Active == true then    -- Players: 1 4 5
            turn = 13
        elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == false then    -- Players: 1 2 3 4
            turn = 15
        elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == false and Player5Active == true then    -- Players: 1 2 3 5
            turn = 15
        elseif Player1Active == true and Player2Active == true and Player3Active == false and Player4Active == true and Player5Active == true then    -- Players: 1 2 4 5
            turn = 15
        elseif Player1Active == true and Player2Active == false and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 1 3 4 5
            turn = 15
        elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 1 2 3 4 5
            turn = 17
        end
        countdownTimer1:Cancel()
        playerFrame.timerText1:SetText("Time is up!")
        playerFrame.timerText1:SetTextColor(1, 0, 0)

        if playerName == unitName1 then
            SendChatMessage("[P1] Stand", "RAID")
        end
    else
        UpdateTimerDisplay1(countdownDuration)
    end
end

local function StartCountdownTimer1()
    if countdownTimer1 then
        countdownTimer1:Cancel()
    end
    countdownTimer1 = C_Timer.NewTicker(1, OnTimerUpdate1, countdownDuration)
    playerFrame.timerText1:SetPoint("TOP", playerFrame, 0, -90)
    playerFrame.timerText1:SetJustifyH("CENTER")
    playerFrame.timerText1:Show()
    playerFrame.timerText1:SetTextColor(1, 1, 1)
end

local function UpdateTimerDisplay2(secondsRemaining)
    playerFrame.timerText2:SetText("Timer: " .. secondsRemaining .. " s remaining")
end

local function OnTimerUpdate2()
    countdownDuration = countdownDuration - 1

    if countdownDuration <= 0 then
        playerFrame.player2HitButton:Disable()
        playerFrame.player2StandButton:Disable()
        playerFrame.player2DoubleButton:Disable()
        if Player1Active == false and Player2Active == true and Player3Active == false and Player4Active == false and Player5Active == false then       -- Players: 2
            turn = 9
        elseif Player1Active == true and Player2Active == true and Player3Active == false and Player4Active == false and Player5Active == false then    -- Players: 1 2
            turn = 17
        elseif Player1Active == false and Player2Active == true and Player3Active == true and Player4Active == false and Player5Active == false then    -- Players: 2 3
            turn = 11
        elseif Player1Active == false and Player2Active == true and Player3Active == false and Player4Active == true and Player5Active == false then    -- Players: 2 4
            turn = 11
        elseif Player1Active == false and Player2Active == true and Player3Active == false and Player4Active == false and Player5Active == true then    -- Players: 2 5
            turn = 11
        elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == false and Player5Active == false then    -- Players: 1 2 3
            turn = 19
        elseif Player1Active == true and Player2Active == true and Player3Active == false and Player4Active == true and Player5Active == false then    -- Players: 1 2 4
            turn = 19
        elseif Player1Active == true and Player2Active == true and Player3Active == false and Player4Active == false and Player5Active == true then    -- Players: 1 2 5
            turn = 19
        elseif Player1Active == false and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == false then    -- Players: 2 3 4
            turn = 13
        elseif Player1Active == false and Player2Active == true and Player3Active == true and Player4Active == false and Player5Active == true then    -- Players: 2 3 5
            turn = 13
        elseif Player1Active == false and Player2Active == true and Player3Active == false and Player4Active == true and Player5Active == true then    -- Players: 2 4 5
            turn = 13
        elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == false then    -- Players: 1 2 3 4
            turn = 21
        elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == false and Player5Active == true then    -- Players: 1 2 3 5
            turn = 21
        elseif Player1Active == true and Player2Active == true and Player3Active == false and Player4Active == true and Player5Active == true then    -- Players: 1 2 4 5
            turn = 15
        elseif Player1Active == false and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 2 3 4 5
            turn = 15
        elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 1 2 3 4 5
            turn = 23
        end
        countdownTimer2:Cancel()
        playerFrame.timerText2:SetPoint("TOPRIGHT", playerFrame, "TOPRIGHT", -280, -150)
        playerFrame.timerText2:SetText("Time is up!")
        playerFrame.timerText2:SetJustifyH("CENTER")
        playerFrame.timerText2:SetTextColor(1, 0, 0)
    else
        UpdateTimerDisplay2(countdownDuration)
    end
end

local function StartCountdownTimer2()
    if countdownTimer2 then
        countdownTimer2:Cancel()
    end
    countdownTimer2 = C_Timer.NewTicker(1, OnTimerUpdate2, countdownDuration)
    playerFrame.timerText2:SetPoint("TOPRIGHT", playerFrame, "TOPRIGHT", -230, -150)
    playerFrame.timerText2:Show()
    playerFrame.timerText2:SetTextColor(1, 1, 1)
end

local function UpdateTimerDisplayBets(secondsRemaining)
    playerFrame.timerTextBets:SetText("Place your bets!\nTimer: " .. secondsRemaining .. " s remaining")
end

local function OnTimerUpdateBets()
    countdownDuration = countdownDuration - 1

    if countdownDuration <= 0 then
        player1ConfirmMainBetButton:Disable()
        player1ConfirmPPBetButton:Disable()
        player1Confirm213BetButton:Disable()
        player2ConfirmMainBetButton:Disable()
        player2ConfirmPPBetButton:Disable()
        player2Confirm213BetButton:Disable()
        confirmBetButtonMain3:Disable()
        confirmBetButtonPP3:Disable()
        confirmBetButton2133:Disable()
        confirmBetButtonMain4:Disable()
        confirmBetButtonPP4:Disable()
        confirmBetButton2134:Disable()
        confirmBetButtonMain5:Disable()
        confirmBetButtonPP5:Disable()
        confirmBetButton2135:Disable()
        countdownTimerBets:Cancel()
        playerFrame.timerTextBets:SetText("No more bets!")
        playerFrame.timerTextBets:SetJustifyH("CENTER")
        playerFrame.timerTextBets:SetTextColor(1, 1, 0)
    else
        UpdateTimerDisplayBets(countdownDuration)
    end
end

local function StartCountdownTimerBets()
    if countdownTimerBets then
        countdownTimerBets:Cancel()
    end
    countdownTimerBets = C_Timer.NewTicker(1, OnTimerUpdateBets, countdownDuration)
    playerFrame.timerTextBets:SetPoint("TOPRIGHT", playerFrame, "TOPRIGHT", -230, -150)
    playerFrame.timerTextBets:Show()
    playerFrame.timerTextBets:SetTextColor(1, 1, 1)
end



















local function player1Turn()
    playerFrame.player1HitButton:Enable()
    playerFrame.player1StandButton:Enable()
    if player1DoubleToggle == false then
        playerFrame.player1DoubleButton:Enable()
    else
        playerFrame.player1DoubleButton:Disable()
    end
end

local function player1SplitHand1Turn()
    playerFrame.player1HitButtonSplitH1:Enable()
    playerFrame.player1StandButtonSplitH1:Enable()
    if player1DoubleHand1Toggle == false then
        playerFrame.player1DoubleButtonSplitH1:Enable()
    else
        playerFrame.player1DoubleButtonSplitH1:Disable()
    end
end

local function player1SplitHand2Turn()
    playerFrame.player1HitButtonSplitH2:Enable()
    playerFrame.player1StandButtonSplitH2:Enable()
    if player1DoubleHand2Toggle == false then
        playerFrame.player1DoubleButtonSplitH2:Enable()
    else
        playerFrame.player1DoubleButtonSplitH2:Disable()
    end
end

local function playerTurn2()
    playerFrame.player2HitButton:Enable()
    playerFrame.player2StandButton:Enable()
    if double2Flag == false then
        playerFrame.player2DoubleButton:Enable()
    else
        playerFrame.player2DoubleButton:Disable()
    end
end

local function playerTurn3()
    playerFrame.hitButton3:Enable()
    playerFrame.standButton3:Enable()
    playerFrame.doubleButton3:Enable()
end

local function playerTurn4()
    playerFrame.hitButton4:Enable()
    playerFrame.standButton4:Enable()
    playerFrame.doubleButton4:Enable()
end

local function playerTurn5()
    playerFrame.hitButton5:Enable()
    playerFrame.standButton5:Enable()
    playerFrame.doubleButton5:Enable()
end




















-- Function to add a drawn card to the player's cards and display it
local function P12345(cardName)
    if cardName and cardNames[cardName] then
        local cardTexture = playerFrame:CreateTexture(nil, "OVERLAY")
        cardTexture:SetSize(32, 64)
        table.insert(drawnCards, cardTexture)  -- Store the texture in the table

        -- Position the card based on the turn count
        if turn == 0 then 
            cardTexture:SetPoint("BOTTOM", playerFrame, 296, 428)       -- Player 1: 1
        elseif turn == 1 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 165, 337)       -- Player 2: 1
        elseif turn == 2 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 300)         -- Player 3: 1
        elseif turn == 3 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -160, 337)      -- Player 4: 1
        elseif turn == 4 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -285, 429)      -- Player 5: 1
        elseif turn == 5 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 0, 525)         -- Dealer: 1
        elseif turn == 6 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 286, 438)       -- Player 1: 2
        elseif turn == 7 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 155, 347)       -- Player 2: 2
        elseif turn == 8 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 315)         -- Player 3: 2
        elseif turn == 9 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -150, 347)      -- Player 4: 2
        elseif turn == 10 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -275, 439)      -- Player 5: 2
        elseif turn == 11 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 276, 448)       -- Player 1: 3
        elseif turn == 12 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 266, 458)       -- Player 1: 4
        elseif turn == 13 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 256, 468)       -- Player 1: 5
        elseif turn == 14 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 246, 478)       -- Player 1: 6
        elseif turn == 15 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 236, 488)       -- Player 1: 7
        elseif turn == 16 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 276, 448)       -- Player 1: Double
        elseif turn == 17 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 145, 357)       -- Player 2: 3
        elseif turn == 18 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 135, 367)       -- Player 2: 4
        elseif turn == 19 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 125, 377)       -- Player 2: 5
        elseif turn == 20 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 115, 387)       -- Player 2: 6
        elseif turn == 21 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 105, 397)       -- Player 2: 7
        elseif turn == 22 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 145, 357)       -- Player 2: Double
        elseif turn == 23 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 330)         -- Player 3: 3
        elseif turn == 24 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 345)         -- Player 3: 4
        elseif turn == 25 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 360)         -- Player 3: 5
        elseif turn == 26 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 375)         -- Player 3: 6
        elseif turn == 27 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 390)         -- Player 3: 7
        elseif turn == 28 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 330)         -- Player 3: Double
        elseif turn == 29 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -140, 357)      -- Player 4: 3
        elseif turn == 30 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -130, 367)      -- Player 4: 4
        elseif turn == 31 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -120, 377)      -- Player 4: 5
        elseif turn == 32 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -110, 387)      -- Player 4: 6
        elseif turn == 33 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -100, 397)      -- Player 4: 7
        elseif turn == 34 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -140, 357)      -- Player 4: Double
        elseif turn == 35 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -265, 449)      -- Player 5: 3
        elseif turn == 36 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -255, 459)      -- Player 5: 4
        elseif turn == 37 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -245, 469)      -- Player 5: 5
        elseif turn == 38 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -235, 479)      -- Player 5: 6
        elseif turn == 39 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -225, 489)      -- Player 5: 7
        elseif turn == 40 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -265, 449)      -- Player 5: Double
        elseif turn == 41 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 12, 525)        -- Dealer: 2
        elseif turn == 42 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 24, 525)        -- Dealer: 3
        elseif turn == 43 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 36, 525)        -- Dealer: 4
        elseif turn == 44 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 48, 525)        -- Dealer: 5
        elseif turn == 45 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 60, 525)        -- Dealer: 6
        elseif turn == 46 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 72, 525)        -- Dealer: 7
        end


        cardTexture:SetTexture("Interface\\AddOns\\BJPlayer\\Images\\" .. cardName)
        cardTexture:SetDrawLayer("OVERLAY")

        -- Increment the turn counter
        turn = turn + 1
    end
end

-- Function to add a drawn card to the player's cards and display it
local function P2345(cardName)
    if cardName and cardNames[cardName] then
        local cardTexture = playerFrame:CreateTexture(nil, "OVERLAY")
        cardTexture:SetSize(32, 64)
        table.insert(drawnCards, cardTexture)  -- Store the texture in the table

        -- Position the card based on the turn count
        if turn == 0 then 
            cardTexture:SetPoint("BOTTOM", playerFrame, 165, 337)       -- Player 2: 1
        elseif turn == 1 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 300)         -- Player 3: 1
        elseif turn == 2 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -160, 337)      -- Player 4: 1
        elseif turn == 3 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -285, 429)      -- Player 5: 1
        elseif turn == 4 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 0, 525)         -- Dealer: 1
        elseif turn == 5 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 155, 347)       -- Player 2: 2
        elseif turn == 6 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 315)         -- Player 3: 2
        elseif turn == 7 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -150, 347)      -- Player 4: 2
        elseif turn == 8 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -275, 439)      -- Player 5: 2
        elseif turn == 9 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 145, 357)       -- Player 2: 3
        elseif turn == 10 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 135, 367)       -- Player 2: 4
        elseif turn == 11 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 125, 377)       -- Player 2: 5
        elseif turn == 12 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 115, 387)       -- Player 2: 6
        elseif turn == 13 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 105, 397)       -- Player 2: 7
        elseif turn == 14 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 145, 357)       -- Player 2: Double
        elseif turn == 15 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 330)         -- Player 3: 3
        elseif turn == 16 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 345)         -- Player 3: 4
        elseif turn == 17 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 360)         -- Player 3: 5
        elseif turn == 18 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 375)         -- Player 3: 6
        elseif turn == 19 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 390)         -- Player 3: 7
        elseif turn == 20 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 330)         -- Player 3: Double
        elseif turn == 21 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -140, 357)      -- Player 4: 3
        elseif turn == 22 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -130, 367)      -- Player 4: 4
        elseif turn == 23 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -120, 377)      -- Player 4: 5
        elseif turn == 24 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -110, 387)      -- Player 4: 6
        elseif turn == 25 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -100, 397)      -- Player 4: 7
        elseif turn == 26 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -140, 357)      -- Player 4: Double
        elseif turn == 27 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -265, 449)      -- Player 5: 3
        elseif turn == 28 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -255, 459)      -- Player 5: 4
        elseif turn == 29 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -245, 469)      -- Player 5: 5
        elseif turn == 30 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -235, 479)      -- Player 5: 6
        elseif turn == 31 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -225, 489)      -- Player 5: 7
        elseif turn == 32 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -265, 449)      -- Player 5: Double
        elseif turn == 33 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 12, 525)        -- Dealer: 2
        elseif turn == 34 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 24, 525)        -- Dealer: 3
        elseif turn == 35 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 36, 525)        -- Dealer: 4
        elseif turn == 36 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 48, 525)        -- Dealer: 5
        elseif turn == 37 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 60, 525)        -- Dealer: 6
        elseif turn == 38 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 72, 525)        -- Dealer: 7
        end


        cardTexture:SetTexture("Interface\\AddOns\\BJPlayer\\Images\\" .. cardName)
        cardTexture:SetDrawLayer("OVERLAY")

        -- Increment the turn counter
        turn = turn + 1
    end
end

-- Function to add a drawn card to the player's cards and display it
local function P1345(cardName)
    if cardName and cardNames[cardName] then
        local cardTexture = playerFrame:CreateTexture(nil, "OVERLAY")
        cardTexture:SetSize(32, 64)
        table.insert(drawnCards, cardTexture)  -- Store the texture in the table

        -- Position the card based on the turn count
        if turn == 0 then 
            cardTexture:SetPoint("BOTTOM", playerFrame, 296, 428)       -- Player 1: 1
        elseif turn == 1 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 300)         -- Player 3: 1
        elseif turn == 2 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -160, 337)      -- Player 4: 1
        elseif turn == 3 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -285, 429)      -- Player 5: 1
        elseif turn == 4 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 0, 525)         -- Dealer: 1
        elseif turn == 5 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 286, 438)       -- Player 1: 2
        elseif turn == 6 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 315)         -- Player 3: 2
        elseif turn == 7 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -150, 347)      -- Player 4: 2
        elseif turn == 8 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -275, 439)      -- Player 5: 2
        elseif turn == 9 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 276, 448)       -- Player 1: 3
        elseif turn == 10 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 266, 458)       -- Player 1: 4
        elseif turn == 11 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 256, 468)       -- Player 1: 5
        elseif turn == 12 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 246, 478)       -- Player 1: 6
        elseif turn == 13 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 236, 488)       -- Player 1: 7
        elseif turn == 14 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 276, 448)       -- Player 1: Double
        elseif turn == 15 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 330)         -- Player 3: 3
        elseif turn == 16 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 345)         -- Player 3: 4
        elseif turn == 17 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 360)         -- Player 3: 5
        elseif turn == 18 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 375)         -- Player 3: 6
        elseif turn == 19 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 390)         -- Player 3: 7
        elseif turn == 20 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 330)         -- Player 3: Double
        elseif turn == 21 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -140, 357)      -- Player 4: 3
        elseif turn == 22 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -130, 367)      -- Player 4: 4
        elseif turn == 23 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -120, 377)      -- Player 4: 5
        elseif turn == 24 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -110, 387)      -- Player 4: 6
        elseif turn == 25 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -100, 397)      -- Player 4: 7
        elseif turn == 26 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -140, 357)      -- Player 4: Double
        elseif turn == 27 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -265, 449)      -- Player 5: 3
        elseif turn == 28 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -255, 459)      -- Player 5: 4
        elseif turn == 29 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -245, 469)      -- Player 5: 5
        elseif turn == 30 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -235, 479)      -- Player 5: 6
        elseif turn == 31 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -225, 489)      -- Player 5: 7
        elseif turn == 32 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -265, 449)      -- Player 5: Double
        elseif turn == 33 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 12, 525)        -- Dealer: 2
        elseif turn == 34 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 24, 525)        -- Dealer: 3
        elseif turn == 35 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 36, 525)        -- Dealer: 4
        elseif turn == 36 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 48, 525)        -- Dealer: 5
        elseif turn == 37 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 60, 525)        -- Dealer: 6
        elseif turn == 38 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 72, 525)        -- Dealer: 7
        end


        cardTexture:SetTexture("Interface\\AddOns\\BJPlayer\\Images\\" .. cardName)
        cardTexture:SetDrawLayer("OVERLAY")

        -- Increment the turn counter
        turn = turn + 1
    end
end

-- Function to add a drawn card to the player's cards and display it
local function P1245(cardName)
    if cardName and cardNames[cardName] then
        local cardTexture = playerFrame:CreateTexture(nil, "OVERLAY")
        cardTexture:SetSize(32, 64)
        table.insert(drawnCards, cardTexture)  -- Store the texture in the table

        -- Position the card based on the turn count
        if turn == 0 then 
            cardTexture:SetPoint("BOTTOM", playerFrame, 296, 428)       -- Player 1: 1
        elseif turn == 1 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 165, 337)       -- Player 2: 1
        elseif turn == 2 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -160, 337)      -- Player 4: 1
        elseif turn == 3 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -285, 429)      -- Player 5: 1
        elseif turn == 4 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 0, 525)         -- Dealer: 1
        elseif turn == 5 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 286, 438)       -- Player 1: 2
        elseif turn == 6 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 155, 347)       -- Player 2: 2
        elseif turn == 7 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -150, 347)      -- Player 4: 2
        elseif turn == 8 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -275, 439)      -- Player 5: 2
        elseif turn == 9 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 276, 448)       -- Player 1: 3
        elseif turn == 10 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 266, 458)       -- Player 1: 4
        elseif turn == 11 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 256, 468)       -- Player 1: 5
        elseif turn == 12 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 246, 478)       -- Player 1: 6
        elseif turn == 13 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 236, 488)       -- Player 1: 7
        elseif turn == 14 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 276, 448)       -- Player 1: Double
        elseif turn == 15 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 145, 357)       -- Player 2: 3
        elseif turn == 16 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 135, 367)       -- Player 2: 4
        elseif turn == 17 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 125, 377)       -- Player 2: 5
        elseif turn == 18 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 115, 387)       -- Player 2: 6
        elseif turn == 19 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 105, 397)       -- Player 2: 7
        elseif turn == 20 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 145, 357)       -- Player 2: Double
        elseif turn == 21 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -140, 357)      -- Player 4: 3
        elseif turn == 22 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -130, 367)      -- Player 4: 4
        elseif turn == 23 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -120, 377)      -- Player 4: 5
        elseif turn == 24 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -110, 387)      -- Player 4: 6
        elseif turn == 25 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -100, 397)      -- Player 4: 7
        elseif turn == 26 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -140, 357)      -- Player 4: Double
        elseif turn == 27 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -265, 449)      -- Player 5: 3
        elseif turn == 28 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -255, 459)      -- Player 5: 4
        elseif turn == 29 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -245, 469)      -- Player 5: 5
        elseif turn == 30 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -235, 479)      -- Player 5: 6
        elseif turn == 31 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -225, 489)      -- Player 5: 7
        elseif turn == 32 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -265, 449)      -- Player 5: Double
        elseif turn == 33 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 12, 525)        -- Dealer: 2
        elseif turn == 34 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 24, 525)        -- Dealer: 3
        elseif turn == 35 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 36, 525)        -- Dealer: 4
        elseif turn == 36 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 48, 525)        -- Dealer: 5
        elseif turn == 37 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 60, 525)        -- Dealer: 6
        elseif turn == 38 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 72, 525)        -- Dealer: 7
        end


        cardTexture:SetTexture("Interface\\AddOns\\BJPlayer\\Images\\" .. cardName)
        cardTexture:SetDrawLayer("OVERLAY")

        -- Increment the turn counter
        turn = turn + 1
    end
end

-- Function to add a drawn card to the player's cards and display it
local function P1235(cardName)
    if cardName and cardNames[cardName] then
        local cardTexture = playerFrame:CreateTexture(nil, "OVERLAY")
        cardTexture:SetSize(32, 64)
        table.insert(drawnCards, cardTexture)  -- Store the texture in the table

        -- Position the card based on the turn count
        if turn == 0 then 
            cardTexture:SetPoint("BOTTOM", playerFrame, 296, 428)       -- Player 1: 1
        elseif turn == 1 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 165, 337)       -- Player 2: 1
        elseif turn == 2 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 300)         -- Player 3: 1
        elseif turn == 3 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -285, 429)      -- Player 5: 1
        elseif turn == 4 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 0, 525)         -- Dealer: 1
        elseif turn == 5 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 286, 438)       -- Player 1: 2
        elseif turn == 6 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 155, 347)       -- Player 2: 2
        elseif turn == 7 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 315)         -- Player 3: 2
        elseif turn == 8 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -275, 439)      -- Player 5: 2
        elseif turn == 9 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 276, 448)       -- Player 1: 3
        elseif turn == 10 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 266, 458)       -- Player 1: 4
        elseif turn == 11 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 256, 468)       -- Player 1: 5
        elseif turn == 12 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 246, 478)       -- Player 1: 6
        elseif turn == 13 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 236, 488)       -- Player 1: 7
        elseif turn == 14 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 276, 448)       -- Player 1: Double
        elseif turn == 15 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 145, 357)       -- Player 2: 3
        elseif turn == 16 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 135, 367)       -- Player 2: 4
        elseif turn == 17 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 125, 377)       -- Player 2: 5
        elseif turn == 18 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 115, 387)       -- Player 2: 6
        elseif turn == 19 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 105, 397)       -- Player 2: 7
        elseif turn == 20 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 145, 357)       -- Player 2: Double
        elseif turn == 21 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 330)         -- Player 3: 3
        elseif turn == 22 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 345)         -- Player 3: 4
        elseif turn == 23 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 360)         -- Player 3: 5
        elseif turn == 24 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 375)         -- Player 3: 6
        elseif turn == 25 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 390)         -- Player 3: 7
        elseif turn == 26 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 330)         -- Player 3: Double
        elseif turn == 27 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -265, 449)      -- Player 5: 3
        elseif turn == 28 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -255, 459)      -- Player 5: 4
        elseif turn == 29 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -245, 469)      -- Player 5: 5
        elseif turn == 30 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -235, 479)      -- Player 5: 6
        elseif turn == 31 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -225, 489)      -- Player 5: 7
        elseif turn == 32 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -265, 449)      -- Player 5: Double
        elseif turn == 33 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 12, 525)        -- Dealer: 2
        elseif turn == 34 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 24, 525)        -- Dealer: 3
        elseif turn == 35 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 36, 525)        -- Dealer: 4
        elseif turn == 36 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 48, 525)        -- Dealer: 5
        elseif turn == 37 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 60, 525)        -- Dealer: 6
        elseif turn == 38 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 72, 525)        -- Dealer: 7
        end


        cardTexture:SetTexture("Interface\\AddOns\\BJPlayer\\Images\\" .. cardName)
        cardTexture:SetDrawLayer("OVERLAY")

        -- Increment the turn counter
        turn = turn + 1
    end
end

-- Function to add a drawn card to the player's cards and display it
local function P1234(cardName)
    if cardName and cardNames[cardName] then
        local cardTexture = playerFrame:CreateTexture(nil, "OVERLAY")
        cardTexture:SetSize(32, 64)
        table.insert(drawnCards, cardTexture)  -- Store the texture in the table

        -- Position the card based on the turn count
        if turn == 0 then 
            cardTexture:SetPoint("BOTTOM", playerFrame, 296, 428)       -- Player 1: 1
        elseif turn == 1 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 165, 337)       -- Player 2: 1
        elseif turn == 2 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 300)         -- Player 3: 1
        elseif turn == 3 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -160, 337)      -- Player 4: 1
        elseif turn == 4 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 0, 525)         -- Dealer: 1
        elseif turn == 5 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 286, 438)       -- Player 1: 2
        elseif turn == 6 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 155, 347)       -- Player 2: 2
        elseif turn == 7 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 315)         -- Player 3: 2
        elseif turn == 8 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -150, 347)      -- Player 4: 2
        elseif turn == 9 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 276, 448)       -- Player 1: 3
        elseif turn == 10 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 266, 458)       -- Player 1: 4
        elseif turn == 11 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 256, 468)       -- Player 1: 5
        elseif turn == 12 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 246, 478)       -- Player 1: 6
        elseif turn == 13 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 236, 488)       -- Player 1: 7
        elseif turn == 14 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 276, 448)       -- Player 1: Double
        elseif turn == 15 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 145, 357)       -- Player 2: 3
        elseif turn == 16 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 135, 367)       -- Player 2: 4
        elseif turn == 17 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 125, 377)       -- Player 2: 5
        elseif turn == 18 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 115, 387)       -- Player 2: 6
        elseif turn == 19 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 105, 397)       -- Player 2: 7
        elseif turn == 20 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 145, 357)       -- Player 2: Double
        elseif turn == 21 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 330)         -- Player 3: 3
        elseif turn == 22 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 345)         -- Player 3: 4
        elseif turn == 23 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 360)         -- Player 3: 5
        elseif turn == 24 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 375)         -- Player 3: 6
        elseif turn == 25 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 390)         -- Player 3: 7
        elseif turn == 26 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 330)         -- Player 3: Double
        elseif turn == 27 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -140, 357)      -- Player 4: 3
        elseif turn == 28 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -130, 367)      -- Player 4: 4
        elseif turn == 29 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -120, 377)      -- Player 4: 5
        elseif turn == 30 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -110, 387)      -- Player 4: 6
        elseif turn == 31 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -100, 397)      -- Player 4: 7
        elseif turn == 32 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -140, 357)      -- Player 4: Double
        elseif turn == 33 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 12, 525)        -- Dealer: 2
        elseif turn == 34 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 24, 525)        -- Dealer: 3
        elseif turn == 35 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 36, 525)        -- Dealer: 4
        elseif turn == 36 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 48, 525)        -- Dealer: 5
        elseif turn == 37 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 60, 525)        -- Dealer: 6
        elseif turn == 38 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 72, 525)        -- Dealer: 7
        end


        cardTexture:SetTexture("Interface\\AddOns\\BJPlayer\\Images\\" .. cardName)
        cardTexture:SetDrawLayer("OVERLAY")

        -- Increment the turn counter
        turn = turn + 1
    end
end

-- Function to add a drawn card to the player's cards and display it
local function P345(cardName)
    if cardName and cardNames[cardName] then
        local cardTexture = playerFrame:CreateTexture(nil, "OVERLAY")
        cardTexture:SetSize(32, 64)
        table.insert(drawnCards, cardTexture)  -- Store the texture in the table

        -- Position the card based on the turn count
        if turn == 0 then 
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 300)         -- Player 3: 1
        elseif turn == 1 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -160, 337)      -- Player 4: 1
        elseif turn == 2 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -285, 429)      -- Player 5: 1
        elseif turn == 3 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 0, 525)         -- Dealer: 1
        elseif turn == 4 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 315)         -- Player 3: 2
        elseif turn == 5 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -150, 347)      -- Player 4: 2
        elseif turn == 6 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -275, 439)      -- Player 5: 2
        elseif turn == 7 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 330)         -- Player 3: 3
        elseif turn == 8 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 345)         -- Player 3: 4
        elseif turn == 9 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 360)         -- Player 3: 5
        elseif turn == 10 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 375)         -- Player 3: 6
        elseif turn == 11 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 390)         -- Player 3: 7
        elseif turn == 12 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 330)         -- Player 3: Double
        elseif turn == 13 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -140, 357)      -- Player 4: 3
        elseif turn == 14 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -130, 367)      -- Player 4: 4
        elseif turn == 15 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -120, 377)      -- Player 4: 5
        elseif turn == 16 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -110, 387)      -- Player 4: 6
        elseif turn == 17 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -100, 397)      -- Player 4: 7
        elseif turn == 18 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -140, 357)      -- Player 4: Double
        elseif turn == 19 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -265, 449)      -- Player 5: 3
        elseif turn == 20 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -255, 459)      -- Player 5: 4
        elseif turn == 21 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -245, 469)      -- Player 5: 5
        elseif turn == 22 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -235, 479)      -- Player 5: 6
        elseif turn == 23 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -225, 489)      -- Player 5: 7
        elseif turn == 24 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -265, 449)      -- Player 5: Double
        elseif turn == 25 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 12, 525)        -- Dealer: 2
        elseif turn == 26 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 24, 525)        -- Dealer: 3
        elseif turn == 27 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 36, 525)        -- Dealer: 4
        elseif turn == 28 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 48, 525)        -- Dealer: 5
        elseif turn == 29 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 60, 525)        -- Dealer: 6
        elseif turn == 30 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 72, 525)        -- Dealer: 7
        end

        cardTexture:SetTexture("Interface\\AddOns\\BJPlayer\\Images\\" .. cardName)
        cardTexture:SetDrawLayer("OVERLAY")

        -- Increment the turn counter
        turn = turn + 1
    end
end

-- Function to add a drawn card to the player's cards and display it
local function P245(cardName)
    if cardName and cardNames[cardName] then
        local cardTexture = playerFrame:CreateTexture(nil, "OVERLAY")
        cardTexture:SetSize(32, 64)
        table.insert(drawnCards, cardTexture)  -- Store the texture in the table

        -- Position the card based on the turn count
        if turn == 0 then 
            cardTexture:SetPoint("BOTTOM", playerFrame, 165, 337)       -- Player 2: 1
        elseif turn == 1 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -160, 337)      -- Player 4: 1
        elseif turn == 2 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -285, 429)      -- Player 5: 1
        elseif turn == 3 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 0, 525)         -- Dealer: 1
        elseif turn == 4 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 155, 347)       -- Player 2: 2
        elseif turn == 5 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -150, 347)      -- Player 4: 2
        elseif turn == 6 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -275, 439)      -- Player 5: 2
        elseif turn == 7 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 145, 357)       -- Player 2: 3
        elseif turn == 8 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 135, 367)       -- Player 2: 4
        elseif turn == 9 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 125, 377)       -- Player 2: 5
        elseif turn == 10 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 115, 387)       -- Player 2: 6
        elseif turn == 11 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 105, 397)       -- Player 2: 7
        elseif turn == 12 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 145, 357)       -- Player 2: Double
        elseif turn == 29 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -140, 357)      -- Player 4: 3
        elseif turn == 30 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -130, 367)      -- Player 4: 4
        elseif turn == 31 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -120, 377)      -- Player 4: 5
        elseif turn == 32 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -110, 387)      -- Player 4: 6
        elseif turn == 33 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -100, 397)      -- Player 4: 7
        elseif turn == 34 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -140, 357)      -- Player 4: Double
        elseif turn == 19 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -265, 449)      -- Player 5: 3
        elseif turn == 20 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -255, 459)      -- Player 5: 4
        elseif turn == 21 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -245, 469)      -- Player 5: 5
        elseif turn == 22 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -235, 479)      -- Player 5: 6
        elseif turn == 23 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -225, 489)      -- Player 5: 7
        elseif turn == 24 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -265, 449)      -- Player 5: Double
        elseif turn == 25 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 12, 525)        -- Dealer: 2
        elseif turn == 26 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 24, 525)        -- Dealer: 3
        elseif turn == 27 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 36, 525)        -- Dealer: 4
        elseif turn == 28 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 48, 525)        -- Dealer: 5
        elseif turn == 29 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 60, 525)        -- Dealer: 6
        elseif turn == 30 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 72, 525)        -- Dealer: 7
        end

        cardTexture:SetTexture("Interface\\AddOns\\BJPlayer\\Images\\" .. cardName)
        cardTexture:SetDrawLayer("OVERLAY")

        -- Increment the turn counter
        turn = turn + 1
    end
end

-- Function to add a drawn card to the player's cards and display it
local function P235(cardName)
    if cardName and cardNames[cardName] then
        local cardTexture = playerFrame:CreateTexture(nil, "OVERLAY")
        cardTexture:SetSize(32, 64)
        table.insert(drawnCards, cardTexture)  -- Store the texture in the table

        -- Position the card based on the turn count
        if turn == 0 then 
            cardTexture:SetPoint("BOTTOM", playerFrame, 165, 337)       -- Player 2: 1
        elseif turn == 1 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 300)         -- Player 3: 1
        elseif turn == 2 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -285, 429)      -- Player 5: 1
        elseif turn == 3 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 0, 525)         -- Dealer: 1
        elseif turn == 4 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 155, 347)       -- Player 2: 2
        elseif turn == 5 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 315)         -- Player 3: 2
        elseif turn == 6 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -275, 439)      -- Player 5: 2
        elseif turn == 7 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 145, 357)       -- Player 2: 3
        elseif turn == 8 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 135, 367)       -- Player 2: 4
        elseif turn == 9 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 125, 377)       -- Player 2: 5
        elseif turn == 10 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 115, 387)       -- Player 2: 6
        elseif turn == 11 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 105, 397)       -- Player 2: 7
        elseif turn == 12 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 145, 357)       -- Player 2: Double
        elseif turn == 13 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 330)         -- Player 3: 3
        elseif turn == 14 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 345)         -- Player 3: 4
        elseif turn == 15 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 360)         -- Player 3: 5
        elseif turn == 16 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 375)         -- Player 3: 6
        elseif turn == 17 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 390)         -- Player 3: 7
        elseif turn == 18 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 330)         -- Player 3: Double
        elseif turn == 19 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -265, 449)      -- Player 5: 3
        elseif turn == 20 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -255, 459)      -- Player 5: 4
        elseif turn == 21 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -245, 469)      -- Player 5: 5
        elseif turn == 22 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -235, 479)      -- Player 5: 6
        elseif turn == 23 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -225, 489)      -- Player 5: 7
        elseif turn == 24 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -265, 449)      -- Player 5: Double
        elseif turn == 25 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 12, 525)        -- Dealer: 2
        elseif turn == 26 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 24, 525)        -- Dealer: 3
        elseif turn == 27 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 36, 525)        -- Dealer: 4
        elseif turn == 28 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 48, 525)        -- Dealer: 5
        elseif turn == 29 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 60, 525)        -- Dealer: 6
        elseif turn == 30 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 72, 525)        -- Dealer: 7
        end

        cardTexture:SetTexture("Interface\\AddOns\\BJPlayer\\Images\\" .. cardName)
        cardTexture:SetDrawLayer("OVERLAY")

        -- Increment the turn counter
        turn = turn + 1
    end
end

-- Function to add a drawn card to the player's cards and display it
local function P234(cardName)
    if cardName and cardNames[cardName] then
        local cardTexture = playerFrame:CreateTexture(nil, "OVERLAY")
        cardTexture:SetSize(32, 64)
        table.insert(drawnCards, cardTexture)  -- Store the texture in the table

        -- Position the card based on the turn count
        if turn == 0 then 
            cardTexture:SetPoint("BOTTOM", playerFrame, 165, 337)       -- Player 2: 1
        elseif turn == 1 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 300)         -- Player 3: 1
        elseif turn == 2 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -160, 337)      -- Player 4: 1
        elseif turn == 3 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 0, 525)         -- Dealer: 1
        elseif turn == 4 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 155, 347)       -- Player 2: 2
        elseif turn == 5 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 315)         -- Player 3: 2
        elseif turn == 6 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -150, 347)      -- Player 4: 2
        elseif turn == 7 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 145, 357)       -- Player 2: 3
        elseif turn == 8 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 135, 367)       -- Player 2: 4
        elseif turn == 9 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 125, 377)       -- Player 2: 5
        elseif turn == 10 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 115, 387)       -- Player 2: 6
        elseif turn == 11 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 105, 397)       -- Player 2: 7
        elseif turn == 12 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 145, 357)       -- Player 2: Double
        elseif turn == 13 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 330)         -- Player 3: 3
        elseif turn == 14 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 345)         -- Player 3: 4
        elseif turn == 15 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 360)         -- Player 3: 5
        elseif turn == 16 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 375)         -- Player 3: 6
        elseif turn == 17 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 390)         -- Player 3: 7
        elseif turn == 18 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 330)         -- Player 3: Double
        elseif turn == 19 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -140, 357)      -- Player 4: 3
        elseif turn == 20 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -130, 367)      -- Player 4: 4
        elseif turn == 21 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -120, 377)      -- Player 4: 5
        elseif turn == 22 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -110, 387)      -- Player 4: 6
        elseif turn == 23 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -100, 397)      -- Player 4: 7
        elseif turn == 24 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -140, 357)      -- Player 4: Double
        elseif turn == 25 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 12, 525)        -- Dealer: 2
        elseif turn == 26 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 24, 525)        -- Dealer: 3
        elseif turn == 27 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 36, 525)        -- Dealer: 4
        elseif turn == 28 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 48, 525)        -- Dealer: 5
        elseif turn == 29 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 60, 525)        -- Dealer: 6
        elseif turn == 30 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 72, 525)        -- Dealer: 7
        end

        cardTexture:SetTexture("Interface\\AddOns\\BJPlayer\\Images\\" .. cardName)
        cardTexture:SetDrawLayer("OVERLAY")

        -- Increment the turn counter
        turn = turn + 1
    end
end

-- Function to add a drawn card to the player's cards and display it
local function P145(cardName)
    if cardName and cardNames[cardName] then
        local cardTexture = playerFrame:CreateTexture(nil, "OVERLAY")
        cardTexture:SetSize(32, 64)
        table.insert(drawnCards, cardTexture)  -- Store the texture in the table

        -- Position the card based on the turn count
        if turn == 0 then 
            cardTexture:SetPoint("BOTTOM", playerFrame, 296, 428)       -- Player 1: 1
        elseif turn == 1 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -160, 337)      -- Player 4: 1
        elseif turn == 2 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -285, 429)      -- Player 5: 1
        elseif turn == 3 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 0, 525)         -- Dealer: 1
        elseif turn == 4 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 286, 438)       -- Player 1: 2
        elseif turn == 5 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -150, 347)      -- Player 4: 2
        elseif turn == 6 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -275, 439)      -- Player 5: 2
        elseif turn == 7 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 276, 448)       -- Player 1: 3
        elseif turn == 8 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 266, 458)       -- Player 1: 4
        elseif turn == 9 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 256, 468)       -- Player 1: 5
        elseif turn == 10 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 246, 478)       -- Player 1: 6
        elseif turn == 11 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 236, 488)       -- Player 1: 7
        elseif turn == 12 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 276, 448)       -- Player 1: Double
        elseif turn == 13 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -140, 357)      -- Player 4: 3
        elseif turn == 14 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -130, 367)      -- Player 4: 4
        elseif turn == 15 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -120, 377)      -- Player 4: 5
        elseif turn == 16 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -110, 387)      -- Player 4: 6
        elseif turn == 17 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -100, 397)      -- Player 4: 7
        elseif turn == 18 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -140, 357)      -- Player 4: Double
        elseif turn == 19 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -265, 449)      -- Player 5: 3
        elseif turn == 20 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -255, 459)      -- Player 5: 4
        elseif turn == 21 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -245, 469)      -- Player 5: 5
        elseif turn == 22 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -235, 479)      -- Player 5: 6
        elseif turn == 23 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -225, 489)      -- Player 5: 7
        elseif turn == 24 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -265, 449)      -- Player 5: Double
        elseif turn == 25 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 12, 525)        -- Dealer: 2
        elseif turn == 26 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 24, 525)        -- Dealer: 3
        elseif turn == 27 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 36, 525)        -- Dealer: 4
        elseif turn == 28 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 48, 525)        -- Dealer: 5
        elseif turn == 29 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 60, 525)        -- Dealer: 6
        elseif turn == 30 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 72, 525)        -- Dealer: 7
        end

        cardTexture:SetTexture("Interface\\AddOns\\BJPlayer\\Images\\" .. cardName)
        cardTexture:SetDrawLayer("OVERLAY")

        -- Increment the turn counter
        turn = turn + 1
    end
end

-- Function to add a drawn card to the player's cards and display it
local function P135(cardName)
    if cardName and cardNames[cardName] then
        local cardTexture = playerFrame:CreateTexture(nil, "OVERLAY")
        cardTexture:SetSize(32, 64)
        table.insert(drawnCards, cardTexture)  -- Store the texture in the table

        -- Position the card based on the turn count
        if turn == 0 then 
            cardTexture:SetPoint("BOTTOM", playerFrame, 296, 428)       -- Player 1: 1
        elseif turn == 1 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 300)         -- Player 3: 1
        elseif turn == 2 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -285, 429)      -- Player 5: 1
        elseif turn == 3 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 0, 525)         -- Dealer: 1
        elseif turn == 4 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 286, 438)       -- Player 1: 2
        elseif turn == 5 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 315)         -- Player 3: 2
        elseif turn == 6 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -275, 439)      -- Player 5: 2
        elseif turn == 7 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 276, 448)       -- Player 1: 3
        elseif turn == 8 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 266, 458)       -- Player 1: 4
        elseif turn == 9 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 256, 468)       -- Player 1: 5
        elseif turn == 10 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 246, 478)       -- Player 1: 6
        elseif turn == 11 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 236, 488)       -- Player 1: 7
        elseif turn == 12 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 276, 448)       -- Player 1: Double
        elseif turn == 13 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 330)         -- Player 3: 3
        elseif turn == 14 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 345)         -- Player 3: 4
        elseif turn == 15 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 360)         -- Player 3: 5
        elseif turn == 16 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 375)         -- Player 3: 6
        elseif turn == 17 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 390)         -- Player 3: 7
        elseif turn == 18 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 330)         -- Player 3: Double
        elseif turn == 19 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -265, 449)      -- Player 5: 3
        elseif turn == 20 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -255, 459)      -- Player 5: 4
        elseif turn == 21 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -245, 469)      -- Player 5: 5
        elseif turn == 22 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -235, 479)      -- Player 5: 6
        elseif turn == 23 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -225, 489)      -- Player 5: 7
        elseif turn == 24 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -265, 449)      -- Player 5: Double
        elseif turn == 25 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 12, 525)        -- Dealer: 2
        elseif turn == 26 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 24, 525)        -- Dealer: 3
        elseif turn == 27 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 36, 525)        -- Dealer: 4
        elseif turn == 28 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 48, 525)        -- Dealer: 5
        elseif turn == 29 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 60, 525)        -- Dealer: 6
        elseif turn == 30 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 72, 525)        -- Dealer: 7
        end

        cardTexture:SetTexture("Interface\\AddOns\\BJPlayer\\Images\\" .. cardName)
        cardTexture:SetDrawLayer("OVERLAY")

        -- Increment the turn counter
        turn = turn + 1
    end
end

-- Function to add a drawn card to the player's cards and display it
local function P134(cardName)
    if cardName and cardNames[cardName] then
        local cardTexture = playerFrame:CreateTexture(nil, "OVERLAY")
        cardTexture:SetSize(32, 64)
        table.insert(drawnCards, cardTexture)  -- Store the texture in the table

        -- Position the card based on the turn count
        if turn == 0 then 
            cardTexture:SetPoint("BOTTOM", playerFrame, 296, 428)       -- Player 1: 1
        elseif turn == 1 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 300)         -- Player 3: 1
        elseif turn == 2 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -160, 337)      -- Player 4: 1
        elseif turn == 3 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 0, 525)         -- Dealer: 1
        elseif turn == 4 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 286, 438)       -- Player 1: 2
        elseif turn == 5 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 315)         -- Player 3: 2
        elseif turn == 6 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -150, 347)      -- Player 4: 2
        elseif turn == 7 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 276, 448)       -- Player 1: 3
        elseif turn == 8 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 266, 458)       -- Player 1: 4
        elseif turn == 9 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 256, 468)       -- Player 1: 5
        elseif turn == 10 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 246, 478)       -- Player 1: 6
        elseif turn == 11 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 236, 488)       -- Player 1: 7
        elseif turn == 12 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 276, 448)       -- Player 1: Double
        elseif turn == 13 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 330)         -- Player 3: 3
        elseif turn == 14 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 345)         -- Player 3: 4
        elseif turn == 15 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 360)         -- Player 3: 5
        elseif turn == 16 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 375)         -- Player 3: 6
        elseif turn == 17 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 390)         -- Player 3: 7
        elseif turn == 18 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 330)         -- Player 3: Double
        elseif turn == 19 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -140, 357)      -- Player 4: 3
        elseif turn == 20 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -130, 367)      -- Player 4: 4
        elseif turn == 21 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -120, 377)      -- Player 4: 5
        elseif turn == 22 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -110, 387)      -- Player 4: 6
        elseif turn == 23 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -100, 397)      -- Player 4: 7
        elseif turn == 24 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -140, 357)      -- Player 4: Double
        elseif turn == 25 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 12, 525)        -- Dealer: 2
        elseif turn == 26 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 24, 525)        -- Dealer: 3
        elseif turn == 27 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 36, 525)        -- Dealer: 4
        elseif turn == 28 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 48, 525)        -- Dealer: 5
        elseif turn == 29 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 60, 525)        -- Dealer: 6
        elseif turn == 30 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 72, 525)        -- Dealer: 7
        end

        cardTexture:SetTexture("Interface\\AddOns\\BJPlayer\\Images\\" .. cardName)
        cardTexture:SetDrawLayer("OVERLAY")

        -- Increment the turn counter
        turn = turn + 1
    end
end

-- Function to add a drawn card to the player's cards and display it
local function P125(cardName)
    if cardName and cardNames[cardName] then
        local cardTexture = playerFrame:CreateTexture(nil, "OVERLAY")
        cardTexture:SetSize(32, 64)
        table.insert(drawnCards, cardTexture)  -- Store the texture in the table

        -- Position the card based on the turn count
        if turn == 0 then 
            cardTexture:SetPoint("BOTTOM", playerFrame, 296, 428)       -- Player 1: 1
        elseif turn == 1 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 165, 337)       -- Player 2: 1
        elseif turn == 2 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -285, 429)      -- Player 5: 1
        elseif turn == 3 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 0, 525)         -- Dealer: 1
        elseif turn == 4 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 286, 438)       -- Player 1: 2
        elseif turn == 5 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 155, 347)       -- Player 2: 2
        elseif turn == 6 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -275, 439)      -- Player 5: 2
        elseif turn == 7 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 276, 448)       -- Player 1: 3
        elseif turn == 8 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 266, 458)       -- Player 1: 4
        elseif turn == 9 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 256, 468)       -- Player 1: 5
        elseif turn == 10 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 246, 478)       -- Player 1: 6
        elseif turn == 11 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 236, 488)       -- Player 1: 7
        elseif turn == 12 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 276, 448)       -- Player 1: Double
        elseif turn == 13 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 145, 357)       -- Player 2: 3
        elseif turn == 14 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 135, 367)       -- Player 2: 4
        elseif turn == 15 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 125, 377)       -- Player 2: 5
        elseif turn == 16 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 115, 387)       -- Player 2: 6
        elseif turn == 17 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 105, 397)       -- Player 2: 7
        elseif turn == 18 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 145, 357)       -- Player 2: Double
        elseif turn == 19 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -265, 449)      -- Player 5: 3
        elseif turn == 20 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -255, 459)      -- Player 5: 4
        elseif turn == 21 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -245, 469)      -- Player 5: 5
        elseif turn == 22 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -235, 479)      -- Player 5: 6
        elseif turn == 23 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -225, 489)      -- Player 5: 7
        elseif turn == 24 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -265, 449)      -- Player 5: Double
        elseif turn == 25 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 12, 525)        -- Dealer: 2
        elseif turn == 26 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 24, 525)        -- Dealer: 3
        elseif turn == 27 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 36, 525)        -- Dealer: 4
        elseif turn == 28 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 48, 525)        -- Dealer: 5
        elseif turn == 29 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 60, 525)        -- Dealer: 6
        elseif turn == 30 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 72, 525)        -- Dealer: 7
        end

        cardTexture:SetTexture("Interface\\AddOns\\BJPlayer\\Images\\" .. cardName)
        cardTexture:SetDrawLayer("OVERLAY")

        -- Increment the turn counter
        turn = turn + 1
    end
end

-- Function to add a drawn card to the player's cards and display it
local function P124(cardName)
    if cardName and cardNames[cardName] then
        local cardTexture = playerFrame:CreateTexture(nil, "OVERLAY")
        cardTexture:SetSize(32, 64)
        table.insert(drawnCards, cardTexture)  -- Store the texture in the table

        -- Position the card based on the turn count
        if turn == 0 then 
            cardTexture:SetPoint("BOTTOM", playerFrame, 296, 428)       -- Player 1: 1
        elseif turn == 1 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 165, 337)       -- Player 2: 1
        elseif turn == 2 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -160, 337)      -- Player 4: 1
        elseif turn == 3 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 0, 525)         -- Dealer: 1
        elseif turn == 4 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 286, 438)       -- Player 1: 2
        elseif turn == 5 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 155, 347)       -- Player 2: 2
        elseif turn == 6 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -150, 347)      -- Player 4: 2
        elseif turn == 7 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 276, 448)       -- Player 1: 3
        elseif turn == 8 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 266, 458)       -- Player 1: 4
        elseif turn == 9 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 256, 468)       -- Player 1: 5
        elseif turn == 10 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 246, 478)       -- Player 1: 6
        elseif turn == 11 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 236, 488)       -- Player 1: 7
        elseif turn == 12 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 276, 448)       -- Player 1: Double
        elseif turn == 13 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 145, 357)       -- Player 2: 3
        elseif turn == 14 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 135, 367)       -- Player 2: 4
        elseif turn == 15 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 125, 377)       -- Player 2: 5
        elseif turn == 16 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 115, 387)       -- Player 2: 6
        elseif turn == 17 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 105, 397)       -- Player 2: 7
        elseif turn == 18 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 145, 357)       -- Player 2: Double
        elseif turn == 19 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -140, 357)      -- Player 4: 3
        elseif turn == 20 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -130, 367)      -- Player 4: 4
        elseif turn == 21 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -120, 377)      -- Player 4: 5
        elseif turn == 22 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -110, 387)      -- Player 4: 6
        elseif turn == 23 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -100, 397)      -- Player 4: 7
        elseif turn == 24 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -140, 357)      -- Player 4: Double
        elseif turn == 25 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 12, 525)        -- Dealer: 2
        elseif turn == 26 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 24, 525)        -- Dealer: 3
        elseif turn == 27 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 36, 525)        -- Dealer: 4
        elseif turn == 28 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 48, 525)        -- Dealer: 5
        elseif turn == 29 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 60, 525)        -- Dealer: 6
        elseif turn == 30 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 72, 525)        -- Dealer: 7
        end

        cardTexture:SetTexture("Interface\\AddOns\\BJPlayer\\Images\\" .. cardName)
        cardTexture:SetDrawLayer("OVERLAY")

        -- Increment the turn counter
        turn = turn + 1
    end
end

-- Function to add a drawn card to the player's cards and display it
local function P123(cardName)
    if cardName and cardNames[cardName] then
        local cardTexture = playerFrame:CreateTexture(nil, "OVERLAY")
        cardTexture:SetSize(32, 64)
        table.insert(drawnCards, cardTexture)  -- Store the texture in the table

        -- Position the card based on the turn count
        if turn == 0 then 
            cardTexture:SetPoint("BOTTOM", playerFrame, 296, 428)       -- Player 1: 1
        elseif turn == 1 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 165, 337)       -- Player 2: 1
        elseif turn == 2 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 300)         -- Player 3: 1
        elseif turn == 3 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 0, 525)         -- Dealer: 1
        elseif turn == 4 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 286, 438)       -- Player 1: 2
        elseif turn == 5 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 155, 347)       -- Player 2: 2
        elseif turn == 6 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 315)         -- Player 3: 2
        elseif turn == 7 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 276, 448)       -- Player 1: 3
        elseif turn == 8 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 266, 458)       -- Player 1: 4
        elseif turn == 9 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 256, 468)       -- Player 1: 5
        elseif turn == 10 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 246, 478)       -- Player 1: 6
        elseif turn == 11 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 236, 488)       -- Player 1: 7
        elseif turn == 12 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 276, 448)       -- Player 1: Double
        elseif turn == 13 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 145, 357)       -- Player 2: 3
        elseif turn == 14 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 135, 367)       -- Player 2: 4
        elseif turn == 15 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 125, 377)       -- Player 2: 5
        elseif turn == 16 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 115, 387)       -- Player 2: 6
        elseif turn == 17 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 105, 397)       -- Player 2: 7
        elseif turn == 18 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 145, 357)       -- Player 2: Double
        elseif turn == 19 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 330)         -- Player 3: 3
        elseif turn == 20 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 345)         -- Player 3: 4
        elseif turn == 21 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 360)         -- Player 3: 5
        elseif turn == 22 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 375)         -- Player 3: 6
        elseif turn == 23 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 390)         -- Player 3: 7
        elseif turn == 24 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 330)         -- Player 3: Double
        elseif turn == 25 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 12, 525)        -- Dealer: 2
        elseif turn == 26 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 24, 525)        -- Dealer: 3
        elseif turn == 27 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 36, 525)        -- Dealer: 4
        elseif turn == 28 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 48, 525)        -- Dealer: 5
        elseif turn == 29 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 60, 525)        -- Dealer: 6
        elseif turn == 30 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 72, 525)        -- Dealer: 7
        end

        cardTexture:SetTexture("Interface\\AddOns\\BJPlayer\\Images\\" .. cardName)
        cardTexture:SetDrawLayer("OVERLAY")

        -- Increment the turn counter
        turn = turn + 1
    end
end

-- Function to add a drawn card to the player's cards and display it
local function P45(cardName)
    if cardName and cardNames[cardName] then
        local cardTexture = playerFrame:CreateTexture(nil, "OVERLAY")
        cardTexture:SetSize(32, 64)
        table.insert(drawnCards, cardTexture)  -- Store the texture in the table

        -- Position the card based on the turn count
        if turn == 0 then 
            cardTexture:SetPoint("BOTTOM", playerFrame, -160, 337)      -- Player 4: 1
        elseif turn == 1 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -285, 429)      -- Player 5: 1
        elseif turn == 2 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 0, 525)         -- Dealer: 1
        elseif turn == 3 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -150, 347)      -- Player 4: 2
        elseif turn == 4 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -275, 439)      -- Player 5: 2
        elseif turn == 5 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -140, 357)      -- Player 4: 3
        elseif turn == 6 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -130, 367)      -- Player 4: 4
        elseif turn == 7 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -120, 377)      -- Player 4: 5
        elseif turn == 8 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -110, 387)      -- Player 4: 6
        elseif turn == 9 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -100, 397)      -- Player 4: 7
        elseif turn == 10 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -140, 357)      -- Player 4: Double
        elseif turn == 11 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -265, 449)      -- Player 5: 3
        elseif turn == 12 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -255, 459)      -- Player 5: 4
        elseif turn == 13 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -245, 469)      -- Player 5: 5
        elseif turn == 14 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -235, 479)      -- Player 5: 6
        elseif turn == 15 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -225, 489)      -- Player 5: 7
        elseif turn == 16 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -265, 449)      -- Player 5: Double
        elseif turn == 17 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 12, 525)        -- Dealer: 2
        elseif turn == 18 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 24, 525)        -- Dealer: 3
        elseif turn == 19 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 36, 525)        -- Dealer: 4
        elseif turn == 20 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 48, 525)        -- Dealer: 5
        elseif turn == 21 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 60, 525)        -- Dealer: 6
        elseif turn == 22 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 72, 525)        -- Dealer: 7
        end

        cardTexture:SetTexture("Interface\\AddOns\\BJPlayer\\Images\\" .. cardName)
        cardTexture:SetDrawLayer("OVERLAY")

        -- Increment the turn counter
        turn = turn + 1
    end
end

-- Function to add a drawn card to the player's cards and display it
local function P35(cardName)
    if cardName and cardNames[cardName] then
        local cardTexture = playerFrame:CreateTexture(nil, "OVERLAY")
        cardTexture:SetSize(32, 64)
        table.insert(drawnCards, cardTexture)  -- Store the texture in the table

        -- Position the card based on the turn count
        if turn == 0 then 
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 300)         -- Player 3: 1
        elseif turn == 1 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -285, 429)      -- Player 5: 1
        elseif turn == 2 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 0, 525)         -- Dealer: 1
        elseif turn == 3 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 315)         -- Player 3: 2
        elseif turn == 4 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -275, 439)      -- Player 5: 2
        elseif turn == 5 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 330)         -- Player 3: 3
        elseif turn == 6 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 345)         -- Player 3: 4
        elseif turn == 7 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 360)         -- Player 3: 5
        elseif turn == 8 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 375)         -- Player 3: 6
        elseif turn == 9 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 390)         -- Player 3: 7
        elseif turn == 10 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 330)         -- Player 3: Double
        elseif turn == 11 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -265, 449)      -- Player 5: 3
        elseif turn == 12 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -255, 459)      -- Player 5: 4
        elseif turn == 13 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -245, 469)      -- Player 5: 5
        elseif turn == 14 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -235, 479)      -- Player 5: 6
        elseif turn == 15 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -225, 489)      -- Player 5: 7
        elseif turn == 16 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -265, 449)      -- Player 5: Double
        elseif turn == 17 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 12, 525)        -- Dealer: 2
        elseif turn == 18 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 24, 525)        -- Dealer: 3
        elseif turn == 19 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 36, 525)        -- Dealer: 4
        elseif turn == 20 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 48, 525)        -- Dealer: 5
        elseif turn == 21 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 60, 525)        -- Dealer: 6
        elseif turn == 22 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 72, 525)        -- Dealer: 7
        end

        cardTexture:SetTexture("Interface\\AddOns\\BJPlayer\\Images\\" .. cardName)
        cardTexture:SetDrawLayer("OVERLAY")

        -- Increment the turn counter
        turn = turn + 1
    end
end

-- Function to add a drawn card to the player's cards and display it
local function P34(cardName)
    if cardName and cardNames[cardName] then
        local cardTexture = playerFrame:CreateTexture(nil, "OVERLAY")
        cardTexture:SetSize(32, 64)
        table.insert(drawnCards, cardTexture)  -- Store the texture in the table

        -- Position the card based on the turn count
        if turn == 0 then 
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 300)         -- Player 3: 1
        elseif turn == 1 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -160, 337)      -- Player 4: 1
        elseif turn == 2 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 0, 525)         -- Dealer: 1
        elseif turn == 3 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 315)         -- Player 3: 2
        elseif turn == 4 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -150, 347)      -- Player 4: 2
        elseif turn == 5 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 330)         -- Player 3: 3
        elseif turn == 6 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 345)         -- Player 3: 4
        elseif turn == 7 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 360)         -- Player 3: 5
        elseif turn == 8 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 375)         -- Player 3: 6
        elseif turn == 9 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 390)         -- Player 3: 7
        elseif turn == 10 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 330)         -- Player 3: Double
        elseif turn == 11 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -140, 357)      -- Player 4: 3
        elseif turn == 12 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -130, 367)      -- Player 4: 4
        elseif turn == 13 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -120, 377)      -- Player 4: 5
        elseif turn == 14 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -110, 387)      -- Player 4: 6
        elseif turn == 15 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -100, 397)      -- Player 4: 7
        elseif turn == 16 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -140, 357)      -- Player 4: Double
        elseif turn == 17 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 12, 525)        -- Dealer: 2
        elseif turn == 18 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 24, 525)        -- Dealer: 3
        elseif turn == 19 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 36, 525)        -- Dealer: 4
        elseif turn == 20 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 48, 525)        -- Dealer: 5
        elseif turn == 21 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 60, 525)        -- Dealer: 6
        elseif turn == 22 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 72, 525)        -- Dealer: 7
        end

        cardTexture:SetTexture("Interface\\AddOns\\BJPlayer\\Images\\" .. cardName)
        cardTexture:SetDrawLayer("OVERLAY")

        -- Increment the turn counter
        turn = turn + 1
    end
end

-- Function to add a drawn card to the player's cards and display it
local function P25(cardName)
    if cardName and cardNames[cardName] then
        local cardTexture = playerFrame:CreateTexture(nil, "OVERLAY")
        cardTexture:SetSize(32, 64)
        table.insert(drawnCards, cardTexture)  -- Store the texture in the table

        -- Position the card based on the turn count
        if turn == 0 then 
            cardTexture:SetPoint("BOTTOM", playerFrame, 165, 337)       -- Player 2: 1
        elseif turn == 1 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -285, 429)      -- Player 5: 1
        elseif turn == 2 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 0, 525)         -- Dealer: 1
        elseif turn == 3 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 155, 347)       -- Player 2: 2
        elseif turn == 4 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -275, 439)      -- Player 5: 2
        elseif turn == 5 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 145, 357)       -- Player 2: 3
        elseif turn == 6 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 135, 367)       -- Player 2: 4
        elseif turn == 7 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 125, 377)       -- Player 2: 5
        elseif turn == 8 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 115, 387)       -- Player 2: 6
        elseif turn == 9 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 105, 397)       -- Player 2: 7
        elseif turn == 10 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 145, 357)       -- Player 2: Double
        elseif turn == 11 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -265, 449)      -- Player 5: 3
        elseif turn == 12 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -255, 459)      -- Player 5: 4
        elseif turn == 13 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -245, 469)      -- Player 5: 5
        elseif turn == 14 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -235, 479)      -- Player 5: 6
        elseif turn == 15 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -225, 489)      -- Player 5: 7
        elseif turn == 16 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -265, 449)      -- Player 5: Double
        elseif turn == 17 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 12, 525)        -- Dealer: 2
        elseif turn == 18 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 24, 525)        -- Dealer: 3
        elseif turn == 19 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 36, 525)        -- Dealer: 4
        elseif turn == 20 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 48, 525)        -- Dealer: 5
        elseif turn == 21 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 60, 525)        -- Dealer: 6
        elseif turn == 22 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 72, 525)        -- Dealer: 7
        end

        cardTexture:SetTexture("Interface\\AddOns\\BJPlayer\\Images\\" .. cardName)
        cardTexture:SetDrawLayer("OVERLAY")

        -- Increment the turn counter
        turn = turn + 1
    end
end

-- Function to add a drawn card to the player's cards and display it
local function P24(cardName)
    if cardName and cardNames[cardName] then
        local cardTexture = playerFrame:CreateTexture(nil, "OVERLAY")
        cardTexture:SetSize(32, 64)
        table.insert(drawnCards, cardTexture)  -- Store the texture in the table

        -- Position the card based on the turn count
        if turn == 0 then 
            cardTexture:SetPoint("BOTTOM", playerFrame, 165, 337)       -- Player 2: 1
        elseif turn == 1 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -160, 337)      -- Player 4: 1
        elseif turn == 2 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 0, 525)         -- Dealer: 1
        elseif turn == 3 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 155, 347)       -- Player 2: 2
        elseif turn == 4 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -150, 347)      -- Player 4: 2
        elseif turn == 5 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 145, 357)       -- Player 2: 3
        elseif turn == 6 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 135, 367)       -- Player 2: 4
        elseif turn == 7 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 125, 377)       -- Player 2: 5
        elseif turn == 8 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 115, 387)       -- Player 2: 6
        elseif turn == 9 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 105, 397)       -- Player 2: 7
        elseif turn == 10 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 145, 357)       -- Player 2: Double
        elseif turn == 11 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -140, 357)      -- Player 4: 3
        elseif turn == 12 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -130, 367)      -- Player 4: 4
        elseif turn == 13 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -120, 377)      -- Player 4: 5
        elseif turn == 14 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -110, 387)      -- Player 4: 6
        elseif turn == 15 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -100, 397)      -- Player 4: 7
        elseif turn == 16 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -140, 357)      -- Player 4: Double
        elseif turn == 17 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 12, 525)        -- Dealer: 2
        elseif turn == 18 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 24, 525)        -- Dealer: 3
        elseif turn == 19 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 36, 525)        -- Dealer: 4
        elseif turn == 20 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 48, 525)        -- Dealer: 5
        elseif turn == 21 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 60, 525)        -- Dealer: 6
        elseif turn == 22 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 72, 525)        -- Dealer: 7
        end

        cardTexture:SetTexture("Interface\\AddOns\\BJPlayer\\Images\\" .. cardName)
        cardTexture:SetDrawLayer("OVERLAY")

        -- Increment the turn counter
        turn = turn + 1
    end
end

-- Function to add a drawn card to the player's cards and display it
local function P23(cardName)
    if cardName and cardNames[cardName] then
        local cardTexture = playerFrame:CreateTexture(nil, "OVERLAY")
        cardTexture:SetSize(32, 64)
        table.insert(drawnCards, cardTexture)  -- Store the texture in the table

        -- Position the card based on the turn count
        if turn == 0 then 
            cardTexture:SetPoint("BOTTOM", playerFrame, 165, 337)       -- Player 2: 1
        elseif turn == 1 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 300)         -- Player 3: 1
        elseif turn == 2 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 0, 525)         -- Dealer: 1
        elseif turn == 3 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 155, 347)       -- Player 2: 2
        elseif turn == 4 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 315)         -- Player 3: 2
        elseif turn == 5 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 145, 357)       -- Player 2: 3
        elseif turn == 6 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 135, 367)       -- Player 2: 4
        elseif turn == 7 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 125, 377)       -- Player 2: 5
        elseif turn == 8 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 115, 387)       -- Player 2: 6
        elseif turn == 9 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 105, 397)       -- Player 2: 7
        elseif turn == 10 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 145, 357)       -- Player 2: Double
        elseif turn == 11 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 330)         -- Player 3: 3
        elseif turn == 12 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 345)         -- Player 3: 4
        elseif turn == 13 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 360)         -- Player 3: 5
        elseif turn == 14 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 375)         -- Player 3: 6
        elseif turn == 15 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 390)         -- Player 3: 7
        elseif turn == 16 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 330)         -- Player 3: Double
        elseif turn == 17 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 12, 525)        -- Dealer: 2
        elseif turn == 18 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 24, 525)        -- Dealer: 3
        elseif turn == 19 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 36, 525)        -- Dealer: 4
        elseif turn == 20 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 48, 525)        -- Dealer: 5
        elseif turn == 21 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 60, 525)        -- Dealer: 6
        elseif turn == 22 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 72, 525)        -- Dealer: 7
        end

        cardTexture:SetTexture("Interface\\AddOns\\BJPlayer\\Images\\" .. cardName)
        cardTexture:SetDrawLayer("OVERLAY")

        -- Increment the turn counter
        turn = turn + 1
    end
end

-- Function to add a drawn card to the player's cards and display it
local function P15(cardName)
    if cardName and cardNames[cardName] then
        local cardTexture = playerFrame:CreateTexture(nil, "OVERLAY")
        cardTexture:SetSize(32, 64)
        table.insert(drawnCards, cardTexture)  -- Store the texture in the table

        -- Position the card based on the turn count
        if turn == 0 then 
            cardTexture:SetPoint("BOTTOM", playerFrame, 296, 428)       -- Player 1: 1
        elseif turn == 1 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -285, 429)      -- Player 5: 1
        elseif turn == 2 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 0, 525)         -- Dealer: 1
        elseif turn == 3 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 286, 438)       -- Player 1: 2
        elseif turn == 4 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -275, 439)      -- Player 5: 2
        elseif turn == 5 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 276, 448)       -- Player 1: 3
        elseif turn == 6 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 266, 458)       -- Player 1: 4
        elseif turn == 7 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 256, 468)       -- Player 1: 5
        elseif turn == 8 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 246, 478)       -- Player 1: 6
        elseif turn == 9 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 236, 488)       -- Player 1: 7
        elseif turn == 10 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 276, 448)       -- Player 1: Double
        elseif turn == 11 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -265, 449)      -- Player 5: 3
        elseif turn == 12 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -255, 459)      -- Player 5: 4
        elseif turn == 13 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -245, 469)      -- Player 5: 5
        elseif turn == 14 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -235, 479)      -- Player 5: 6
        elseif turn == 15 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -225, 489)      -- Player 5: 7
        elseif turn == 16 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -265, 449)      -- Player 5: Double
        elseif turn == 17 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 12, 525)        -- Dealer: 2
        elseif turn == 18 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 24, 525)        -- Dealer: 3
        elseif turn == 19 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 36, 525)        -- Dealer: 4
        elseif turn == 20 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 48, 525)        -- Dealer: 5
        elseif turn == 21 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 60, 525)        -- Dealer: 6
        elseif turn == 22 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 72, 525)        -- Dealer: 7
        end

        cardTexture:SetTexture("Interface\\AddOns\\BJPlayer\\Images\\" .. cardName)
        cardTexture:SetDrawLayer("OVERLAY")

        -- Increment the turn counter
        turn = turn + 1
    end
end

-- Function to add a drawn card to the player's cards and display it
local function P14(cardName)
    if cardName and cardNames[cardName] then
        local cardTexture = playerFrame:CreateTexture(nil, "OVERLAY")
        cardTexture:SetSize(32, 64)
        table.insert(drawnCards, cardTexture)  -- Store the texture in the table

        -- Position the card based on the turn count
        if turn == 0 then 
            cardTexture:SetPoint("BOTTOM", playerFrame, 296, 428)       -- Player 1: 1
        elseif turn == 1 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -160, 337)      -- Player 4: 1
        elseif turn == 2 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 0, 525)         -- Dealer: 1
        elseif turn == 3 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 286, 438)       -- Player 1: 2
        elseif turn == 4 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -150, 347)      -- Player 4: 2
        elseif turn == 5 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 276, 448)       -- Player 1: 3
        elseif turn == 6 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 266, 458)       -- Player 1: 4
        elseif turn == 7 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 256, 468)       -- Player 1: 5
        elseif turn == 8 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 246, 478)       -- Player 1: 6
        elseif turn == 9 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 236, 488)       -- Player 1: 7
        elseif turn == 10 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 276, 448)       -- Player 1: Double
        elseif turn == 11 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -140, 357)      -- Player 4: 3
        elseif turn == 12 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -130, 367)      -- Player 4: 4
        elseif turn == 13 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -120, 377)      -- Player 4: 5
        elseif turn == 14 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -110, 387)      -- Player 4: 6
        elseif turn == 15 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -100, 397)      -- Player 4: 7
        elseif turn == 16 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -140, 357)      -- Player 4: Double
        elseif turn == 17 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 12, 525)        -- Dealer: 2
        elseif turn == 18 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 24, 525)        -- Dealer: 3
        elseif turn == 19 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 36, 525)        -- Dealer: 4
        elseif turn == 20 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 48, 525)        -- Dealer: 5
        elseif turn == 21 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 60, 525)        -- Dealer: 6
        elseif turn == 22 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 72, 525)        -- Dealer: 7
        end

        cardTexture:SetTexture("Interface\\AddOns\\BJPlayer\\Images\\" .. cardName)
        cardTexture:SetDrawLayer("OVERLAY")

        -- Increment the turn counter
        turn = turn + 1
    end
end

-- Function to add a drawn card to the player's cards and display it
local function P13(cardName)
    if cardName and cardNames[cardName] then
        local cardTexture = playerFrame:CreateTexture(nil, "OVERLAY")
        cardTexture:SetSize(32, 64)
        table.insert(drawnCards, cardTexture)  -- Store the texture in the table

        -- Position the card based on the turn count
        if turn == 0 then 
            cardTexture:SetPoint("BOTTOM", playerFrame, 296, 428)       -- Player 1: 1
        elseif turn == 1 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 300)         -- Player 3: 1
        elseif turn == 2 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 0, 525)         -- Dealer: 1
        elseif turn == 3 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 286, 438)       -- Player 1: 2
        elseif turn == 4 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 315)         -- Player 3: 2
        elseif turn == 5 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 276, 448)       -- Player 1: 3
        elseif turn == 6 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 266, 458)       -- Player 1: 4
        elseif turn == 7 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 256, 468)       -- Player 1: 5
        elseif turn == 8 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 246, 478)       -- Player 1: 6
        elseif turn == 9 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 236, 488)       -- Player 1: 7
        elseif turn == 10 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 276, 448)       -- Player 1: Double
        elseif turn == 11 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 330)         -- Player 3: 3
        elseif turn == 12 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 345)         -- Player 3: 4
        elseif turn == 13 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 360)         -- Player 3: 5
        elseif turn == 14 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 375)         -- Player 3: 6
        elseif turn == 15 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 390)         -- Player 3: 7
        elseif turn == 16 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 330)         -- Player 3: Double
        elseif turn == 17 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 12, 525)        -- Dealer: 2
        elseif turn == 18 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 24, 525)        -- Dealer: 3
        elseif turn == 19 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 36, 525)        -- Dealer: 4
        elseif turn == 20 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 48, 525)        -- Dealer: 5
        elseif turn == 21 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 60, 525)        -- Dealer: 6
        elseif turn == 22 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 72, 525)        -- Dealer: 7
        end

        cardTexture:SetTexture("Interface\\AddOns\\BJPlayer\\Images\\" .. cardName)
        cardTexture:SetDrawLayer("OVERLAY")

        -- Increment the turn counter
        turn = turn + 1
    end
end

-- Function to add a drawn card to the player's cards and display it
local function P12(cardName)
    if cardName and cardNames[cardName] then
        local cardTexture = playerFrame:CreateTexture(nil, "OVERLAY")
        cardTexture:SetSize(32, 64)
        table.insert(drawnCards, cardTexture)  -- Store the texture in the table
        table.insert(dealtCards, cardNames[cardName])

        -- Position the card based on the turn count
        if turn == 0 then 
            cardTexture:SetPoint("BOTTOM", playerFrame, 296, 428)       -- Player 1: 1
        elseif turn == 1 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 165, 337)       -- Player 2: 1
        elseif turn == 2 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 0, 525)         -- Dealer: 1
        elseif turn == 3 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 286, 438)       -- Player 1: 2
        elseif turn == 4 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 155, 347)       -- Player 2: 2
        elseif turn == 5 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 276, 448)       -- Player 1: 3
        elseif turn == 6 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 266, 458)       -- Player 1: 4
        elseif turn == 7 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 256, 468)       -- Player 1: 5
        elseif turn == 8 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 246, 478)       -- Player 1: 6
        elseif turn == 9 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 236, 488)       -- Player 1: 7
        elseif turn == 10 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 276, 448)       -- Player 1: Double
        elseif turn == 11 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 145, 357)       -- Player 2: 3
        elseif turn == 12 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 135, 367)       -- Player 2: 4
        elseif turn == 13 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 125, 377)       -- Player 2: 5
        elseif turn == 14 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 115, 387)       -- Player 2: 6
        elseif turn == 15 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 105, 397)       -- Player 2: 7
        elseif turn == 16 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 145, 357)       -- Player 2: Double
        elseif turn == 17 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 12, 525)        -- Dealer: 2
        elseif turn == 18 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 24, 525)        -- Dealer: 3
        elseif turn == 19 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 36, 525)        -- Dealer: 4
        elseif turn == 20 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 48, 525)        -- Dealer: 5
        elseif turn == 21 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 60, 525)        -- Dealer: 6
        elseif turn == 22 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 72, 525)        -- Dealer: 7
        end

        cardTexture:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. cardName)
        cardTexture:SetDrawLayer("OVERLAY")

        -- Increment the turn counter
        turn = turn + 1
    end
end

-- Function to add a drawn card to the player's cards and display it
local function P5(cardName)
    if cardName and cardNames[cardName] then
        local cardTexture = playerFrame:CreateTexture(nil, "OVERLAY")
        cardTexture:SetSize(32, 64)
        table.insert(drawnCards, cardTexture)  -- Store the texture in the table

        -- Position the card based on the turn count
        if turn == 0 then 
            cardTexture:SetPoint("BOTTOM", playerFrame, -285, 429)      -- Player 5: 1
        elseif turn == 1 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 0, 525)         -- Dealer: 1
        elseif turn == 2 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -275, 439)      -- Player 5: 2
        elseif turn == 3 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -265, 449)      -- Player 5: 3
        elseif turn == 4 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -255, 459)      -- Player 5: 4
        elseif turn == 5 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -245, 469)      -- Player 5: 5
        elseif turn == 6 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -235, 479)      -- Player 5: 6
        elseif turn == 7 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -225, 489)      -- Player 5: 7
        elseif turn == 8 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -265, 449)      -- Player 5: Double
        elseif turn == 9 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 12, 525)        -- Dealer: 2
        elseif turn == 10 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 24, 525)        -- Dealer: 3
        elseif turn == 11 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 36, 525)        -- Dealer: 4
        elseif turn == 12 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 48, 525)        -- Dealer: 5
        elseif turn == 13 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 60, 525)        -- Dealer: 6
        elseif turn == 14 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 72, 525)        -- Dealer: 7
        end

        cardTexture:SetTexture("Interface\\AddOns\\BJPlayer\\Images\\" .. cardName)
        cardTexture:SetDrawLayer("OVERLAY")

        -- Increment the turn counter
        turn = turn + 1
    end
end

-- Function to add a drawn card to the player's cards and display it
local function P4(cardName)
    if cardName and cardNames[cardName] then
        local cardTexture = playerFrame:CreateTexture(nil, "OVERLAY")
        cardTexture:SetSize(32, 64)
        table.insert(drawnCards, cardTexture)  -- Store the texture in the table

        -- Position the card based on the turn count
        if turn == 0 then 
            cardTexture:SetPoint("BOTTOM", playerFrame, -160, 337)      -- Player 4: 1
        elseif turn == 1 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 0, 525)         -- Dealer: 1
        elseif turn == 2 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -150, 347)      -- Player 4: 2
        elseif turn == 3 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -140, 357)      -- Player 4: 3
        elseif turn == 4 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -130, 367)      -- Player 4: 4
        elseif turn == 5 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -120, 377)      -- Player 4: 5
        elseif turn == 6 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -110, 387)      -- Player 4: 6
        elseif turn == 7 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -100, 397)      -- Player 4: 7
        elseif turn == 8 then
            cardTexture:SetPoint("BOTTOM", playerFrame, -140, 357)      -- Player 4: Double
        elseif turn == 9 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 12, 525)        -- Dealer: 2
        elseif turn == 10 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 24, 525)        -- Dealer: 3
        elseif turn == 11 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 36, 525)        -- Dealer: 4
        elseif turn == 12 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 48, 525)        -- Dealer: 5
        elseif turn == 13 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 60, 525)        -- Dealer: 6
        elseif turn == 14 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 72, 525)        -- Dealer: 7
        end

        cardTexture:SetTexture("Interface\\AddOns\\BJPlayer\\Images\\" .. cardName)
        cardTexture:SetDrawLayer("OVERLAY")

        -- Increment the turn counter
        turn = turn + 1
    end
end

-- Function to add a drawn card to the player's cards and display it
local function P3(cardName)
    if cardName and cardNames[cardName] then
        local cardTexture = playerFrame:CreateTexture(nil, "OVERLAY")
        cardTexture:SetSize(32, 64)
        table.insert(drawnCards, cardTexture)  -- Store the texture in the table

        -- Position the card based on the turn count
        if turn == 0 then 
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 300)         -- Player 3: 1
        elseif turn == 1 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 0, 525)         -- Dealer: 1
        elseif turn == 2 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 315)         -- Player 3: 2
        elseif turn == 3 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 330)         -- Player 3: 3
        elseif turn == 4 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 345)         -- Player 3: 4
        elseif turn == 5 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 360)         -- Player 3: 5
        elseif turn == 6 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 375)         -- Player 3: 6
        elseif turn == 7 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 390)         -- Player 3: 7
        elseif turn == 8 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 3, 330)         -- Player 3: Double
        elseif turn == 9 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 12, 525)        -- Dealer: 2
        elseif turn == 10 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 24, 525)        -- Dealer: 3
        elseif turn == 11 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 36, 525)        -- Dealer: 4
        elseif turn == 12 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 48, 525)        -- Dealer: 5
        elseif turn == 13 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 60, 525)        -- Dealer: 6
        elseif turn == 14 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 72, 525)        -- Dealer: 7
        end

        cardTexture:SetTexture("Interface\\AddOns\\BJPlayer\\Images\\" .. cardName)
        cardTexture:SetDrawLayer("OVERLAY")

        -- Increment the turn counter
        turn = turn + 1
    end
end

-- Function to add a drawn card to the player's cards and display it
local function P2(cardName)
    if cardName and cardNames[cardName] then
        local cardTexture = playerFrame:CreateTexture(nil, "OVERLAY")
        cardTexture:SetSize(32, 64)
        table.insert(drawnCards, cardTexture)  -- Store the texture in the table

        -- Position the card based on the turn count
        if turn == 0 then 
            cardTexture:SetPoint("BOTTOM", playerFrame, 165, 337)       -- Player 2: 1
        elseif turn == 1 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 0, 525)         -- Dealer: 1
        elseif turn == 2 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 155, 347)       -- Player 2: 2
        elseif turn == 3 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 145, 357)       -- Player 2: 3
        elseif turn == 4 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 135, 367)       -- Player 2: 4
        elseif turn == 5 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 125, 377)       -- Player 2: 5
        elseif turn == 6 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 115, 387)       -- Player 2: 6
        elseif turn == 7 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 105, 397)       -- Player 2: 7
        elseif turn == 8 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 145, 357)       -- Player 2: Double
        elseif turn == 9 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 12, 525)        -- Dealer: 2
        elseif turn == 10 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 24, 525)        -- Dealer: 3
        elseif turn == 11 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 36, 525)        -- Dealer: 4
        elseif turn == 12 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 48, 525)        -- Dealer: 5
        elseif turn == 13 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 60, 525)        -- Dealer: 6
        elseif turn == 14 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 72, 525)        -- Dealer: 7
        end

        cardTexture:SetTexture("Interface\\AddOns\\BJPlayer\\Images\\" .. cardName)
        cardTexture:SetDrawLayer("OVERLAY")

        -- Increment the turn counter
        turn = turn + 1
    end
end

-- Function to add a drawn card to the player's cards and display it
local function P1(cardName)
    if cardName and cardNames[cardName] then
        local cardTexture = playerFrame:CreateTexture(nil, "OVERLAY")
        cardTexture:SetSize(32, 64)
        table.insert(drawnCards, cardTexture)  -- Store the texture in the table
        table.insert(dealtCards, cardNames[cardName])

        -- Position the card based on the turn count
        if turn == 0 then 
            cardTexture:SetPoint("BOTTOM", playerFrame, 296, 428)       -- Player 1: 1st Card
        elseif turn == 1 then
            cardTexture:SetSize(45, 90)
            cardTexture:SetPoint("BOTTOM", playerFrame, 0, 500)         -- Dealer: 1st Card
        elseif turn == 2 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 286, 438)       -- Player 1: 2nd Card
        elseif turn == 3 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 276, 448)       -- Player 1: 3rd Card
        elseif turn == 4 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 266, 458)       -- Player 1: 4th Card
        elseif turn == 5 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 256, 468)       -- Player 1: 5th Card
        elseif turn == 6 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 246, 478)       -- Player 1: 6th Card
        elseif turn == 7 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 236, 488)       -- Player 1: 7th Card
        elseif turn == 8 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 292, 464)       -- Player 1: 2nd Card (Split H1)
        elseif turn == 9 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 255, 445)       -- Player 1: 2nd Card (Split H2)
        elseif turn == 10 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 282, 474)       -- Player 1: 3rd Card (Split H1)
        elseif turn == 11 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 272, 484)       -- Player 1: 4th Card (Split H1)
        elseif turn == 12 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 262, 494)       -- Player 1: 5th Card (Split H1)
        elseif turn == 13 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 252, 504)       -- Player 1: 6th Card (Split H1)
        elseif turn == 14 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 242, 514)       -- Player 1: 7th Card (Split H1)
        elseif turn == 15 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 282, 474)       -- Player 1: 3rd Card (Double) (Split H1)
        elseif turn == 16 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 245, 455)       -- Player 1: 3rd Card (Split H2)
        elseif turn == 17 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 235, 465)       -- Player 1: 4th Card (Split H2)
        elseif turn == 18 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 225, 475)       -- Player 1: 5th Card (Split H2)
        elseif turn == 19 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 215, 485)       -- Player 1: 6th Card (Split H2)
        elseif turn == 20 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 205, 495)       -- Player 1: 7th Card (Split H2)
        elseif turn == 21 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 245, 455)       -- Player 1: 3rd Card (Double) (Split H2)
        elseif turn == 22 then
            cardTexture:SetPoint("BOTTOM", playerFrame, 276, 448)       -- Player 1: 3rd Card (Double)
        elseif turn == 23 then
            cardTexture:SetSize(45, 90)
            cardTexture:SetPoint("BOTTOM", playerFrame, 20, 500)        -- Dealer: 2nd Card
        elseif turn == 24 then
            cardTexture:SetSize(45, 90)
            cardTexture:SetPoint("BOTTOM", playerFrame, 40, 500)        -- Dealer: 3rd Card
        elseif turn == 25 then
            cardTexture:SetSize(45, 90)
            cardTexture:SetPoint("BOTTOM", playerFrame, 60, 500)        -- Dealer: 4th Card
        elseif turn == 26 then
            cardTexture:SetSize(45, 90)
            cardTexture:SetPoint("BOTTOM", playerFrame, 80, 500)        -- Dealer: 5th Card
        elseif turn == 27 then
            cardTexture:SetSize(45, 90)
            cardTexture:SetPoint("BOTTOM", playerFrame, 100, 500)        -- Dealer: 6th Card
        elseif turn == 28 then
            cardTexture:SetSize(45, 90)
            cardTexture:SetPoint("BOTTOM", playerFrame, 120, 500)        -- Dealer: 7th Card
        end

        cardTexture:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. cardName)
        cardTexture:SetDrawLayer("OVERLAY")

        if turn == 21 then
            turn = 23
        else
            turn = turn + 1
        end
    end
end



























local function Player1Card1(message)
    number = string.find(message, "(%d+)")
    if string.find(message, "1 or 11") then
        playerFrame.player1CardTotalText:SetText("1 or 11")
        PlaySoundFile(soundFilePaths[22])
    elseif number >= 2 and number <= 10 then
        playerFrame.player1CardTotalText:SetText(number)
        PlaySoundFile(soundFilePaths[number])
    end
end


local function Player1Card2to8(message)
    local soundIndex = Player1Total + number
    if soundIndex >= 2 and soundIndex <= 21 then
        PlaySoundFile(soundFilePaths[soundIndex])
    elseif soundIndex >= 22 then
        PlaySoundFile(soundFilePaths[48])
        playerFrame.player1CardTotalText:SetText(soundIndex)
        playerFrame.player1CardTotalText:SetTextColor(1, 0, 0)
    end
end


local function Player2Card1(message)
    if string.find(message, "1 or 11") then
        playerFrame.player2CardTotalText:SetText("1 or 11")
        PlaySoundFile(soundFilePaths[22])
    elseif number >= 2 and number <= 10 then
        playerFrame.player2CardTotalText:SetText(number)
        PlaySoundFile(soundFilePaths[number])
    end
end

local function Player2Card2to8(message)
    local soundIndex = Player2Total + number
    if string.find(message, unitName2) and string.find(message, "has Blackjack") then
        PlaySoundFile(soundFilePaths[53])
        playerFrame.player2CardTotalText:SetText("Blackjack")
        playerFrame.player2CardTotalText:SetTextColor(1, 1, 0)
    elseif soundIndex >= 2 and soundIndex <= 21 then
        PlaySoundFile(soundFilePaths[soundIndex])
    elseif soundIndex >= 22 then
        PlaySoundFile(soundFilePaths[49])
        playerFrame.player2CardTotalText:SetText(soundIndex)
        playerFrame.player2CardTotalText:SetTextColor(1, 0, 0)
    end
end

local Player1Total = 0
local Player2Total = 0
local DealerTotal = 0


-- Function to handle incoming chat messages
local function HandleCardsP1(message)
    -- Check if the message contains card names
    for cardName, cardFullName in pairs(cardNames) do
        playerFrame.player1CardTotalText:Show()
        playerFrame.dealerCardTotalText:Show()
        if string.find(message, cardFullName) then
            P1(cardName)
        end
    end

    local _, _, number = string.find(message, "(%d+)")

    if turn == 1 then
        if string.find(message, "1 or 11") then
            PlaySoundFile(soundFilePaths[22])
            playerFrame.player1CardTotalText:SetText("1 or 11")
        elseif string.find(message, "2") then
            PlaySoundFile(soundFilePaths[2])
            playerFrame.player1CardTotalText:SetText("2")
        elseif string.find(message, "3") then
            PlaySoundFile(soundFilePaths[3])
            playerFrame.player1CardTotalText:SetText("3")
        elseif string.find(message, "4") then
            PlaySoundFile(soundFilePaths[4])
            playerFrame.player1CardTotalText:SetText("4")
        elseif string.find(message, "5") then
            PlaySoundFile(soundFilePaths[5])
            playerFrame.player1CardTotalText:SetText("5")
        elseif string.find(message, "6") then
            PlaySoundFile(soundFilePaths[6])
            playerFrame.player1CardTotalText:SetText("6")
        elseif string.find(message, "7") then
            PlaySoundFile(soundFilePaths[7])
            playerFrame.player1CardTotalText:SetText("7")
        elseif string.find(message, "8") then
            PlaySoundFile(soundFilePaths[8])
            playerFrame.player1CardTotalText:SetText("8")
        elseif string.find(message, "9") then
            PlaySoundFile(soundFilePaths[9])
            playerFrame.player1CardTotalText:SetText("9")
        elseif string.find(message, "10") then
            PlaySoundFile(soundFilePaths[10])
            playerFrame.player1CardTotalText:SetText("10")
        end
    elseif string.find(message, unitName1) and string.find(message, "has") then
        if turn == 3 or turn == 4 or turn == 5 or turn == 6 or turn == 7 or turn == 8 or turn == 23 and not string.find(message, "Hand 2") then
            if string.find(message, "Blackjack") then
                PlaySoundFile(soundFilePaths[52])
                playerFrame.player1CardTotalText:SetText("Blackjack")
                playerFrame.player1CardTotalText:SetTextColor(1, 1, 0)
                turn = 23 -- Skip to Dealer 2nd Card
            elseif string.find(message, "2 or 12") then
                PlaySoundFile(soundFilePaths[23])
                playerFrame.player1CardTotalText:SetText("2 or 12")
            elseif string.find(message, "3 or 13") then
                PlaySoundFile(soundFilePaths[24])
                playerFrame.player1CardTotalText:SetText("3 or 13")
            elseif string.find(message, "4 or 14") then
                PlaySoundFile(soundFilePaths[25])
                playerFrame.player1CardTotalText:SetText("4 or 14")
            elseif string.find(message, "5 or 15") then
                PlaySoundFile(soundFilePaths[26])
                playerFrame.player1CardTotalText:SetText("5 or 15")
            elseif string.find(message, "6 or 16") then
                PlaySoundFile(soundFilePaths[27])
                playerFrame.player1CardTotalText:SetText("6 or 16")
            elseif string.find(message, "7 or 17") then
                PlaySoundFile(soundFilePaths[28])
                playerFrame.player1CardTotalText:SetText("7 or 17")
            elseif string.find(message, "8 or 18") then
                PlaySoundFile(soundFilePaths[29])
                playerFrame.player1CardTotalText:SetText("8 or 18")
            elseif string.find(message, "9 or 19") then
                PlaySoundFile(soundFilePaths[30])
                playerFrame.player1CardTotalText:SetText("9 or 19")
            elseif string.find(message, "10 or 20") then
                PlaySoundFile(soundFilePaths[31])
                playerFrame.player1CardTotalText:SetText("10 or 20")
            elseif string.find(message, "14") then
                PlaySoundFile(soundFilePaths[14])
                playerFrame.player1CardTotalText:SetText("14")
            elseif string.find(message, "15") then
                PlaySoundFile(soundFilePaths[15])
                playerFrame.player1CardTotalText:SetText("15")
            elseif string.find(message, "16") then
                PlaySoundFile(soundFilePaths[16])
                playerFrame.player1CardTotalText:SetText("16")
            elseif string.find(message, "17") then
                PlaySoundFile(soundFilePaths[17])
                playerFrame.player1CardTotalText:SetText("17")
            elseif string.find(message, "18") then
                PlaySoundFile(soundFilePaths[18])
                playerFrame.player1CardTotalText:SetText("18")
            elseif string.find(message, "19") then
                PlaySoundFile(soundFilePaths[19])
                playerFrame.player1CardTotalText:SetText("19")
            elseif string.find(message, "20") then
                PlaySoundFile(soundFilePaths[20])
                playerFrame.player1CardTotalText:SetText("20")
            elseif string.find(message, "21") then
                PlaySoundFile(soundFilePaths[21])
                playerFrame.player1CardTotalText:SetText("21")
                turn = 23 -- Skip to Dealer 2nd Card
            elseif string.find(message, "22") then
                PlaySoundFile(soundFilePaths[48])
                playerFrame.player1CardTotalText:SetText("22")
                playerFrame.player1CardTotalText:SetTextColor(1, 0, 0)
            elseif string.find(message, "23") then
                PlaySoundFile(soundFilePaths[48])
                playerFrame.player1CardTotalText:SetText("23")
                playerFrame.player1CardTotalText:SetTextColor(1, 0, 0)
            elseif string.find(message, "24") then
                PlaySoundFile(soundFilePaths[48])
                playerFrame.player1CardTotalText:SetText("24")
                playerFrame.player1CardTotalText:SetTextColor(1, 0, 0)
            elseif string.find(message, "25") then
                PlaySoundFile(soundFilePaths[48])
                playerFrame.player1CardTotalText:SetText("25")
                playerFrame.player1CardTotalText:SetTextColor(1, 0, 0)
            elseif string.find(message, "26") then
                PlaySoundFile(soundFilePaths[48])
                playerFrame.player1CardTotalText:SetText("26")
                playerFrame.player1CardTotalText:SetTextColor(1, 0, 0)
            elseif string.find(message, "27") then
                PlaySoundFile(soundFilePaths[48])
                playerFrame.player1CardTotalText:SetText("27")
                playerFrame.player1CardTotalText:SetTextColor(1, 0, 0)
            elseif string.find(message, "28") then
                PlaySoundFile(soundFilePaths[48])
                playerFrame.player1CardTotalText:SetText("28")
                playerFrame.player1CardTotalText:SetTextColor(1, 0, 0)
            elseif string.find(message, "29") then
                PlaySoundFile(soundFilePaths[48])
                playerFrame.player1CardTotalText:SetText("29")
                playerFrame.player1CardTotalText:SetTextColor(1, 0, 0)
            elseif string.find(message, "30") then
                PlaySoundFile(soundFilePaths[48])
                playerFrame.player1CardTotalText:SetText("30")
                playerFrame.player1CardTotalText:SetTextColor(1, 0, 0)
            elseif string.find(message, "4") then
                PlaySoundFile(soundFilePaths[4])
                playerFrame.player1CardTotalText:SetText("4")
            elseif string.find(message, "5") then
                PlaySoundFile(soundFilePaths[5])
                playerFrame.player1CardTotalText:SetText("5")
            elseif string.find(message, "6") then
                PlaySoundFile(soundFilePaths[6])
                playerFrame.player1CardTotalText:SetText("6")
            elseif string.find(message, "7") then
                PlaySoundFile(soundFilePaths[7])
                playerFrame.player1CardTotalText:SetText("7")
            elseif string.find(message, "8") then
                PlaySoundFile(soundFilePaths[8])
                playerFrame.player1CardTotalText:SetText("8")
            elseif string.find(message, "9") then
                PlaySoundFile(soundFilePaths[9])
                playerFrame.player1CardTotalText:SetText("9")
            elseif string.find(message, "10") then
                PlaySoundFile(soundFilePaths[10])
                playerFrame.player1CardTotalText:SetText("10")
            elseif string.find(message, "11") then
                PlaySoundFile(soundFilePaths[11])
                playerFrame.player1CardTotalText:SetText("11")
            elseif string.find(message, "12") then
                PlaySoundFile(soundFilePaths[12])
                playerFrame.player1CardTotalText:SetText("12")
            elseif string.find(message, "13") then
                PlaySoundFile(soundFilePaths[13])
                playerFrame.player1CardTotalText:SetText("13")
            end
        elseif turn == 9 or turn == 11 or turn == 12 or turn == 13 or turn == 14 or turn == 15 or turn == 16 then
            if string.find(message, "2 or 12") then
                PlaySoundFile(soundFilePaths[23])
                playerFrame.player1SplitHand1CardTotalText:SetText("2 or 12")
            elseif string.find(message, "3 or 13") then
                PlaySoundFile(soundFilePaths[24])
                playerFrame.player1SplitHand1CardTotalText:SetText("3 or 13")
            elseif string.find(message, "4 or 14") then
                PlaySoundFile(soundFilePaths[25])
                playerFrame.player1SplitHand1CardTotalText:SetText("4 or 14")
            elseif string.find(message, "5 or 15") then
                PlaySoundFile(soundFilePaths[26])
                playerFrame.player1SplitHand1CardTotalText:SetText("5 or 15")
            elseif string.find(message, "6 or 16") then
                PlaySoundFile(soundFilePaths[27])
                playerFrame.player1SplitHand1CardTotalText:SetText("6 or 16")
            elseif string.find(message, "7 or 17") then
                PlaySoundFile(soundFilePaths[28])
                playerFrame.player1SplitHand1CardTotalText:SetText("7 or 17")
            elseif string.find(message, "8 or 18") then
                PlaySoundFile(soundFilePaths[29])
                playerFrame.player1SplitHand1CardTotalText:SetText("8 or 18")
            elseif string.find(message, "9 or 19") then
                PlaySoundFile(soundFilePaths[30])
                playerFrame.player1SplitHand1CardTotalText:SetText("9 or 19")
            elseif string.find(message, "10 or 20") then
                PlaySoundFile(soundFilePaths[31])
                playerFrame.player1SplitHand1CardTotalText:SetText("10 or 20")
            elseif string.find(message, "14") then
                PlaySoundFile(soundFilePaths[14])
                playerFrame.player1SplitHand1CardTotalText:SetText("14")
            elseif string.find(message, "15") then
                PlaySoundFile(soundFilePaths[15])
                playerFrame.player1SplitHand1CardTotalText:SetText("15")
            elseif string.find(message, "16") then
                PlaySoundFile(soundFilePaths[16])
                playerFrame.player1SplitHand1CardTotalText:SetText("16")
            elseif string.find(message, "17") then
                PlaySoundFile(soundFilePaths[17])
                playerFrame.player1SplitHand1CardTotalText:SetText("17")
            elseif string.find(message, "18") then
                PlaySoundFile(soundFilePaths[18])
                playerFrame.player1SplitHand1CardTotalText:SetText("18")
            elseif string.find(message, "19") then
                PlaySoundFile(soundFilePaths[19])
                playerFrame.player1SplitHand1CardTotalText:SetText("19")
            elseif string.find(message, "20") then
                PlaySoundFile(soundFilePaths[20])
                playerFrame.player1SplitHand1CardTotalText:SetText("20")
            elseif string.find(message, "21") then
                PlaySoundFile(soundFilePaths[21])
                playerFrame.player1SplitHand1CardTotalText:SetText("21")
                if playerFrame.player1SplitHand2CardTotalText:GetText() == "Blackjack" then
                    turn = 23 -- Skip to Dealer 2nd Card
                else
                    turn = 16 -- Skip to Player 1 3rd Card (Hand 2)
                end
            elseif string.find(message, "22") then
                playerFrame.player1SplitHand1CardTotalText:SetText("22")
                playerFrame.player1SplitHand1CardTotalText:SetTextColor(1, 0, 0)
                if playerFrame.player1SplitHand2CardTotalText:GetText() == "Blackjack" then
                    turn = 23 -- Skip to Dealer 2nd Card
                else
                    turn = 16 -- Skip to Player 1 3rd Card (Hand 2)
                end
            elseif string.find(message, "23") then
                playerFrame.player1SplitHand1CardTotalText:SetText("23")
                playerFrame.player1SplitHand1CardTotalText:SetTextColor(1, 0, 0)
                if playerFrame.player1SplitHand2CardTotalText:GetText() == "Blackjack" then
                    turn = 23 -- Skip to Dealer 2nd Card
                else
                    turn = 16 -- Skip to Player 1 3rd Card (Hand 2)
                end
            elseif string.find(message, "24") then
                playerFrame.player1SplitHand1CardTotalText:SetText("24")
                playerFrame.player1SplitHand1CardTotalText:SetTextColor(1, 0, 0)
                if playerFrame.player1SplitHand2CardTotalText:GetText() == "Blackjack" then
                    turn = 23 -- Skip to Dealer 2nd Card
                else
                    turn = 16 -- Skip to Player 1 3rd Card (Hand 2)
                end
            elseif string.find(message, "25") then
                playerFrame.player1SplitHand1CardTotalText:SetText("25")
                playerFrame.player1SplitHand1CardTotalText:SetTextColor(1, 0, 0)
                if playerFrame.player1SplitHand2CardTotalText:GetText() == "Blackjack" then
                    turn = 23 -- Skip to Dealer 2nd Card
                else
                    turn = 16 -- Skip to Player 1 3rd Card (Hand 2)
                end
            elseif string.find(message, "26") then
                playerFrame.player1SplitHand1CardTotalText:SetText("26")
                playerFrame.player1SplitHand1CardTotalText:SetTextColor(1, 0, 0)
                if playerFrame.player1SplitHand2CardTotalText:GetText() == "Blackjack" then
                    turn = 23 -- Skip to Dealer 2nd Card
                else
                    turn = 16 -- Skip to Player 1 3rd Card (Hand 2)
                end
            elseif string.find(message, "27") then
                playerFrame.player1SplitHand1CardTotalText:SetText("27")
                playerFrame.player1SplitHand1CardTotalText:SetTextColor(1, 0, 0)
                if playerFrame.player1SplitHand2CardTotalText:GetText() == "Blackjack" then
                    turn = 23 -- Skip to Dealer 2nd Card
                else
                    turn = 16 -- Skip to Player 1 3rd Card (Hand 2)
                end
            elseif string.find(message, "28") then
                playerFrame.player1SplitHand1CardTotalText:SetText("28")
                playerFrame.player1SplitHand1CardTotalText:SetTextColor(1, 0, 0)
                if playerFrame.player1SplitHand2CardTotalText:GetText() == "Blackjack" then
                    turn = 23 -- Skip to Dealer 2nd Card
                else
                    turn = 16 -- Skip to Player 1 3rd Card (Hand 2)
                end
            elseif string.find(message, "29") then
                playerFrame.player1SplitHand1CardTotalText:SetText("29")
                playerFrame.player1SplitHand1CardTotalText:SetTextColor(1, 0, 0)
                if playerFrame.player1SplitHand2CardTotalText:GetText() == "Blackjack" then
                    turn = 23 -- Skip to Dealer 2nd Card
                else
                    turn = 16 -- Skip to Player 1 3rd Card (Hand 2)
                end
            elseif string.find(message, "30") then
                playerFrame.player1SplitHand1CardTotalText:SetText("30")
                playerFrame.player1SplitHand1CardTotalText:SetTextColor(1, 0, 0)
                if playerFrame.player1SplitHand2CardTotalText:GetText() == "Blackjack" then
                    turn = 23 -- Skip to Dealer 2nd Card
                else
                    turn = 16 -- Skip to Player 1 3rd Card (Hand 2)
                end
            elseif string.find(message, "4") then
                PlaySoundFile(soundFilePaths[4])
                playerFrame.player1SplitHand1CardTotalText:SetText("4")
            elseif string.find(message, "5") then
                PlaySoundFile(soundFilePaths[5])
                playerFrame.player1SplitHand1CardTotalText:SetText("5")
            elseif string.find(message, "6") then
                PlaySoundFile(soundFilePaths[6])
                playerFrame.player1SplitHand1CardTotalText:SetText("6")
            elseif string.find(message, "7") then
                PlaySoundFile(soundFilePaths[7])
                playerFrame.player1SplitHand1CardTotalText:SetText("7")
            elseif string.find(message, "8") then
                PlaySoundFile(soundFilePaths[8])
                playerFrame.player1SplitHand1CardTotalText:SetText("8")
            elseif string.find(message, "9") then
                PlaySoundFile(soundFilePaths[9])
                playerFrame.player1SplitHand1CardTotalText:SetText("9")
            elseif string.find(message, "10") then
                PlaySoundFile(soundFilePaths[10])
                playerFrame.player1SplitHand1CardTotalText:SetText("10")
            elseif string.find(message, "11") then
                PlaySoundFile(soundFilePaths[11])
                playerFrame.player1SplitHand1CardTotalText:SetText("11")
            elseif string.find(message, "12") then
                PlaySoundFile(soundFilePaths[12])
                playerFrame.player1SplitHand1CardTotalText:SetText("12")
            elseif string.find(message, "13") then
                PlaySoundFile(soundFilePaths[13])
                playerFrame.player1SplitHand1CardTotalText:SetText("13")
            elseif turn == 16 then
                if playerFrame.player1SplitHand2CardTotalText:GetText() == "Blackjack" then
                    turn = 23 -- Skip to Dealer 2nd Card
                else
                    turn = 16 -- Skip to Player 1 3rd Card (Hand 2)
                end
            end
        elseif turn == 10 or turn == 17 or turn == 18 or turn == 19 or turn == 20 or turn == 21 or turn == 23 and string.find(message, "Hand 2") then
            if string.find(message, "2 or 12") then
                PlaySoundFile(soundFilePaths[23])
                playerFrame.player1SplitHand2CardTotalText:SetText("2 or 12")
            elseif string.find(message, "3 or 13") then
                PlaySoundFile(soundFilePaths[24])
                playerFrame.player1SplitHand2CardTotalText:SetText("3 or 13")
            elseif string.find(message, "4 or 14") then
                PlaySoundFile(soundFilePaths[25])
                playerFrame.player1SplitHand2CardTotalText:SetText("4 or 14")
            elseif string.find(message, "5 or 15") then
                PlaySoundFile(soundFilePaths[26])
                playerFrame.player1SplitHand2CardTotalText:SetText("5 or 15")
            elseif string.find(message, "6 or 16") then
                PlaySoundFile(soundFilePaths[27])
                playerFrame.player1SplitHand2CardTotalText:SetText("6 or 16")
            elseif string.find(message, "7 or 17") then
                PlaySoundFile(soundFilePaths[28])
                playerFrame.player1SplitHand2CardTotalText:SetText("7 or 17")
            elseif string.find(message, "8 or 18") then
                PlaySoundFile(soundFilePaths[29])
                playerFrame.player1SplitHand2CardTotalText:SetText("8 or 18")
            elseif string.find(message, "9 or 19") then
                PlaySoundFile(soundFilePaths[30])
                playerFrame.player1SplitHand2CardTotalText:SetText("9 or 19")
            elseif string.find(message, "10 or 20") then
                PlaySoundFile(soundFilePaths[31])
                playerFrame.player1SplitHand2CardTotalText:SetText("10 or 20")
            elseif string.find(message, "14") then
                PlaySoundFile(soundFilePaths[14])
                playerFrame.player1SplitHand2CardTotalText:SetText("14")
            elseif string.find(message, "15") then
                PlaySoundFile(soundFilePaths[15])
                playerFrame.player1SplitHand2CardTotalText:SetText("15")
            elseif string.find(message, "16") then
                PlaySoundFile(soundFilePaths[16])
                playerFrame.player1SplitHand2CardTotalText:SetText("16")
            elseif string.find(message, "17") then
                PlaySoundFile(soundFilePaths[17])
                playerFrame.player1SplitHand2CardTotalText:SetText("17")
            elseif string.find(message, "18") then
                PlaySoundFile(soundFilePaths[18])
                playerFrame.player1SplitHand2CardTotalText:SetText("18")
            elseif string.find(message, "19") then
                PlaySoundFile(soundFilePaths[19])
                playerFrame.player1SplitHand2CardTotalText:SetText("19")
            elseif string.find(message, "20") then
                PlaySoundFile(soundFilePaths[20])
                playerFrame.player1SplitHand2CardTotalText:SetText("20")
            elseif string.find(message, "21") then
                PlaySoundFile(soundFilePaths[21])
                playerFrame.player1SplitHand2CardTotalText:SetText("21")
                turn = 23 -- Skip to Dealer 2nd Card
            elseif string.find(message, "22") then
                playerFrame.player1SplitHand2CardTotalText:SetText("22")
                playerFrame.player1SplitHand2CardTotalText:SetTextColor(1, 0, 0)
                turn = 23 -- Skip to Dealer 2nd Card
            elseif string.find(message, "23") then
                playerFrame.player1SplitHand2CardTotalText:SetText("23")
                playerFrame.player1SplitHand2CardTotalText:SetTextColor(1, 0, 0)
                turn = 23 -- Skip to Dealer 2nd Card
            elseif string.find(message, "24") then
                playerFrame.player1SplitHand2CardTotalText:SetText("24")
                playerFrame.player1SplitHand2CardTotalText:SetTextColor(1, 0, 0)
                turn = 23 -- Skip to Dealer 2nd Card
            elseif string.find(message, "25") then
                playerFrame.player1SplitHand2CardTotalText:SetText("25")
                playerFrame.player1SplitHand2CardTotalText:SetTextColor(1, 0, 0)
                turn = 23 -- Skip to Dealer 2nd Card
            elseif string.find(message, "26") then
                playerFrame.player1SplitHand2CardTotalText:SetText("26")
                playerFrame.player1SplitHand2CardTotalText:SetTextColor(1, 0, 0)
                turn = 23 -- Skip to Dealer 2nd Card
            elseif string.find(message, "27") then
                playerFrame.player1SplitHand2CardTotalText:SetText("27")
                playerFrame.player1SplitHand2CardTotalText:SetTextColor(1, 0, 0)
                turn = 23 -- Skip to Dealer 2nd Card
            elseif string.find(message, "28") then
                playerFrame.player1SplitHand2CardTotalText:SetText("28")
                playerFrame.player1SplitHand2CardTotalText:SetTextColor(1, 0, 0)
                turn = 23 -- Skip to Dealer 2nd Card
            elseif string.find(message, "29") then
                playerFrame.player1SplitHand2CardTotalText:SetText("29")
                playerFrame.player1SplitHand2CardTotalText:SetTextColor(1, 0, 0)
                turn = 23 -- Skip to Dealer 2nd Card
            elseif string.find(message, "30") then
                playerFrame.player1SplitHand2CardTotalText:SetText("30")
                playerFrame.player1SplitHand2CardTotalText:SetTextColor(1, 0, 0)
                turn = 23 -- Skip to Dealer 2nd Card
            elseif string.find(message, "4") then
                PlaySoundFile(soundFilePaths[4])
                playerFrame.player1SplitHand2CardTotalText:SetText("4")
            elseif string.find(message, "5") then
                PlaySoundFile(soundFilePaths[5])
                playerFrame.player1SplitHand2CardTotalText:SetText("5")
            elseif string.find(message, "6") then
                PlaySoundFile(soundFilePaths[6])
                playerFrame.player1SplitHand2CardTotalText:SetText("6")
            elseif string.find(message, "7") then
                PlaySoundFile(soundFilePaths[7])
                playerFrame.player1SplitHand2CardTotalText:SetText("7")
            elseif string.find(message, "8") then
                PlaySoundFile(soundFilePaths[8])
                playerFrame.player1SplitHand2CardTotalText:SetText("8")
            elseif string.find(message, "9") then
                PlaySoundFile(soundFilePaths[9])
                playerFrame.player1SplitHand2CardTotalText:SetText("9")
            elseif string.find(message, "10") then
                PlaySoundFile(soundFilePaths[10])
                playerFrame.player1SplitHand2CardTotalText:SetText("10")
            elseif string.find(message, "11") then
                PlaySoundFile(soundFilePaths[11])
                playerFrame.player1SplitHand2CardTotalText:SetText("11")
            elseif string.find(message, "12") then
                PlaySoundFile(soundFilePaths[12])
                playerFrame.player1SplitHand2CardTotalText:SetText("12")
            elseif string.find(message, "13") then
                PlaySoundFile(soundFilePaths[13])
                playerFrame.player1SplitHand2CardTotalText:SetText("13")
            elseif turn == 10 then
                if playerFrame.player1SplitHand1CardTotalText:GetText() == "Blackjack" then
                    if playerFrame.player1SplitHand2CardTotalText:GetText() == "Blackjack" then
                        turn = 23 -- Skip to Dealer 2nd Card
                    else
                        turn = 16 -- Skip to Player 1 3rd Card (Hand 2)
                    end
                end
            end
        end

    elseif turn == 2 then
        if string.find(message, "1 or 11") then
            PlaySoundFile(soundFilePaths[22])
            playerFrame.dealerCardTotalText:SetText("1 or 11")
        elseif string.find(message, "2") then
            PlaySoundFile(soundFilePaths[2])
            playerFrame.dealerCardTotalText:SetText("2")
        elseif string.find(message, "3") then
            PlaySoundFile(soundFilePaths[3])
            playerFrame.dealerCardTotalText:SetText("3")
        elseif string.find(message, "4") then
            PlaySoundFile(soundFilePaths[4])
            playerFrame.dealerCardTotalText:SetText("4")
        elseif string.find(message, "5") then
            PlaySoundFile(soundFilePaths[5])
            playerFrame.dealerCardTotalText:SetText("5")
        elseif string.find(message, "6") then
            PlaySoundFile(soundFilePaths[6])
            playerFrame.dealerCardTotalText:SetText("6")
        elseif string.find(message, "7") then
            PlaySoundFile(soundFilePaths[7])
            playerFrame.dealerCardTotalText:SetText("7")
        elseif string.find(message, "8") then
            PlaySoundFile(soundFilePaths[8])
            playerFrame.dealerCardTotalText:SetText("8")
        elseif string.find(message, "9") then
            PlaySoundFile(soundFilePaths[9])
            playerFrame.dealerCardTotalText:SetText("9")
        elseif string.find(message, "10") then
            PlaySoundFile(soundFilePaths[10])
            playerFrame.dealerCardTotalText:SetText("10")
        end

    elseif string.find(message, "Dealer") and string.find(message, "has") and not string.find(message, "turned") then
        if turn >= 24 then
            
            if string.find(message, "2 or 12") then
                PlaySoundFile(soundFilePaths[23])
                playerFrame.dealerCardTotalText:SetText("2 or 12")
            elseif string.find(message, "3 or 13") then
                PlaySoundFile(soundFilePaths[24])
                playerFrame.dealerCardTotalText:SetText("3 or 13")
            elseif string.find(message, "4 or 14") then
                PlaySoundFile(soundFilePaths[25])
                playerFrame.dealerCardTotalText:SetText("4 or 14")
            elseif string.find(message, "5 or 15") then
                PlaySoundFile(soundFilePaths[26])
                playerFrame.dealerCardTotalText:SetText("5 or 15")
            elseif string.find(message, "6 or 16") then
                PlaySoundFile(soundFilePaths[27])
                playerFrame.dealerCardTotalText:SetText("6 or 16")
            elseif string.find(message, "14") then
                PlaySoundFile(soundFilePaths[14])
                playerFrame.dealerCardTotalText:SetText("14")
            elseif string.find(message, "15") then
                PlaySoundFile(soundFilePaths[15])
                playerFrame.dealerCardTotalText:SetText("15")
            elseif string.find(message, "16") then
                PlaySoundFile(soundFilePaths[16])
                playerFrame.dealerCardTotalText:SetText("16")
            elseif string.find(message, "17") then
                PlaySoundFile(soundFilePaths[17])
                playerFrame.dealerCardTotalText:SetText("17")
            elseif string.find(message, "18") then
                PlaySoundFile(soundFilePaths[18])
                playerFrame.dealerCardTotalText:SetText("18")
            elseif string.find(message, "19") then
                PlaySoundFile(soundFilePaths[19])
                playerFrame.dealerCardTotalText:SetText("19")
            elseif string.find(message, "20") then
                PlaySoundFile(soundFilePaths[20])
                playerFrame.dealerCardTotalText:SetText("20")
            elseif string.find(message, "21") then
                PlaySoundFile(soundFilePaths[21])
                playerFrame.dealerCardTotalText:SetText("21")
            elseif string.find(message, "22") then
                PlaySoundFile(soundFilePaths[37])
                playerFrame.dealerCardTotalText:SetText("22")
                playerFrame.dealerCardTotalText:SetTextColor(1, 0, 0)
            elseif string.find(message, "23") then
                PlaySoundFile(soundFilePaths[37])
                playerFrame.dealerCardTotalText:SetText("23")
                playerFrame.dealerCardTotalText:SetTextColor(1, 0, 0)
            elseif string.find(message, "24") then
                PlaySoundFile(soundFilePaths[37])
                playerFrame.dealerCardTotalText:SetText("24")
                playerFrame.dealerCardTotalText:SetTextColor(1, 0, 0)
            elseif string.find(message, "25") then
                PlaySoundFile(soundFilePaths[37])
                playerFrame.dealerCardTotalText:SetText("25")
                playerFrame.dealerCardTotalText:SetTextColor(1, 0, 0)
            elseif string.find(message, "26") then
                PlaySoundFile(soundFilePaths[37])
                playerFrame.dealerCardTotalText:SetText("26")
                playerFrame.dealerCardTotalText:SetTextColor(1, 0, 0)
            elseif string.find(message, "27") then
                PlaySoundFile(soundFilePaths[37])
                playerFrame.dealerCardTotalText:SetText("27")
                playerFrame.dealerCardTotalText:SetTextColor(1, 0, 0)
            elseif string.find(message, "28") then
                PlaySoundFile(soundFilePaths[37])
                playerFrame.dealerCardTotalText:SetText("28")
                playerFrame.dealerCardTotalText:SetTextColor(1, 0, 0)
            elseif string.find(message, "29") then
                PlaySoundFile(soundFilePaths[37])
                playerFrame.dealerCardTotalText:SetText("29")
                playerFrame.dealerCardTotalText:SetTextColor(1, 0, 0)
            elseif string.find(message, "30") then
                PlaySoundFile(soundFilePaths[37])
                playerFrame.dealerCardTotalText:SetText("30")
                playerFrame.dealerCardTotalText:SetTextColor(1, 0, 0)
            elseif string.find(message, "4") then
                PlaySoundFile(soundFilePaths[4])
                playerFrame.dealerCardTotalText:SetText("4")
            elseif string.find(message, "5") then
                PlaySoundFile(soundFilePaths[5])
                playerFrame.dealerCardTotalText:SetText("5")
            elseif string.find(message, "6") then
                PlaySoundFile(soundFilePaths[6])
                playerFrame.dealerCardTotalText:SetText("6")
            elseif string.find(message, "7") then
                PlaySoundFile(soundFilePaths[7])
                playerFrame.dealerCardTotalText:SetText("7")
            elseif string.find(message, "8") then
                PlaySoundFile(soundFilePaths[8])
                playerFrame.dealerCardTotalText:SetText("8")
            elseif string.find(message, "9") then
                PlaySoundFile(soundFilePaths[9])
                playerFrame.dealerCardTotalText:SetText("9")
            elseif string.find(message, "10") then
                PlaySoundFile(soundFilePaths[10])
                playerFrame.dealerCardTotalText:SetText("10")
            elseif string.find(message, "11") then
                PlaySoundFile(soundFilePaths[11])
                playerFrame.dealerCardTotalText:SetText("11")
            elseif string.find(message, "12") then
                PlaySoundFile(soundFilePaths[12])
                playerFrame.dealerCardTotalText:SetText("12")
            elseif string.find(message, "13") then
                PlaySoundFile(soundFilePaths[13])
                playerFrame.dealerCardTotalText:SetText("13")
            end
        end
    end
end

-- Function to handle incoming chat messages
local function HandleCardsP12(message)

    -- Check if the message contains card names
    for cardName, cardFullName in pairs(cardNames) do
        playerFrame.player1CardTotalText:Show()
        playerFrame.player2CardTotalText:Show()
        playerFrame.dealerCardTotalText:Show()
        if string.find(message, cardFullName) then
            P12(cardName)
        end
    end


    local _, _, number = string.find(message, "(%d+)")


    -- Player 1: Ace Combos
    if string.find(message, unitName1) and string.find(message, "1 or 11") and turn == 1 then -- Player: Ace
        playerFrame.player1CardTotalText:SetText("1 or 11")
        PlaySoundFile(soundFilePaths[22])
    elseif string.find(message, unitName1) and string.find(message, "2 or 12") then -- Player: Ace + Ace
        playerFrame.player1CardTotalText:SetText("2 or 12")
        PlaySoundFile(soundFilePaths[23])
    elseif string.find(message, unitName1) and string.find(message, "3 or 13") then -- Player: Ace + 2   or   2 + Ace
        playerFrame.player1CardTotalText:SetText("3 or 13")
        PlaySoundFile(soundFilePaths[24])
    elseif string.find(message, unitName1) and string.find(message, "4 or 14") then -- Player: Ace + 3   or   3 + Ace
        playerFrame.player1CardTotalText:SetText("4 or 14")
        PlaySoundFile(soundFilePaths[25])
    elseif string.find(message, unitName1) and string.find(message, "5 or 15") then -- Player: Ace + 4   or   4 + Ace
        playerFrame.player1CardTotalText:SetText("5 or 15")
        PlaySoundFile(soundFilePaths[26])
    elseif string.find(message, unitName1) and string.find(message, "6 or 16") then -- Player: Ace + 5   or   5 + Ace
        playerFrame.player1CardTotalText:SetText("6 or 16")
        PlaySoundFile(soundFilePaths[27])
    elseif string.find(message, unitName1) and string.find(message, "7 or 17") then -- Player: Ace + 6   or   6 + Ace
        playerFrame.player1CardTotalText:SetText("7 or 17")
        PlaySoundFile(soundFilePaths[28])
    elseif string.find(message, unitName1) and string.find(message, "8 or 18") then -- Player: Ace + 7   or   7 + Ace
        playerFrame.player1CardTotalText:SetText("8 or 18")
        PlaySoundFile(soundFilePaths[29])
    elseif string.find(message, unitName1) and string.find(message, "9 or 19") then -- Player: Ace + 8   or   8 + Ace
        playerFrame.player1CardTotalText:SetText("9 or 19")
        PlaySoundFile(soundFilePaths[30])
    elseif string.find(message, unitName1) and string.find(message, "10 or 20") then -- Player: Ace + 9   or   9 + Ace
        playerFrame.player1CardTotalText:SetText("10 or 20")
        PlaySoundFile(soundFilePaths[31])
    elseif string.find(message, unitName1) and string.find(message, "21") then -- Player: 21
        playerFrame.player1CardTotalText:SetText("21")
        PlaySoundFile(soundFilePaths[21])

    -- Player 1: 2-21
    elseif number and tonumber(number) >= 2 and tonumber(number) <= 21 and string.find(message, unitName1) then
        playerFrame.player1CardTotalText:SetText(Player1Total + number)
        if string.find(message,"received the") and turn == 1 then
            if Player1Total + number >= 2 and Player1Total + number <= 10 then
                PlaySoundFile(soundFilePaths[Player1Total + number])
            end
        elseif string.find(message, unitName1) and string.find(message, "has") and turn == 4 or string.find(message, unitName1) and string.find(message, "has") and turn >= 6 and turn <= 10 then
            if Player1Total + number >= 2 and Player1Total + number <= 21 then
                PlaySoundFile(soundFilePaths[Player1Total + number])
            end
        end

    -- Player 1: Blackjack
    elseif string.find(message, unitName1) and string.find(message, "Blackjack") then
        playerFrame.player1CardTotalText:SetText("Blackjack")
        playerFrame.player1CardTotalText:SetTextColor(1, 1, 0) -- RGB values for yellow
        PlaySoundFile(soundFilePaths[32])
        playerFrame.player1HitButton:Disable()
        playerFrame.player1StandButton:Disable()
        playerFrame.player1DoubleButton:Disable()
        countdownDuration = 30
        playerFrame.timerText1:SetText("")
        playerFrame.timerText1:Hide()





    -- Player 2: Ace Combos
    elseif string.find(message, unitName2) and string.find(message, "1 or 11") and turn == 2 then -- Player: Ace
        playerFrame.player2CardTotalText:SetText("1 or 11")
        PlaySoundFile(soundFilePaths[22])
    elseif string.find(message, unitName2) and string.find(message, "2 or 12") then -- Player: Ace + Ace
        playerFrame.player2CardTotalText:SetText("2 or 12")
        PlaySoundFile(soundFilePaths[23])
    elseif string.find(message, unitName2) and string.find(message, "3 or 13") then -- Player: Ace + 2   or   2 + Ace
        playerFrame.player2CardTotalText:SetText("3 or 13")
        PlaySoundFile(soundFilePaths[24])
    elseif string.find(message, unitName2) and string.find(message, "4 or 14") then -- Player: Ace + 3   or   3 + Ace
        playerFrame.player2CardTotalText:SetText("4 or 14")
        PlaySoundFile(soundFilePaths[25])
    elseif string.find(message, unitName2) and string.find(message, "5 or 15") then -- Player: Ace + 4   or   4 + Ace
        playerFrame.player2CardTotalText:SetText("5 or 15")
        PlaySoundFile(soundFilePaths[26])
    elseif string.find(message, unitName2) and string.find(message, "6 or 16") then -- Player: Ace + 5   or   5 + Ace
        playerFrame.player2CardTotalText:SetText("6 or 16")
        PlaySoundFile(soundFilePaths[27])
    elseif string.find(message, unitName2) and string.find(message, "7 or 17") then -- Player: Ace + 6   or   6 + Ace
        playerFrame.player2CardTotalText:SetText("7 or 17")
        PlaySoundFile(soundFilePaths[28])
    elseif string.find(message, unitName2) and string.find(message, "8 or 18") then -- Player: Ace + 7   or   7 + Ace
        playerFrame.player2CardTotalText:SetText("8 or 18")
        PlaySoundFile(soundFilePaths[29])
    elseif string.find(message, unitName2) and string.find(message, "9 or 19") then -- Player: Ace + 8   or   8 + Ace
        playerFrame.player2CardTotalText:SetText("9 or 19")
        PlaySoundFile(soundFilePaths[30])
    elseif string.find(message, unitName2) and string.find(message, "10 or 20") then -- Player: Ace + 9   or   9 + Ace
        playerFrame.player2CardTotalText:SetText("10 or 20")
        PlaySoundFile(soundFilePaths[31])
    elseif string.find(message, unitName2) and string.find(message, "21") then -- Player: 21
        playerFrame.player2CardTotalText:SetText("21")
        PlaySoundFile(soundFilePaths[21])

    -- Player 2: 2-21
    elseif number and tonumber(number) >= 2 and tonumber(number) <= 21 and string.find(message, unitName2) then
        playerFrame.player2CardTotalText:SetText(Player2Total + number)
        if string.find(message,"received the") and turn == 2 then
            if Player2Total + number == 2 then
                PlaySoundFile(soundFilePaths[2])
            elseif Player2Total + number == 3 then
                PlaySoundFile(soundFilePaths[3])
            elseif Player2Total + number == 4 then
                PlaySoundFile(soundFilePaths[4])
            elseif Player2Total + number == 5 then
                PlaySoundFile(soundFilePaths[5])
            elseif Player2Total + number == 6 then
                PlaySoundFile(soundFilePaths[6])
            elseif Player2Total + number == 7 then
                PlaySoundFile(soundFilePaths[7])
            elseif Player2Total + number == 8 then
                PlaySoundFile(soundFilePaths[8])
            elseif Player2Total + number == 9 then
                PlaySoundFile(soundFilePaths[9])
            elseif Player2Total + number == 10 then
                PlaySoundFile(soundFilePaths[10])
            end
        elseif string.find(message, unitName2) and string.find(message, "has") and turn == 5 or string.find(message, unitName2) and string.find(message, "has") and turn >= 11 and turn <= 15 then
            if Player2Total + number >= 2 and Player2Total + number <= 21 then
                PlaySoundFile(soundFilePaths[Player2Total + number])
            end
        end

    -- Player 2: Blackjack
    elseif string.find(message, unitName2) and string.find(message, "Blackjack") then
        playerFrame.player2CardTotalText:SetText("Blackjack")
        playerFrame.player2CardTotalText:SetTextColor(1, 1, 0) -- RGB values for yellow
        PlaySoundFile(soundFilePaths[32])
        playerFrame.player2HitButton:Disable()
        playerFrame.player2StandButton:Disable()
        playerFrame.player2DoubleButton:Disable()
        countdownDuration = 30
        playerFrame.timerText2:SetText("")
        playerFrame.timerText2:Hide()

    
    -- Dealer: Ace Combos
    elseif string.find(message, "Dealer") and string.find(message, "1 or 11") and turn == 3 then -- Dealer: Ace
        playerFrame.dealerCardTotalText:SetText("1 or 11")
        PlaySoundFile(soundFilePaths[22])
    elseif string.find(message, "Dealer") and string.find(message, "2 or 12") then -- Dealer: Ace + Ace
        playerFrame.dealerCardTotalText:SetText("2 or 12")
        PlaySoundFile(soundFilePaths[23])
    elseif string.find(message, "Dealer") and string.find(message, "3 or 13") then -- Dealer: Ace + 2   or   2 + Ace
        playerFrame.dealerCardTotalText:SetText("3 or 13")
        PlaySoundFile(soundFilePaths[24])
    elseif string.find(message, "Dealer") and string.find(message, "4 or 14") then -- Dealer: Ace + 3   or   3 + Ace
        playerFrame.dealerCardTotalText:SetText("4 or 14")
        PlaySoundFile(soundFilePaths[25])
    elseif string.find(message, "Dealer") and string.find(message, "5 or 15") then -- Dealer: Ace + 4   or   4 + Ace
        playerFrame.dealerCardTotalText:SetText("5 or 15")
        PlaySoundFile(soundFilePaths[26])
    elseif string.find(message, "Dealer") and string.find(message, "6 or 16") then -- Dealer: Ace + 5   or   5 + Ace
        playerFrame.dealerCardTotalText:SetText("6 or 16")
        PlaySoundFile(soundFilePaths[27])

    -- Dealer: 2-21
    elseif number and tonumber(number) >=2 and tonumber(number) <= 20 and string.find(message, "Dealer") then -- Dealer Total: 2 to 21
        playerFrame.dealerCardTotalText:SetText(DealerTotal + number)
        if string.find(message, "Dealer has 20") then
            PlaySoundFile(soundFilePaths[20])
        elseif string.find(message, "Dealer has 21") then
            PlaySoundFile(soundFilePaths[21])  
        elseif string.find(message, "Dealer has 2") then
            PlaySoundFile(soundFilePaths[2])
        elseif string.find(message, "Dealer has 3") then
            PlaySoundFile(soundFilePaths[3])
        elseif string.find(message, "Dealer has 4") then
            PlaySoundFile(soundFilePaths[4])
        elseif string.find(message, "Dealer has 5") then
            PlaySoundFile(soundFilePaths[5])
        elseif string.find(message, "Dealer has 6") then
            PlaySoundFile(soundFilePaths[6])
        elseif string.find(message, "Dealer has 7") then
            PlaySoundFile(soundFilePaths[7])
        elseif string.find(message, "Dealer has 8") then
            PlaySoundFile(soundFilePaths[8])
        elseif string.find(message, "Dealer has 9") then
            PlaySoundFile(soundFilePaths[9])
        elseif string.find(message, "Dealer has 10") then
            PlaySoundFile(soundFilePaths[10])
        elseif string.find(message, "Dealer has 11") then
            PlaySoundFile(soundFilePaths[11])
        elseif string.find(message, "Dealer has 12") then
            PlaySoundFile(soundFilePaths[12])
        elseif string.find(message, "Dealer has 13") then
            PlaySoundFile(soundFilePaths[13])
        elseif string.find(message, "Dealer has 14") then
            PlaySoundFile(soundFilePaths[14])
        elseif string.find(message, "Dealer has 15") then
            PlaySoundFile(soundFilePaths[15])
        elseif string.find(message, "Dealer has 16") then
            PlaySoundFile(soundFilePaths[16])
        elseif string.find(message, "Dealer has 17") then
            PlaySoundFile(soundFilePaths[17])
        elseif string.find(message, "Dealer has 18") then
            PlaySoundFile(soundFilePaths[18])
        elseif string.find(message, "Dealer has 19") then
            PlaySoundFile(soundFilePaths[19])
        else
        end

    -- Dealer: 21
    elseif string.find(message, "21") and string.find(message, "Dealer") then
        playerFrame.dealerCardTotalText:SetText("21")

    -- Dealer: 22
    elseif string.find(message, "22") and string.find(message, "Dealer") then
        playerFrame.dealerCardTotalText:SetText("22")
        playerFrame.dealerCardTotalText:SetTextColor(1, 0, 0)
    -- Dealer: 23
    elseif string.find(message, "23") and string.find(message, "Dealer") then
        playerFrame.dealerCardTotalText:SetText("23")
        playerFrame.dealerCardTotalText:SetTextColor(1, 0, 0)
    -- Dealer: 24
    elseif string.find(message, "24") and string.find(message, "Dealer") then
        playerFrame.dealerCardTotalText:SetText("24")
        playerFrame.dealerCardTotalText:SetTextColor(1, 0, 0)
    -- Dealer: 25
    elseif string.find(message, "25") and string.find(message, "Dealer") then
        playerFrame.dealerCardTotalText:SetText("25")
        playerFrame.dealerCardTotalText:SetTextColor(1, 0, 0)
    -- Dealer: 26
    elseif string.find(message, "26") and string.find(message, "Dealer") then
        playerFrame.dealerCardTotalText:SetText("26")
        playerFrame.dealerCardTotalText:SetTextColor(1, 0, 0)
    -- Dealer: 27
    elseif string.find(message, "27") and string.find(message, "Dealer") then
        playerFrame.dealerCardTotalText:SetText("27")
        playerFrame.dealerCardTotalText:SetTextColor(1, 0, 0)
    -- Dealer: 28
    elseif string.find(message, "28") and string.find(message, "Dealer") then
        playerFrame.dealerCardTotalText:SetText("28")
        playerFrame.dealerCardTotalText:SetTextColor(1, 0, 0)
    -- Dealer: 29
    elseif string.find(message, "29") and string.find(message, "Dealer") then
        playerFrame.dealerCardTotalText:SetText("29")
        playerFrame.dealerCardTotalText:SetTextColor(1, 0, 0)
    -- Dealer: 30
    elseif string.find(message, "30") and string.find(message, "Dealer") then
        playerFrame.dealerCardTotalText:SetText("30")
        playerFrame.dealerCardTotalText:SetTextColor(1, 0, 0)


    -- Dealer: Blackjack
    elseif string.find(message, "Dealer") and string.find(message, "Blackjack") then
        playerFrame.dealerCardTotalText:SetText("Blackjack")
        playerFrame.dealerCardTotalText:SetTextColor(1, 1, 0) -- RGB values for yellow
        PlaySoundFile(soundFilePaths[36])
    
        
    end
end












-- Function to handle incoming chat messages
local function HandleChatMessage(message)
    -- Check if the message contains card names
    for cardName, cardFullName in pairs(cardNames) do
        if string.find(message, cardFullName) and Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == true then
            P12345(cardName)
        elseif string.find(message, cardFullName) and Player1Active == false and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == true then
            P2345(cardName)
        elseif string.find(message, cardFullName) and Player1Active == true and Player2Active == false and Player3Active == true and Player4Active == true and Player5Active == true then
            P1345(cardName)  
        elseif string.find(message, cardFullName) and Player1Active == true and Player2Active == true and Player3Active == false and Player4Active == true and Player5Active == true then
            P1245(cardName) 
        elseif string.find(message, cardFullName) and Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == false and Player5Active == true then
            P1235(cardName)
        elseif string.find(message, cardFullName) and Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == false then
            P1234(cardName)
        elseif string.find(message, cardFullName) and Player1Active == false and Player2Active == false and Player3Active == true and Player4Active == true and Player5Active == true then
            P345(cardName)
        elseif string.find(message, cardFullName) and Player1Active == false and Player2Active == true and Player3Active == false and Player4Active == true and Player5Active == true then
            P245(cardName)
        elseif string.find(message, cardFullName) and Player1Active == false and Player2Active == true and Player3Active == true and Player4Active == false and Player5Active == true then
            P235(cardName)
        elseif string.find(message, cardFullName) and Player1Active == false and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == false then
            P234(cardName)
        elseif string.find(message, cardFullName) and Player1Active == true and Player2Active == false and Player3Active == false and Player4Active == true and Player5Active == true then
            P145(cardName)
        elseif string.find(message, cardFullName) and Player1Active == true and Player2Active == false and Player3Active == true and Player4Active == false and Player5Active == true then
            P135(cardName)
        elseif string.find(message, cardFullName) and Player1Active == true and Player2Active == false and Player3Active == true and Player4Active == true and Player5Active == false then
            P134(cardName)
        elseif string.find(message, cardFullName) and Player1Active == true and Player2Active == true and Player3Active == false and Player4Active == false and Player5Active == true then
            P125(cardName)
        elseif string.find(message, cardFullName) and Player1Active == true and Player2Active == true and Player3Active == false and Player4Active == true and Player5Active == false then
            P124(cardName)
        elseif string.find(message, cardFullName) and Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == false and Player5Active == false then
            P123(cardName)
        elseif string.find(message, cardFullName) and Player1Active == false and Player2Active == false and Player3Active == false and Player4Active == true and Player5Active == true then
            P45(cardName)
        elseif string.find(message, cardFullName) and Player1Active == false and Player2Active == false and Player3Active == true and Player4Active == false and Player5Active == true then
            P35(cardName)
        elseif string.find(message, cardFullName) and Player1Active == false and Player2Active == false and Player3Active == true and Player4Active == true and Player5Active == false then
            P34(cardName)
        elseif string.find(message, cardFullName) and Player1Active == false and Player2Active == true and Player3Active == false and Player4Active == false and Player5Active == true then
            P25(cardName)
        elseif string.find(message, cardFullName) and Player1Active == false and Player2Active == true and Player3Active == false and Player4Active == true and Player5Active == false then
            P24(cardName)
        elseif string.find(message, cardFullName) and Player1Active == false and Player2Active == true and Player3Active == true and Player4Active == false and Player5Active == false then
            P23(cardName)
        elseif string.find(message, cardFullName) and Player1Active == true and Player2Active == false and Player3Active == false and Player4Active == false and Player5Active == true then
            P15(cardName)
        elseif string.find(message, cardFullName) and Player1Active == true and Player2Active == false and Player3Active == false and Player4Active == true and Player5Active == false then
            P14(cardName)
        elseif string.find(message, cardFullName) and Player1Active == true and Player2Active == false and Player3Active == true and Player4Active == false and Player5Active == false then
            P13(cardName)
        elseif string.find(message, cardFullName) and Player1Active == false and Player2Active == false and Player3Active == false and Player4Active == false and Player5Active == true then
            P5(cardName)
        elseif string.find(message, cardFullName) and Player1Active == false and Player2Active == false and Player3Active == false and Player4Active == true and Player5Active == false then
            P4(cardName)
        elseif string.find(message, cardFullName) and Player1Active == false and Player2Active == false and Player3Active == true and Player4Active == false and Player5Active == false then
            P3(cardName)
        elseif string.find(message, cardFullName) and Player1Active == false and Player2Active == true and Player3Active == false and Player4Active == false and Player5Active == false then
            P2(cardName)
        end
        playerFrame.player1CardTotalText:Show()
        playerFrame.player2CardTotalText:Show()
        playerFrame.player3CardTotalText:Show()
        playerFrame.player4CardTotalText:Show()
        playerFrame.player5CardTotalText:Show()
        playerFrame.dealerCardTotalText:Show()
    end

    -- Players: 1
    if Player1Active and not Player2Active and not Player3Active and not Player4Active and not Player5Active then
        HandleCardsP1(message)
    -- Players: 1, 2
    elseif Player1Active and Player2Active and not Player3Active and not Player4Active and not Player5Active then
        HandleCardsP12(message)
    end

end


















-- Update player names with the names of raid party members 2 - 6
local function updatePlayerNames()
    local playerName = UnitName("player");  -- Get your own player name

    -- Check if the player is in the raid party
    local isInRaidParty = isPlayerInRaidParty(playerName, {unitName1, unitName2, unitName3, unitName4, unitName5})

    -- Sets the POV using visibility functions above
    if isInRaidParty then
        if playerName == unitName1 then
            isPlayer1()
            isPlayer1CashDesk()
        elseif playerName == unitName2 then
            isPlayer2()
            isPlayer2CashDesk()
        elseif playerName == unitName3 then
            isPlayer3()
            isPlayer3CashDesk()
        elseif playerName == unitName4 then
            isPlayer4()
            isPlayer4CashDesk()
        elseif playerName == unitName5 then
            isPlayer5()
            isPlayer5CashDesk()
        end
    else
        print("You must reload to claim a seat.")
    end
end

updatePlayerNames();









-- Updates player names when raid roster changes (requires /reload)
local eventFrame = CreateFrame("Frame")
eventFrame:RegisterEvent("RAID_ROSTER_UPDATE")
eventFrame:SetScript("OnEvent", updatePlayerNames)

-- Event register for raid chat messages
local eventFrame = CreateFrame("Frame")
eventFrame:RegisterEvent("CHAT_MSG_RAID")

-- Event handler if it detects raid chat messages
eventFrame:SetScript("OnEvent", function(self, event, message, sender)

    local AceValues = {
        ["1 or 11"] = "11",
        ["2 or 12"] = "12",
        ["3 or 13"] = "13",
        ["4 or 14"] = "14",
        ["5 or 15"] = "15",
        ["6 or 16"] = "16",
        ["7 or 17"] = "17",
        ["8 or 18"] = "18",
        ["9 or 19"] = "19",
        ["10 or 20"] = "20"
    }

    player1BeforeStandValue = playerFrame.player1CardTotalText:GetText()
    player1AfterStandValue = AceValues[player1BeforeStandValue]

    player1SplitHand1BeforeStandValue = playerFrame.player1SplitHand1CardTotalText:GetText()
    player1SplitHand1AfterStandValue = AceValues[player1SplitHand1BeforeStandValue]

    player1SplitHand2BeforeStandValue = playerFrame.player1SplitHand2CardTotalText:GetText()
    player1SplitHand2AfterStandValue = AceValues[player1SplitHand2BeforeStandValue]

    player2BeforeStandValue = playerFrame.player2CardTotalText:GetText()
    player2AfterStandValue = AceValues[player2BeforeStandValue]

    player3BeforeStandValue = playerFrame.player3CardTotalText:GetText()
    player3AfterStandValue = AceValues[player3BeforeStandValue]

    player4BeforeStandValue = playerFrame.player4CardTotalText:GetText()
    player4AfterStandValue = AceValues[player4BeforeStandValue]

    player5BeforeStandValue = playerFrame.player5CardTotalText:GetText()
    player5AfterStandValue = AceValues[player5BeforeStandValue]

    if string.find(message, "%[P1%] Placing") and string.find(message, "main") then
        player1PlaceCoinsMainBet()
        Player1Active = true
        local player1MainBet = string.match(message, "(%d+)G")
        if player1MainBet then
            player1PlaceTextMainBet(message)
        else
        end
    elseif string.find(message, "%[P1%] Placing") and string.find(message, "Perfect") then
        player1PlaceCoinsPPBet()
        local player1PPBet = string.match(message, "(%d+)G")
        if player1PPBet then
            player1PlaceTextPPBet(message)
        else
        end
    elseif string.find(message, "%[P1%] Placing") and string.find(message, "21") then
        player1PlaceCoins213Bet()
        local player1213Bet = string.match(message, "(%d+)G")
        if player1213Bet then
            player1PlaceText213Bet(message)
        else
        end
    elseif string.find(message, "%[P1%] Hit") then
        playerFrame.timerText1:SetText("")
        playerFrame.timerText1:Hide()
        countdownDuration = 30
    elseif string.find(message, "%[P1%] %(H1%) Hit") then
        playerFrame.timerText1:SetText("")
        playerFrame.timerText1:Hide()
        countdownDuration = 30
    elseif string.find(message, "%[P1%] %(H2%) Hit") then
        playerFrame.timerText1:SetText("")
        playerFrame.timerText1:Hide()
        countdownDuration = 30
    elseif string.find(message, "%[P1%] Stand") then
        playerFrame.timerText1:SetText("")
        playerFrame.timerText1:Hide()
        countdownDuration = 30

        turn = 23 -- Skip to Dealer 2nd Card
        if player1AfterStandValue then
            playerFrame.player1CardTotalText:SetText(player1AfterStandValue)
        end
        
    elseif string.find(message, "%[P1%] %(H1%) Stand") then
        playerFrame.timerText1:SetText("")
        playerFrame.timerText1:Hide()
        countdownDuration = 30

        if player1SplitHand2BeforeStandValue == "Blackjack" then
            turn = 23 -- Dealer: 2nd Card
        else
            turn = 16 -- Player 1: 3rd Card (Split H2)
        end

        if player1SplitHand1AfterStandValue then
            playerFrame.player1SplitHand1CardTotalText:SetText(player1SplitHand1AfterStandValue)
        end

    elseif string.find(message, "%[P1%] %(H2%) Stand") then
        playerFrame.timerText1:SetText("")
        playerFrame.timerText1:Hide()
        countdownDuration = 30

        turn = 23 -- Skip to Dealer 2nd Card

        if player1SplitHand2AfterStandValue then
            playerFrame.player1SplitHand2CardTotalText:SetText(player1SplitHand2AfterStandValue)
        end

    elseif string.find(message, "%[P1%] Double") then
        local betDoubleAmount1 = string.match(message, "Double my bet to (%d+)G")
        if betDoubleAmount1 then
            player1PlaceCoinsDoubleBet()
            player1MainBetAmount:SetText(betDoubleAmount1 .. " G")
            PlaySoundFile(soundFilePaths[43])
            playerFrame.timerText1:SetText("")
            playerFrame.timerText1:Hide()
            countdownDuration = 30
            -- Players: 1
            if Player1Active and not Player2Active and not Player3Active and not Player4Active and not Player5Active then
                turn = 22 -- Skip to Player 1 3rd Card (Double)
            elseif Player1Active == true and Player2Active == true and Player3Active == false and Player4Active == false and Player5Active == false then    -- Players: 1 2
                turn = 10
            elseif Player1Active == true and Player2Active == false and Player3Active == true and Player4Active == false and Player5Active == false then    -- Players: 1 3
                turn = 10
            elseif Player1Active == true and Player2Active == false and Player3Active == false and Player4Active == true and Player5Active == false then    -- Players: 1 4
                turn = 10
            elseif Player1Active == true and Player2Active == false and Player3Active == false and Player4Active == false and Player5Active == true then    -- Players: 1 5
                turn = 10
            elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == false and Player5Active == false then    -- Players: 1 2 3
                turn = 12
            elseif Player1Active == true and Player2Active == true and Player3Active == false and Player4Active == true and Player5Active == false then    -- Players: 1 2 4
                turn = 12
            elseif Player1Active == true and Player2Active == true and Player3Active == false and Player4Active == false and Player5Active == true then    -- Players: 1 2 5
                turn = 12
            elseif Player1Active == true and Player2Active == false and Player3Active == true and Player4Active == true and Player5Active == false then    -- Players: 1 3 4
                turn = 12
            elseif Player1Active == true and Player2Active == false and Player3Active == true and Player4Active == false and Player5Active == true then    -- Players: 1 3 5
                turn = 12
            elseif Player1Active == true and Player2Active == false and Player3Active == false and Player4Active == true and Player5Active == true then    -- Players: 1 4 5
                turn = 12
            elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == false then    -- Players: 1 2 3 4
                turn = 14
            elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == false and Player5Active == true then    -- Players: 1 2 3 5
                turn = 14
            elseif Player1Active == true and Player2Active == true and Player3Active == false and Player4Active == true and Player5Active == true then    -- Players: 1 2 4 5
                turn = 14
            elseif Player1Active == true and Player2Active == false and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 1 3 4 5
                turn = 14
            elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 1 2 3 4 5
                turn = 16
            end
            if playerFrame.player1CardTotalText:GetText() == "1 or 11" then
                playerFrame.player1CardTotalText:SetText("11")
            elseif playerFrame.player1CardTotalText:GetText() == "2 or 12" then
                playerFrame.player1CardTotalText:SetText("12")
            elseif playerFrame.player1CardTotalText:GetText() == "3 or 13" then
                playerFrame.player1CardTotalText:SetText("13")
            elseif playerFrame.player1CardTotalText:GetText() == "4 or 14" then
                playerFrame.player1CardTotalText:SetText("14")
            elseif playerFrame.player1CardTotalText:GetText() == "5 or 15" then
                playerFrame.player1CardTotalText:SetText("15")
            elseif playerFrame.player1CardTotalText:GetText() == "6 or 16" then
                playerFrame.player1CardTotalText:SetText("16")
            elseif playerFrame.player1CardTotalText:GetText() == "7 or 17" then
                playerFrame.player1CardTotalText:SetText("17")
            elseif playerFrame.player1CardTotalText:GetText() == "8 or 18" then
                playerFrame.player1CardTotalText:SetText("18")
            elseif playerFrame.player1CardTotalText:GetText() == "9 or 19" then
                playerFrame.player1CardTotalText:SetText("19")
            elseif playerFrame.player1CardTotalText:GetText() == "10 or 20" then
                playerFrame.player1CardTotalText:SetText("20")
            end
            playerFrame.player1HitButton:Disable()
            playerFrame.player1StandButton:Disable()
            playerFrame.player1DoubleButton:Disable()
            playerFrame.player1SplitButton:Disable()
        end
    elseif string.find(message, "%[P1%] %(H1%) Double") then
        betDoubleAmountSplitH1 = string.match(message, "Double my bet to (%d+)G")
        if betDoubleAmountSplitH1 then
            player1SplitH1BetAmount:SetText(betDoubleAmountSplitH1 .. " G")
            PlaySoundFile(soundFilePaths[41])
            timerReset()
            if Player1Active and not Player2Active and not Player3Active and not Player4Active and not Player5Active then
                turn = 15 -- Skip to Player 1 3rd Card (Double) H1
            end
        end

        playerFrame.player1SplitHand1Coins:Hide()
        playerFrame.player1SplitHand1DoubleCoins:Show()

    elseif string.find(message, "%[P1%] %(H2%) Double") then
        betDoubleAmountSplitH2 = string.match(message, "Double my bet to (%d+)G")
        if betDoubleAmountSplitH2 then
            player1SplitH2BetAmount:SetText(betDoubleAmountSplitH2 .. " G")
            PlaySoundFile(soundFilePaths[41])
            timerReset()
            if Player1Active and not Player2Active and not Player3Active and not Player4Active and not Player5Active then
                turn = 21 -- Skip to Player 1 3rd Card (Double) H2
            end
        end

        playerFrame.player1SplitHand2Coins:Hide()
        playerFrame.player1SplitHand2DoubleCoins:Show()

    elseif string.find(message, "%[P1%] Split") then
        player1HandleSplit(message)
    elseif string.find(message, "%[P2%] Placing") and string.find(message, "main") then
        PlaceBetsMain2() 
        Player2Active = true
        local player2MainBet = string.match(message, "(%d+)G")
        if player2MainBet then
            player2PlaceMainBetText(message)
        else
        end
    elseif string.find(message, "%[P2%] Placing") and string.find(message, "Perfect") then
        PlaceBetsPP2()
        local player2PPBet = string.match(message, "(%d+)G")
        if player2PPBet then
            player2PlacePPBetText(message)
        else
        end
    elseif string.find(message, "%[P2%] Placing") and string.find(message, "21") then
        PlaceBets2132()
        local player2213Bet = string.match(message, "(%d+)G")
        if player2213Bet then
            player2Place213BetText(message)
        else
        end
    elseif string.find(message, "%[P2%] Hit") then
        playerFrame.timerText2:SetText("")
        playerFrame.timerText2:Hide()
        countdownDuration = 30
        playerFrame.player2HitButton:Disable()
        playerFrame.player2StandButton:Disable()
        playerFrame.player2DoubleButton:Disable()
        playerFrame.player2SplitButton:Disable()
    elseif string.find(message, "%[P2%] Stand") then
        playerFrame.timerText2:SetText("")
        playerFrame.timerText2:Hide()
        countdownDuration = 30
        if Player1Active == false and Player2Active == true and Player3Active == false and Player4Active == false and Player5Active == false then       -- Players: 2
            turn = 9
        elseif Player1Active == true and Player2Active == true and Player3Active == false and Player4Active == false and Player5Active == false then    -- Players: 1 2
            turn = 17
        elseif Player1Active == false and Player2Active == true and Player3Active == true and Player4Active == false and Player5Active == false then    -- Players: 2 3
            turn = 11
        elseif Player1Active == false and Player2Active == true and Player3Active == false and Player4Active == true and Player5Active == false then    -- Players: 2 4
            turn = 11
        elseif Player1Active == false and Player2Active == true and Player3Active == false and Player4Active == false and Player5Active == true then    -- Players: 2 5
            turn = 11
        elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == false and Player5Active == false then    -- Players: 1 2 3
            turn = 19
        elseif Player1Active == true and Player2Active == true and Player3Active == false and Player4Active == true and Player5Active == false then    -- Players: 1 2 4
            turn = 19
        elseif Player1Active == true and Player2Active == true and Player3Active == false and Player4Active == false and Player5Active == true then    -- Players: 1 2 5
            turn = 19
        elseif Player1Active == false and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == false then    -- Players: 2 3 4
            turn = 13
        elseif Player1Active == false and Player2Active == true and Player3Active == true and Player4Active == false and Player5Active == true then    -- Players: 2 3 5
            turn = 13
        elseif Player1Active == false and Player2Active == true and Player3Active == false and Player4Active == true and Player5Active == true then    -- Players: 2 4 5
            turn = 13
        elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == false then    -- Players: 1 2 3 4
            turn = 21
        elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == false and Player5Active == true then    -- Players: 1 2 3 5
            turn = 21
        elseif Player1Active == true and Player2Active == true and Player3Active == false and Player4Active == true and Player5Active == true then    -- Players: 1 2 4 5
            turn = 15
        elseif Player1Active == false and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 2 3 4 5
            turn = 15
        elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 1 2 3 4 5
            turn = 23
        end
        if playerFrame.player2CardTotalText:GetText() == "1 or 11" then
            playerFrame.player2CardTotalText:SetText("11")
        elseif playerFrame.player2CardTotalText:GetText() == "2 or 12" then
            playerFrame.player2CardTotalText:SetText("12")
        elseif playerFrame.player2CardTotalText:GetText() == "3 or 13" then
            playerFrame.player2CardTotalText:SetText("13")
        elseif playerFrame.player2CardTotalText:GetText() == "4 or 14" then
            playerFrame.player2CardTotalText:SetText("14")
        elseif playerFrame.player2CardTotalText:GetText() == "5 or 15" then
            playerFrame.player2CardTotalText:SetText("15")
        elseif playerFrame.player2CardTotalText:GetText() == "6 or 16" then
            playerFrame.player2CardTotalText:SetText("16")
        elseif playerFrame.player2CardTotalText:GetText() == "7 or 17" then
            playerFrame.player2CardTotalText:SetText("17")
        elseif playerFrame.player2CardTotalText:GetText() == "8 or 18" then
            playerFrame.player2CardTotalText:SetText("18")
        elseif playerFrame.player2CardTotalText:GetText() == "9 or 19" then
            playerFrame.player2CardTotalText:SetText("19")
        elseif playerFrame.player2CardTotalText:GetText() == "10 or 20" then
            playerFrame.player2CardTotalText:SetText("20")
        end
        playerFrame.player2HitButton:Disable()
        playerFrame.player2StandButton:Disable()
        playerFrame.player2DoubleButton:Disable()
        playerFrame.player2SplitButton:Disable()
    elseif string.find(message, "%[P2%] Double") then
        local betDoubleAmount2 = string.match(message, "Double my bet to (%d+)G")
        if betDoubleAmount2 then
            PlaceBetsMain2Double()
            player2MainBetAmount:SetText(betDoubleAmount2 .. " G")
            PlaySoundFile(soundFilePaths[43])
            playerFrame.timerText2:SetText("")
            playerFrame.timerText2:Hide()
            countdownDuration = 30
            if Player1Active == false and Player2Active == true and Player3Active == false and Player4Active == false and Player5Active == false then       -- Players: 2
                turn = 8
            elseif Player1Active == true and Player2Active == true and Player3Active == false and Player4Active == false and Player5Active == false then    -- Players: 1 2
                turn = 16
            elseif Player1Active == false and Player2Active == true and Player3Active == true and Player4Active == false and Player5Active == false then    -- Players: 2 3
                turn = 10
            elseif Player1Active == false and Player2Active == true and Player3Active == false and Player4Active == true and Player5Active == false then    -- Players: 2 4
                turn = 10
            elseif Player1Active == false and Player2Active == true and Player3Active == false and Player4Active == false and Player5Active == true then    -- Players: 2 5
                turn = 10
            elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == false and Player5Active == false then    -- Players: 1 2 3
                turn = 18
            elseif Player1Active == true and Player2Active == true and Player3Active == false and Player4Active == true and Player5Active == false then    -- Players: 1 2 4
                turn = 18
            elseif Player1Active == true and Player2Active == true and Player3Active == false and Player4Active == false and Player5Active == true then    -- Players: 1 2 5
                turn = 18
            elseif Player1Active == false and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == false then    -- Players: 2 3 4
                turn = 12
            elseif Player1Active == false and Player2Active == true and Player3Active == true and Player4Active == false and Player5Active == true then    -- Players: 2 3 5
                turn = 12
            elseif Player1Active == false and Player2Active == true and Player3Active == false and Player4Active == true and Player5Active == true then    -- Players: 2 4 5
                turn = 12
            elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == false then    -- Players: 1 2 3 4
                turn = 20
            elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == false and Player5Active == true then    -- Players: 1 2 3 5
                turn = 20
            elseif Player1Active == true and Player2Active == true and Player3Active == false and Player4Active == true and Player5Active == true then    -- Players: 1 2 4 5
                turn = 14
            elseif Player1Active == false and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 2 3 4 5
                turn = 14
            elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 1 2 3 4 5
                turn = 22
            end
            if playerFrame.player2CardTotalText:GetText() == "1 or 11" then
                playerFrame.player2CardTotalText:SetText("11")
            elseif playerFrame.player2CardTotalText:GetText() == "2 or 12" then
                playerFrame.player2CardTotalText:SetText("12")
            elseif playerFrame.player2CardTotalText:GetText() == "3 or 13" then
                playerFrame.player2CardTotalText:SetText("13")
            elseif playerFrame.player2CardTotalText:GetText() == "4 or 14" then
                playerFrame.player2CardTotalText:SetText("14")
            elseif playerFrame.player2CardTotalText:GetText() == "5 or 15" then
                playerFrame.player2CardTotalText:SetText("15")
            elseif playerFrame.player2CardTotalText:GetText() == "6 or 16" then
                playerFrame.player2CardTotalText:SetText("16")
            elseif playerFrame.player2CardTotalText:GetText() == "7 or 17" then
                playerFrame.player2CardTotalText:SetText("17")
            elseif playerFrame.player2CardTotalText:GetText() == "8 or 18" then
                playerFrame.player2CardTotalText:SetText("18")
            elseif playerFrame.player2CardTotalText:GetText() == "9 or 19" then
                playerFrame.player2CardTotalText:SetText("19")
            elseif playerFrame.player2CardTotalText:GetText() == "10 or 20" then
                playerFrame.player2CardTotalText:SetText("20")
            end
            playerFrame.player2HitButton:Disable()
            playerFrame.player2StandButton:Disable()
            playerFrame.player2DoubleButton:Disable()
            playerFrame.player2SplitButton:Disable()
        end
    elseif string.find(message, "%[P3%] Placing") and string.find(message, "main") then
        PlaceBetsMain3() 
        Player3Active = true
        local betAmountMain3 = string.match(message, "(%d+)G")
        if betAmountMain3 then
            PlaceBetsTextMain3(betAmountMain3)
        else
        end
    elseif string.find(message, "%[P3%] Placing") and string.find(message, "Perfect") then
        PlaceBetsPP3()
        local betAmountPP3 = string.match(message, "(%d+)G")
        if betAmountPP3 then
            PlaceBetsTextPP3(betAmountPP3)
        else
        end
    elseif string.find(message, "%[P3%] Placing") and string.find(message, "21") then
        PlaceBets2133()
        local betAmount2133 = string.match(message, "(%d+)G")
        if betAmount2133 then
            PlaceBetsText2133(betAmount2133)
        else
        end
    elseif string.find(message, "%[P3%] Hit") then
        playerFrame.timerText3:SetText("")
        playerFrame.timerText3:Hide()
        countdownDuration = 30
        playerFrame.hitButton3:Disable()
        playerFrame.standButton3:Disable()
        playerFrame.doubleButton3:Disable()
        playerFrame.splitButton3:Disable()
    elseif string.find(message, "%[P3%] Stand") then
        playerFrame.timerText3:SetText("")
        playerFrame.timerText3:Hide()
        countdownDuration = 30
        if Player1Active == false and Player2Active == false and Player3Active == true and Player4Active == false and Player5Active == false then       -- Players: 3
            turn = 9
        elseif Player1Active == true and Player2Active == false and Player3Active == true and Player4Active == false and Player5Active == false then    -- Players: 1 3
            turn = 17
        elseif Player1Active == false and Player2Active == true and Player3Active == true and Player4Active == false and Player5Active == false then    -- Players: 2 3
            turn = 17
        elseif Player1Active == false and Player2Active == false and Player3Active == true and Player4Active == true and Player5Active == false then    -- Players: 3 4
            turn = 11
        elseif Player1Active == false and Player2Active == false and Player3Active == true and Player4Active == false and Player5Active == true then    -- Players: 3 5
            turn = 11
        elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == false and Player5Active == false then    -- Players: 1 2 3
            turn = 25
        elseif Player1Active == true and Player2Active == false and Player3Active == true and Player4Active == true and Player5Active == false then    -- Players: 1 3 4
            turn = 19
        elseif Player1Active == true and Player2Active == false and Player3Active == true and Player4Active == false and Player5Active == true then    -- Players: 1 3 5
            turn = 19
        elseif Player1Active == false and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == false then    -- Players: 2 3 4
            turn = 19
        elseif Player1Active == false and Player2Active == true and Player3Active == true and Player4Active == false and Player5Active == true then    -- Players: 2 3 5
            turn = 19
        elseif Player1Active == false and Player2Active == false and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 3 4 5
            turn = 13
        elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == false then    -- Players: 1 2 3 4
            turn = 27
        elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == false and Player5Active == true then    -- Players: 1 2 3 5
            turn = 27
        elseif Player1Active == true and Player2Active == false and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 1 3 4 5
            turn = 21
        elseif Player1Active == false and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 2 3 4 5
            turn = 21
        elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 1 2 3 4 5
            turn = 29
        end
        playerFrame.hitButton3:Disable()
        playerFrame.standButton3:Disable()
        playerFrame.doubleButton3:Disable()
        playerFrame.splitButton3:Disable()
    elseif string.find(message, "%[P3%] Double") then
        local betDoubleAmount3 = string.match(message, "Double my bet to (%d+)G")
        if betDoubleAmount3 then
            mainBetAmount3:SetText(betDoubleAmount3 .. " G")
            PlaySoundFile(soundFilePaths[43])
            playerFrame.timerText3:SetText("")
            playerFrame.timerText3:Hide()
            countdownDuration = 30
            if Player1Active == false and Player2Active == false and Player3Active == true and Player4Active == false and Player5Active == false then       -- Players: 3
                turn = 8
            elseif Player1Active == true and Player2Active == false and Player3Active == true and Player4Active == false and Player5Active == false then    -- Players: 1 3
                turn = 16
            elseif Player1Active == false and Player2Active == true and Player3Active == true and Player4Active == false and Player5Active == false then    -- Players: 2 3
                turn = 16
            elseif Player1Active == false and Player2Active == false and Player3Active == true and Player4Active == true and Player5Active == false then    -- Players: 3 4
                turn = 10
            elseif Player1Active == false and Player2Active == false and Player3Active == true and Player4Active == false and Player5Active == true then    -- Players: 3 5
                turn = 10
            elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == false and Player5Active == false then    -- Players: 1 2 3
                turn = 24
            elseif Player1Active == true and Player2Active == false and Player3Active == true and Player4Active == true and Player5Active == false then    -- Players: 1 3 4
                turn = 18
            elseif Player1Active == true and Player2Active == false and Player3Active == true and Player4Active == false and Player5Active == true then    -- Players: 1 3 5
                turn = 18
            elseif Player1Active == false and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == false then    -- Players: 2 3 4
                turn = 18
            elseif Player1Active == false and Player2Active == true and Player3Active == true and Player4Active == false and Player5Active == true then    -- Players: 2 3 5
                turn = 18
            elseif Player1Active == false and Player2Active == false and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 3 4 5
                turn = 12
            elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == false then    -- Players: 1 2 3 4
                turn = 26
            elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == false and Player5Active == true then    -- Players: 1 2 3 5
                turn = 26
            elseif Player1Active == true and Player2Active == false and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 1 3 4 5
                turn = 20
            elseif Player1Active == false and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 2 3 4 5
                turn = 20
            elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 1 2 3 4 5
                turn = 28
            end
            playerFrame.hitButton3:Disable()
            playerFrame.standButton3:Disable()
            playerFrame.doubleButton3:Disable()
            playerFrame.splitButton3:Disable()
        end
    elseif string.find(message, "%[P4%] Placing") and string.find(message, "main") then
        PlaceBetsMain4() 
        Player4Active = true
        local betAmountMain4 = string.match(message, "(%d+)G")
        if betAmountMain4 then
            PlaceBetsTextMain4(betAmountMain4)
        else
        end
    elseif string.find(message, "%[P4%] Placing") and string.find(message, "Perfect") then
        PlaceBetsPP4()
        local betAmountPP4 = string.match(message, "(%d+)G")
        if betAmountPP4 then
            PlaceBetsTextPP4(betAmountPP4)
        else
        end
    elseif string.find(message, "%[P4%] Placing") and string.find(message, "21") then
        PlaceBets2134()
        local betAmount2134 = string.match(message, "(%d+)G")
        if betAmount2134 then
            PlaceBetsText2134(betAmount2134)
        else
        end
    elseif string.find(message, "%[P4%] Hit") then
        playerFrame.timerText4:SetText("")
        playerFrame.timerText4:Hide()
        countdownDuration = 30
        playerFrame.hitButton4:Disable()
        playerFrame.standButton4:Disable()
        playerFrame.doubleButton4:Disable()
        playerFrame.splitButton4:Disable()
    elseif string.find(message, "%[P4%] Stand") then
        playerFrame.timerText4:SetText("")
        playerFrame.timerText4:Hide()
        countdownDuration = 30
        if Player1Active == false and Player2Active == false and Player3Active == false and Player4Active == true and Player5Active == false then       -- Players: 4
            turn = 9
        elseif Player1Active == true and Player2Active == false and Player3Active == false and Player4Active == true and Player5Active == false then    -- Players: 1 4
            turn = 17
        elseif Player1Active == false and Player2Active == true and Player3Active == false and Player4Active == true and Player5Active == false then    -- Players: 2 4
            turn = 17
        elseif Player1Active == false and Player2Active == false and Player3Active == true and Player4Active == true and Player5Active == false then    -- Players: 3 4
            turn = 17
        elseif Player1Active == false and Player2Active == false and Player3Active == false and Player4Active == true and Player5Active == true then    -- Players: 4 5
            turn = 11
        elseif Player1Active == true and Player2Active == true and Player3Active == false and Player4Active == true and Player5Active == false then    -- Players: 1 2 4
            turn = 25
        elseif Player1Active == true and Player2Active == false and Player3Active == true and Player4Active == true and Player5Active == false then    -- Players: 1 3 4
            turn = 25
        elseif Player1Active == true and Player2Active == false and Player3Active == false and Player4Active == true and Player5Active == true then    -- Players: 1 4 5
            turn = 19
        elseif Player1Active == false and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == false then    -- Players: 2 3 4
            turn = 25
        elseif Player1Active == false and Player2Active == true and Player3Active == false and Player4Active == true and Player5Active == true then    -- Players: 2 4 5
            turn = 19
        elseif Player1Active == false and Player2Active == false and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 3 4 5
            turn = 19
        elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == false then    -- Players: 1 2 3 4
            turn = 33
        elseif Player1Active == true and Player2Active == true and Player3Active == false and Player4Active == true and Player5Active == true then    -- Players: 1 2 4 5
            turn = 27
        elseif Player1Active == true and Player2Active == false and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 1 3 4 5
            turn = 27
        elseif Player1Active == false and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 2 3 4 5
            turn = 27
        elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 1 2 3 4 5
            turn = 35
        end
        playerFrame.hitButton4:Disable()
        playerFrame.standButton4:Disable()
        playerFrame.doubleButton4:Disable()
        playerFrame.splitButton4:Disable()
    elseif string.find(message, "%[P4%] Double") then
        local betDoubleAmount4 = string.match(message, "Double my bet to (%d+)G")
        if betDoubleAmount4 then
            mainBetAmount4:SetText(betDoubleAmount4 .. " G")
            PlaySoundFile(soundFilePaths[43])
            playerFrame.timerText4:SetText("")
            playerFrame.timerText4:Hide()
            countdownDuration = 30
            if Player1Active == false and Player2Active == false and Player3Active == false and Player4Active == true and Player5Active == false then       -- Players: 4
                turn = 8
            elseif Player1Active == true and Player2Active == false and Player3Active == false and Player4Active == true and Player5Active == false then    -- Players: 1 4
                turn = 16
            elseif Player1Active == false and Player2Active == true and Player3Active == false and Player4Active == true and Player5Active == false then    -- Players: 2 4
                turn = 16
            elseif Player1Active == false and Player2Active == false and Player3Active == true and Player4Active == true and Player5Active == false then    -- Players: 3 4
                turn = 16
            elseif Player1Active == false and Player2Active == false and Player3Active == false and Player4Active == true and Player5Active == true then    -- Players: 4 5
                turn = 10
            elseif Player1Active == true and Player2Active == true and Player3Active == false and Player4Active == true and Player5Active == false then    -- Players: 1 2 4
                turn = 24
            elseif Player1Active == true and Player2Active == false and Player3Active == true and Player4Active == true and Player5Active == false then    -- Players: 1 3 4
                turn = 24
            elseif Player1Active == true and Player2Active == false and Player3Active == false and Player4Active == true and Player5Active == true then    -- Players: 1 4 5
                turn = 18
            elseif Player1Active == false and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == false then    -- Players: 2 3 4
                turn = 24
            elseif Player1Active == false and Player2Active == true and Player3Active == false and Player4Active == true and Player5Active == true then    -- Players: 2 4 5
                turn = 18
            elseif Player1Active == false and Player2Active == false and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 3 4 5
                turn = 18
            elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == false then    -- Players: 1 2 3 4
                turn = 32
            elseif Player1Active == true and Player2Active == true and Player3Active == false and Player4Active == true and Player5Active == true then    -- Players: 1 2 4 5
                turn = 26
            elseif Player1Active == true and Player2Active == false and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 1 3 4 5
                turn = 26
            elseif Player1Active == false and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 2 3 4 5
                turn = 26
            elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 1 2 3 4 5
                turn = 34
            end
            playerFrame.hitButton4:Disable()
            playerFrame.standButton4:Disable()
            playerFrame.doubleButton4:Disable()
            playerFrame.splitButton4:Disable()
        end
    elseif string.find(message, "%[P5%] Placing") and string.find(message, "main") then
        PlaceBetsMain5() 
        Player5Active = true
        local betAmountMain5 = string.match(message, "(%d+)G")
        if betAmountMain5 then
            PlaceBetsTextMain5(betAmountMain5)
        else
        end
    elseif string.find(message, "%[P5%] Placing") and string.find(message, "Perfect") then
        PlaceBetsPP5()
        local betAmountPP5 = string.match(message, "(%d+)G")
        if betAmountPP5 then
            PlaceBetsTextPP5(betAmountPP5)
        else
        end
    elseif string.find(message, "%[P5%] Placing") and string.find(message, "21") then
        PlaceBets2135()
        local betAmount2135 = string.match(message, "(%d+)G")
        if betAmount2135 then
            PlaceBetsText2135(betAmount2135)
        else
        end
    elseif string.find(message, "%[P5%] Hit") then
        playerFrame.timerText5:SetText("")
        playerFrame.timerText5:Hide()
        countdownDuration = 30
        playerFrame.hitButton5:Disable()
        playerFrame.standButton5:Disable()
        playerFrame.doubleButton5:Disable()
        playerFrame.splitButton5:Disable()
    elseif string.find(message, "%[P5%] Stand") then
        playerFrame.timerText5:SetText("")
        playerFrame.timerText5:Hide()
        countdownDuration = 30
        if Player1Active == false and Player2Active == false and Player3Active == false and Player4Active == false and Player5Active == true then       -- Players: 5
            turn = 9
        elseif Player1Active == true and Player2Active == false and Player3Active == false and Player4Active == false and Player5Active == true then    -- Players: 1 5
            turn = 17
        elseif Player1Active == false and Player2Active == true and Player3Active == false and Player4Active == false and Player5Active == true then    -- Players: 2 5
            turn = 17
        elseif Player1Active == false and Player2Active == false and Player3Active == true and Player4Active == false and Player5Active == true then    -- Players: 3 5
            turn = 17
        elseif Player1Active == false and Player2Active == false and Player3Active == false and Player4Active == true and Player5Active == true then    -- Players: 4 5
            turn = 17
        elseif Player1Active == true and Player2Active == true and Player3Active == false and Player4Active == false and Player5Active == true then    -- Players: 1 2 5
            turn = 25
        elseif Player1Active == true and Player2Active == false and Player3Active == true and Player4Active == false and Player5Active == true then    -- Players: 1 3 5
            turn = 25
        elseif Player1Active == true and Player2Active == false and Player3Active == false and Player4Active == true and Player5Active == true then    -- Players: 1 4 5
            turn = 25
        elseif Player1Active == false and Player2Active == true and Player3Active == true and Player4Active == false and Player5Active == true then    -- Players: 2 3 5
            turn = 25
        elseif Player1Active == false and Player2Active == true and Player3Active == false and Player4Active == true and Player5Active == true then    -- Players: 2 4 5
            turn = 25
        elseif Player1Active == false and Player2Active == false and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 3 4 5
            turn = 25
        elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == false and Player5Active == true then    -- Players: 1 2 3 5
            turn = 33
        elseif Player1Active == true and Player2Active == true and Player3Active == false and Player4Active == true and Player5Active == true then    -- Players: 1 2 4 5
            turn = 33
        elseif Player1Active == true and Player2Active == false and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 1 3 4 5
            turn = 33
        elseif Player1Active == false and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 2 3 4 5
            turn = 33
        elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 1 2 3 4 5
            turn = 41
        end
        playerFrame.hitButton5:Disable()
        playerFrame.standButton5:Disable()
        playerFrame.doubleButton5:Disable()
        playerFrame.splitButton5:Disable()
    elseif string.find(message, "%[P5%] Double") then
        local betDoubleAmount5 = string.match(message, "Double my bet to (%d+)G")
        if betDoubleAmount5 then
            mainBetAmount5:SetText(betDoubleAmount5 .. " G")
            PlaySoundFile(soundFilePaths[43])
            playerFrame.timerText5:SetText("")
            playerFrame.timerText5:Hide()
            countdownDuration = 30
            if Player1Active == false and Player2Active == false and Player3Active == false and Player4Active == false and Player5Active == true then       -- Players: 5
                turn = 8
            elseif Player1Active == true and Player2Active == false and Player3Active == false and Player4Active == false and Player5Active == true then    -- Players: 1 5
                turn = 16
            elseif Player1Active == false and Player2Active == true and Player3Active == false and Player4Active == false and Player5Active == true then    -- Players: 2 5
                turn = 16
            elseif Player1Active == false and Player2Active == false and Player3Active == true and Player4Active == false and Player5Active == true then    -- Players: 3 5
                turn = 16
            elseif Player1Active == false and Player2Active == false and Player3Active == false and Player4Active == true and Player5Active == true then    -- Players: 4 5
                turn = 16
            elseif Player1Active == true and Player2Active == true and Player3Active == false and Player4Active == false and Player5Active == true then    -- Players: 1 2 5
                turn = 24
            elseif Player1Active == true and Player2Active == false and Player3Active == true and Player4Active == false and Player5Active == true then    -- Players: 1 3 5
                turn = 24
            elseif Player1Active == true and Player2Active == false and Player3Active == false and Player4Active == true and Player5Active == true then    -- Players: 1 4 5
                turn = 24
            elseif Player1Active == false and Player2Active == true and Player3Active == true and Player4Active == false and Player5Active == true then    -- Players: 2 3 5
                turn = 24
            elseif Player1Active == false and Player2Active == true and Player3Active == false and Player4Active == true and Player5Active == true then    -- Players: 2 4 5
                turn = 24
            elseif Player1Active == false and Player2Active == false and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 3 4 5
                turn = 24
            elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == false and Player5Active == true then    -- Players: 1 2 3 5
                turn = 32
            elseif Player1Active == true and Player2Active == true and Player3Active == false and Player4Active == true and Player5Active == true then    -- Players: 1 2 4 5
                turn = 32
            elseif Player1Active == true and Player2Active == false and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 1 3 4 5
                turn = 32
            elseif Player1Active == false and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 2 3 4 5
                turn = 32
            elseif Player1Active == true and Player2Active == true and Player3Active == true and Player4Active == true and Player5Active == true then    -- Players: 1 2 3 4 5
                turn = 40
            end
            playerFrame.hitButton5:Disable()
            playerFrame.standButton5:Disable()
            playerFrame.doubleButton5:Disable()
            playerFrame.splitButton5:Disable()
        end
    else     
    end
    AddMessageToScrollFrame(message, sender)
end)

















function timerReset()
    playerFrame.timerText1:SetText("")
    playerFrame.timerText1:Hide()
    playerFrame.timerText2:SetText("")
    playerFrame.timerText2:Hide()
    playerFrame.timerText3:SetText("")
    playerFrame.timerText3:Hide()
    playerFrame.timerText4:SetText("")
    playerFrame.timerText4:Hide()
    playerFrame.timerText5:SetText("")
    playerFrame.timerText5:Hide()
    playerFrame.timerTextBets:SetText("")
    playerFrame.timerTextBets:Hide()
    countdownDuration = 30
end

function roundStarted()

    -- "Place your bets" message
    playerFrame.timerTextBets:Hide()
    countdownDuration = 30

    -- Player 1 bet buttons disabled
    player1ConfirmMainBetButton:Disable()
    player1ConfirmPPBetButton:Disable()
    player1Confirm213BetButton:Disable()

    -- Player 2 bet buttons disabled
    player2ConfirmMainBetButton:Disable()
    player2ConfirmPPBetButton:Disable()
    player2Confirm213BetButton:Disable()

end

function insuranceAvailable()

    -- Player 1
    playerFrame.player1InsuranceYesButton:Enable()
    playerFrame.player1InsuranceNoButton:Enable()
    playerFrame.player1HitButton:Disable()
    playerFrame.player1StandButton:Disable()
    playerFrame.player1DoubleButton:Disable()

    -- Player 2
    playerFrame.player2InsuranceYesButton:Enable()
    playerFrame.player2InsuranceNoButton:Enable()
    playerFrame.player2HitButton:Disable()
    playerFrame.player2StandButton:Disable()
    playerFrame.player2DoubleButton:Disable()

end



















-- Reacts to the Dealer "New Game" button - "I have started a new round."
function betReset()
    playerFrame.player1HitButton:Show()
    playerFrame.player1StandButton:Show()
    playerFrame.player1DoubleButton:Show()
    playerFrame.player1SplitButton:Show()
    playerFrame.player1InsuranceYesButton:Show()
    playerFrame.player1InsuranceNoButton:Show()
    playerFrame.player1InsuranceTitle:Show()
    playerFrame.player1InsuranceSubtitle:Show()
    player1MainBetEditBox:Show()
    playerFrame.player1MainBetTitle:Show()
    player1ConfirmMainBetButton:Enable()
    player1ConfirmMainBetButton:Show()
    player1ConfirmPPBetButton:Enable()
    player1Confirm213BetButton:Enable()
    player1MainBetEditBox:Enable()
    player1MainBetEditBox:SetText("")
    player1PPBetEditBox:Enable()
    player1PPBetEditBox:SetText("")
    player1213BetEditBox:Enable()
    player1213BetEditBox:SetText("")
    playerFrame.player1HitButton:Disable()
    playerFrame.player1StandButton:Disable()
    playerFrame.player1DoubleButton:Disable()
    playerFrame.player1SplitButton:Disable()
    playerFrame.player1MainBetCoins:Hide()
    playerFrame.player1NormalWinCoins:Hide()
    playerFrame.player1SplitHand2Coins:Hide()
    playerFrame.player1SplitHand2DoubleCoins:Hide()
    playerFrame.player1SplitHand2NormalWinCoins:Hide()
    playerFrame.player1SplitHand1Coins:Hide()
    playerFrame.player1SplitHand1DoubleCoins:Hide()
    playerFrame.player1SplitHand1NormalWinCoins:Hide()
    playerFrame.player1BJWinCoins:Hide()
    playerFrame.player1SplitHand2BJWinCoins:Hide()
    playerFrame.player1SplitHand1BJWinCoins:Hide()
    playerFrame.player1DoubleBetCoins:Hide()
    playerFrame.player1PPBetCoins:Hide()
    playerFrame.player1213BetCoins:Hide()
    playerFrame.player1PPWinCoins:Hide()
    playerFrame.player1213WinCoins:Hide()
    player1MainBetAmount:Hide()
    player1SplitH1BetAmount:Hide()
    player1SplitH2BetAmount:Hide()
    player1PPBetAmount:Hide()
    player1213BetAmount:Hide()
    player1InsuranceYesIcon:Hide()
    player1InsuranceNoIcon:Hide()
    playerFrame.player1InsuranceYesButton:Disable()
    playerFrame.player1InsuranceNoButton:Disable()
    playerFrame.player1InsuranceBetAmount:SetText("")
    playerFrame.player1PPWinCoins:Hide()
    playerFrame.player1213WinCoins:Hide()
    playerFrame.player1BJWinCoins:Hide()
    playerFrame.player1SplitH1Title:Hide()
    playerFrame.player1SplitH2Title:Hide()
    player1SplitH1EditBox:Hide()
    player1SplitH2EditBox:Hide()
    playerFrame.player1HitButtonSplitH1:Hide()
    playerFrame.player1StandButtonSplitH1:Hide()
    playerFrame.player1DoubleButtonSplitH1:Hide()
    playerFrame.player1HitButtonSplitH2:Hide()
    playerFrame.player1StandButtonSplitH2:Hide()
    playerFrame.player1DoubleButtonSplitH2:Hide()


    player2ConfirmMainBetButton:Enable()
    player2ConfirmPPBetButton:Enable()
    player2Confirm213BetButton:Enable()
    player2MainBetEditBox:Enable()
    player2MainBetEditBox:SetText("")
    player2PPBetEditBox:Enable()
    player2PPBetEditBox:SetText("")
    player2213BetEditBox:Enable()
    player2213BetEditBox:SetText("")
    playerFrame.player2HitButton:Disable()
    playerFrame.player2StandButton:Disable()
    playerFrame.player2DoubleButton:Disable()
    playerFrame.coinsMainBet2:Hide()
    playerFrame.coinsDoubleBet2:Hide()
    playerFrame.player2CoinsPPBet:Hide()
    playerFrame.player2Coins213Bet:Hide()
    player2MainBetAmount:Hide()
    player2PPBetAmount:Hide()
    player2213BetAmount:Hide()
    insuranceYesIcon2:Hide()
    insuranceNoIcon2:Hide()
    playerFrame.player2InsuranceYesButton:Disable()
    playerFrame.player2InsuranceNoButton:Disable()
    playerFrame.player2InsuranceBetAmount:SetText("")
    playerFrame.player2CoinsPPWin:Hide()
    playerFrame.player2Coins213Win:Hide()
    playerFrame.coinsBJWin2:Hide()
    
    playerFrame.timerText1:SetText("")
    playerFrame.timerText1:Hide()
    playerFrame.timerText2:SetText("")
    playerFrame.timerText2:Hide()
    playerFrame.timerText3:SetText("")
    playerFrame.timerText3:Hide()
    playerFrame.timerText4:SetText("")
    playerFrame.timerText4:Hide()
    playerFrame.timerText5:SetText("")
    playerFrame.timerText5:Hide()
    playerFrame.timerTextBets:SetText("")
    playerFrame.timerTextBets:Hide()
    countdownDuration = 30
    turn = 0
    
    playerFrame.player1CardTotalText:SetTextColor(1, 1, 1)
    playerFrame.player1SplitHand1CardTotalText:SetTextColor(1, 1, 1)
    playerFrame.player1SplitHand2CardTotalText:SetTextColor(1, 1, 1)
    playerFrame.player2CardTotalText:SetTextColor(1, 1, 1)
    playerFrame.dealerCardTotalText:SetTextColor(1, 1, 1)
    player1MainBetAmount:SetTextColor(1, 1, 1)
    player1SplitH1BetAmount:SetTextColor(1, 1, 1)
    player1SplitH2BetAmount:SetTextColor(1, 1, 1)
    player1PPBetAmount:SetTextColor(1, 1, 1)
    player1213BetAmount:SetTextColor(1, 1, 1)
    player1PPBetAmount:SetPoint("CENTER", playerFrame, 275, 60)
    player1213BetAmount:SetPoint("CENTER", playerFrame, 345, 156)
    
    player1MainCardName1 = nil
    player1MainCardName2 = nil
    player1MainCardName3 = nil
    player1MainCardName4 = nil
    player1MainCardName5 = nil
    player1MainCardName6 = nil
    player1MainCardName7 = nil
    player1MainCardFileName1 = nil
    player1MainCardFileName2 = nil
    player1MainCardFileName3 = nil
    player1MainCardFileName4 = nil
    player1MainCardFileName5 = nil
    player1MainCardFileName6 = nil
    player1MainCardFileName7 = nil
    player1H1CardName1 = nil
    player1H1CardName2 = nil
    player1H1CardName3 = nil
    player1H1CardName4 = nil
    player1H1CardName5 = nil
    player1H1CardName6 = nil
    player1H1CardName7 = nil
    player1H1CardFileName1 = nil
    player1H1CardFileName2 = nil
    player1H1CardFileName3 = nil
    player1H1CardFileName4 = nil
    player1H1CardFileName5 = nil
    player1H1CardFileName6 = nil
    player1H1CardFileName7 = nil
    player1H2CardName1 = nil
    player1H2CardName2 = nil
    player1H2CardName3 = nil
    player1H2CardName4 = nil
    player1H2CardName5 = nil
    player1H2CardName6 = nil
    player1H2CardName7 = nil
    player1H2CardFileName1 = nil
    player1H2CardFileName2 = nil
    player1H2CardFileName3 = nil
    player1H2CardFileName4 = nil
    player1H2CardFileName5 = nil
    player1H2CardFileName6 = nil
    player1H2CardFileName7 = nil

    dealerCardName1 = nil
    dealerCardName2 = nil
    dealerCardName3 = nil
    dealerCardName4 = nil
    dealerCardName5 = nil
    dealerCardName6 = nil
    dealerCardName7 = nil
    dealerCardFileName1 = nil
    dealerCardFileName2 = nil
    dealerCardFileName3 = nil
    dealerCardFileName4 = nil
    dealerCardFileName5 = nil
    dealerCardFileName6 = nil
    dealerCardFileName7 = nil

    player1NumberOfCards = 0
    player1NumberOfCardsH1 = 0
    player1SessionWin = 0

    if dealtCardsFramePlayer1H1:IsShown() then
        dealtCardsFramePlayer1H1:Hide()
        dealtCardsFramePlayer1H1.playerH1CardsButton:Hide()
        dealtCardsFramePlayer1H1.playerH2CardsButton:Hide()
        dealtCardsFramePlayer1H1.dealerCardsButton:Hide()
        dealtCardsFramePlayer1H2:Hide()
        dealtCardsFramePlayer1H2.playerH1CardsButton:Hide()
        dealtCardsFramePlayer1H2.playerH2CardsButton:Hide()
        dealtCardsFramePlayer1H2.dealerCardsButton:Hide()
        dealtCardsFrameDealerSplit:Hide()
        dealtCardsFrameDealerSplit.playerH1CardsButton:Hide()
        dealtCardsFrameDealerSplit.playerH2CardsButton:Hide()
        dealtCardsFrameDealerSplit.dealerCardsButton:Hide()
        dealtCardsFramePlayer:Show()
        dealtCardsFramePlayer.playerCardsButton:Show()
        dealtCardsFramePlayer.dealerCardsButton:Show()
        dealtCardsFramePlayer.notStartedYetText:Show()
    elseif dealtCardsFramePlayer1H2:IsShown() then
        dealtCardsFramePlayer1H1:Hide()
        dealtCardsFramePlayer1H1.playerH1CardsButton:Hide()
        dealtCardsFramePlayer1H1.playerH2CardsButton:Hide()
        dealtCardsFramePlayer1H1.dealerCardsButton:Hide()
        dealtCardsFramePlayer1H2:Hide()
        dealtCardsFramePlayer1H2.playerH1CardsButton:Hide()
        dealtCardsFramePlayer1H2.playerH2CardsButton:Hide()
        dealtCardsFramePlayer1H2.dealerCardsButton:Hide()
        dealtCardsFrameDealerSplit:Hide()
        dealtCardsFrameDealerSplit.playerH1CardsButton:Hide()
        dealtCardsFrameDealerSplit.playerH2CardsButton:Hide()
        dealtCardsFrameDealerSplit.dealerCardsButton:Hide()
        dealtCardsFramePlayer:Show()
        dealtCardsFramePlayer.playerCardsButton:Show()
        dealtCardsFramePlayer.dealerCardsButton:Show()
        dealtCardsFramePlayer.notStartedYetText:Show()
    elseif dealtCardsFrameDealerSplit:IsShown() then
        dealtCardsFramePlayer1H1:Hide()
        dealtCardsFramePlayer1H1.playerH1CardsButton:Hide()
        dealtCardsFramePlayer1H1.playerH2CardsButton:Hide()
        dealtCardsFramePlayer1H1.dealerCardsButton:Hide()
        dealtCardsFramePlayer1H2:Hide()
        dealtCardsFramePlayer1H2.playerH1CardsButton:Hide()
        dealtCardsFramePlayer1H2.playerH2CardsButton:Hide()
        dealtCardsFramePlayer1H2.dealerCardsButton:Hide()
        dealtCardsFrameDealerSplit:Hide()
        dealtCardsFrameDealerSplit.playerH1CardsButton:Hide()
        dealtCardsFrameDealerSplit.playerH2CardsButton:Hide()
        dealtCardsFrameDealerSplit.dealerCardsButton:Hide()
        dealtCardsFramePlayer:Show()
        dealtCardsFramePlayer.playerCardsButton:Show()
        dealtCardsFramePlayer.dealerCardsButton:Show()
        dealtCardsFramePlayer.notStartedYetText:Show()
    end

    dealtCardsFramePlayer.notStartedYetText:Show()
    dealtCardsFrameDealer.notStartedYetText:Show()

    player1DoubleToggle = false
    player1SplitToggle = false
    player1DoubleHand1Toggle = false
    player1DoubleHand2Toggle = false
    double2Flag = false

    player1PPSideBetWin = false
    player1213SideBetWin = false
    player2PPSideBetWin = false
    player2213SideBetWin = false

    sideBetWinFramePP:Hide()
    sideBetWinFrame213:Hide()
    sideBetWinFramePP.title:Hide()
    sideBetWinFrame213.title:Hide()
    sideBetWinFramePP.PPtext:Hide()
    sideBetWinFrame213.t213text:Hide()
    sideBetWinFramePP.MixedPairText:Hide()
    sideBetWinFramePP.ColouredPairText:Hide()
    sideBetWinFramePP.PerfectPairText:Hide()
    sideBetWinFrame213.FlushText:Hide()
    sideBetWinFrame213.StraightText:Hide()
    sideBetWinFrame213.ThreeOfAKindText:Hide()
    sideBetWinFrame213.StraightFlushText:Hide()
    sideBetWinFrame213.SuitedThreeOfAKindText:Hide()
    sideBetWinFramePP.player1PPCardImage1:Hide()
    sideBetWinFramePP.player1PPCardImage2:Hide()
    sideBetWinFrame213.player1213CardImage1:Hide()
    sideBetWinFrame213.player1213CardImage2:Hide()
    sideBetWinFrame213.dealer213CardImage1:Hide()
    sideBetWinFrame213.PlusSymbol:Hide()

    player1PreloadBetButton:Enable()
    player2PreloadBetButton:Enable()

    dealtCardsFramePlayer.notStartedYetText:Show()
    gameRunning = false

    player1MainBet = 0
    player1PPBet = 0
    player1213Bet = 0

end













-- Function to handle Player 1 PP Win Image
function player1PlaceBetsPPWin(message)
    playerFrame.player1PPBetCoins:Hide()
    playerFrame.player1PPWinCoins:Show()
    player1PPBetAmount:SetPoint("CENTER", playerFrame, 274, 77)
end

-- Function to handle Player 1 21+3 Win Image
function player1PlaceBets213Win(message)
    playerFrame.player1213BetCoins:Hide()
    playerFrame.player1213WinCoins:Show()
    player1213BetAmount:SetPoint("CENTER", playerFrame, 345, 174)
end

function player1MixedPairWin(message)
    player1PPBetAmountValue = tonumber(string.match(player1PPBetEditBox:GetText(), "%d+"))
    if player1PPBetAmountValue then
        player1NewPPAmount = player1PPBetAmountValue * 6
        player1PPBetAmount:SetText(player1NewPPAmount .. " G")
        player1PPBetAmount:SetTextColor(0, 1, 0)

        player1PPProfitvalue = player1NewPPAmount - player1PPBetAmountValue

        player1totalWin = player1totalWin + tonumber(player1PPProfitvalue)
        historyFrame.player1totalWonAmount:SetText(player1totalWin .. " G")

        player1totalProfit = player1totalProfit + tonumber(player1PPProfitvalue)
        historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

        if player1totalProfit >= 0 then
            historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
        else
            historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
        end

        player1TotalBankrollAmount = player1TotalBankrollAmount + tonumber(player1NewPPAmount)
        bankrollFrame.player1TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
        cashDeskFrame.player1TotalBankroll:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")

    end
    player1PlaceBetsPPWin()
    player1PPSideBetWin = true

    player1SessionWin = player1SessionWin + tonumber(player1NewPPAmount)

end

function player1ColouredPairWin(message)
    player1PPBetAmountValue = tonumber(string.match(player1PPBetEditBox:GetText(), "%d+"))
    if player1PPBetAmountValue then
        player1NewPPAmount = player1PPBetAmountValue * 11
        player1PPBetAmount:SetText(player1NewPPAmount .. " G")
        player1PPBetAmount:SetTextColor(0, 1, 0)

        player1PPProfitvalue = player1NewPPAmount - player1PPBetAmountValue

        player1totalWin = player1totalWin + tonumber(player1PPProfitvalue)
        historyFrame.player1totalWonAmount:SetText(player1totalWin .. " G")

        player1totalProfit = player1totalProfit + tonumber(player1PPProfitvalue)
        historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

        if player1totalProfit >= 0 then
            historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
        else
            historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
        end

        player1TotalBankrollAmount = player1TotalBankrollAmount + tonumber(player1NewPPAmount)
        bankrollFrame.player1TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
        cashDeskFrame.player1TotalBankroll:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")

    end
    player1PlaceBetsPPWin()
    player1PPSideBetWin = true

    player1SessionWin = player1SessionWin + tonumber(player1NewPPAmount)

end

function player1PerfectPairWin(message)
    player1PPBetAmountValue = tonumber(string.match(player1PPBetEditBox:GetText(), "%d+"))
    if player1PPBetAmountValue then
        player1NewPPAmount = player1PPBetAmountValue * 31
        player1PPBetAmount:SetText(player1NewPPAmount .. " G")
        player1PPBetAmount:SetTextColor(0, 1, 0)

        player1PPProfitvalue = player1NewPPAmount - player1PPBetAmountValue

        player1totalWin = player1totalWin + tonumber(player1PPProfitvalue)
        historyFrame.player1totalWonAmount:SetText(player1totalWin .. " G")

        player1totalProfit = player1totalProfit + tonumber(player1PPProfitvalue)
        historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

        if player1totalProfit >= 0 then
            historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
        else
            historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
        end

        player1TotalBankrollAmount = player1TotalBankrollAmount + tonumber(player1NewPPAmount)
        bankrollFrame.player1TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
        cashDeskFrame.player1TotalBankroll:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")

    end
    player1PlaceBetsPPWin()
    player1PPSideBetWin = true

    player1SessionWin = player1SessionWin + tonumber(player1NewPPAmount)

end

function player1SuitedThreeOfAKindWin(message)
    player1213BetAmountValue = tonumber(string.match(player1213BetEditBox:GetText(), "%d+"))
    if player1213BetAmountValue then
        player1New213Amount = player1213BetAmountValue * 101
        player1213BetAmount:SetText(player1New213Amount .. " G")
        player1213BetAmount:SetTextColor(0, 1, 0)

        player1213Profitvalue = player1New213Amount - player1213BetAmountValue

        player1totalWin = player1totalWin + tonumber(player1213Profitvalue)
        historyFrame.player1totalWonAmount:SetText(player1totalWin .. " G")

        player1totalProfit = player1totalProfit + tonumber(player1213Profitvalue)
        historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

        if player1totalProfit >= 0 then
            historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
        else
            historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
        end

        player1TotalBankrollAmount = player1TotalBankrollAmount + tonumber(player1New213Amount)
        bankrollFrame.player1TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
        cashDeskFrame.player1TotalBankroll:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")

    end
    player1PlaceBets213Win()
    player1213SideBetWin = true

    player1SessionWin = player1SessionWin + tonumber(player1New213Amount)

end

function player1StraightFlushWin(message)
    player1213BetAmountValue = tonumber(string.match(player1213BetEditBox:GetText(), "%d+"))
    if player1213BetAmountValue then
        player1New213Amount = player1213BetAmountValue * 41
        player1213BetAmount:SetText(player1New213Amount .. " G")
        player1213BetAmount:SetTextColor(0, 1, 0)

        player1213Profitvalue = player1New213Amount - player1213BetAmountValue

        player1totalWin = player1totalWin + tonumber(player1213Profitvalue)
        historyFrame.player1totalWonAmount:SetText(player1totalWin .. " G")

        player1totalProfit = player1totalProfit + tonumber(player1213Profitvalue)
        historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

        if player1totalProfit >= 0 then
            historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
        else
            historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
        end

        player1TotalBankrollAmount = player1TotalBankrollAmount + tonumber(player1New213Amount)
        bankrollFrame.player1TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
        cashDeskFrame.player1TotalBankroll:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")

    end
    player1PlaceBets213Win()
    player1213SideBetWin = true

    player1SessionWin = player1SessionWin + tonumber(player1New213Amount)

end

function player1ThreeOfAKindWin(message)
    player1213BetAmountValue = tonumber(string.match(player1213BetEditBox:GetText(), "%d+"))
    if player1213BetAmountValue then
        player1New213Amount = player1213BetAmountValue * 31
        player1213BetAmount:SetText(player1New213Amount .. " G")
        player1213BetAmount:SetTextColor(0, 1, 0)

        player1213Profitvalue = player1New213Amount - player1213BetAmountValue

        player1totalWin = player1totalWin + tonumber(player1213Profitvalue)
        historyFrame.player1totalWonAmount:SetText(player1totalWin .. " G")

        player1totalProfit = player1totalProfit + tonumber(player1213Profitvalue)
        historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

        if player1totalProfit >= 0 then
            historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
        else
            historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
        end

        player1TotalBankrollAmount = player1TotalBankrollAmount + tonumber(player1New213Amount)
        bankrollFrame.player1TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
        cashDeskFrame.player1TotalBankroll:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")

    end
    player1PlaceBets213Win()
    player1213SideBetWin = true

    player1SessionWin = player1SessionWin + tonumber(player1New213Amount)

end

function player1StraightWin(message)
    player1213BetAmountValue = tonumber(string.match(player1213BetEditBox:GetText(), "%d+"))
    if player1213BetAmountValue then
        player1New213Amount = player1213BetAmountValue * 11
        player1213BetAmount:SetText(player1New213Amount .. " G")
        player1213BetAmount:SetTextColor(0, 1, 0)

        player1213Profitvalue = player1New213Amount - player1213BetAmountValue

        player1totalWin = player1totalWin + tonumber(player1213Profitvalue)
        historyFrame.player1totalWonAmount:SetText(player1totalWin .. " G")

        player1totalProfit = player1totalProfit + tonumber(player1213Profitvalue)
        historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

        if player1totalProfit >= 0 then
            historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
        else
            historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
        end

        player1TotalBankrollAmount = player1TotalBankrollAmount + tonumber(player1New213Amount)
        bankrollFrame.player1TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
        cashDeskFrame.player1TotalBankroll:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")

    end
    player1PlaceBets213Win()
    player1213SideBetWin = true

    player1SessionWin = player1SessionWin + tonumber(player1New213Amount)

end

function player1FlushWin(message)
    player1213BetAmountValue = tonumber(string.match(player1213BetEditBox:GetText(), "%d+"))
    if player1213BetAmountValue then
        player1New213Amount = player1213BetAmountValue * 6
        player1213BetAmount:SetText(player1New213Amount .. " G")
        player1213BetAmount:SetTextColor(0, 1, 0)

        player1213Profitvalue = player1New213Amount - player1213BetAmountValue

        player1totalWin = player1totalWin + tonumber(player1213Profitvalue)
        historyFrame.player1totalWonAmount:SetText(player1totalWin .. " G")

        player1totalProfit = player1totalProfit + tonumber(player1213Profitvalue)
        historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

        if player1totalProfit >= 0 then
            historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
        else
            historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
        end

        player1TotalBankrollAmount = player1TotalBankrollAmount + tonumber(player1New213Amount)
        bankrollFrame.player1TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
        cashDeskFrame.player1TotalBankroll:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")

    end
    player1PlaceBets213Win()
    player1213SideBetWin = true

    player1SessionWin = player1SessionWin + tonumber(player1New213Amount)

end

function player1Loss()
    player1MainBetValue = tonumber(string.match(player1MainBetAmount:GetText(), "%d+"))
    if player1MainBetValue then

        player1totalLoss = player1totalLoss + tonumber(player1MainBetValue)
        historyFrame.player1totalLostAmount:SetText(player1totalLoss .. " G")

        player1totalProfit = player1totalProfit - tonumber(player1MainBetValue)
        historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

        if player1totalProfit >= 0 then
            historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
        else
            historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
        end
        
        local player1PPBetText = player1PPBetAmount:GetText()

        if player1PPBetText and player1PPBetText ~= "" then
            player1PPBetAmountValue = tonumber(string.match(player1PPBetText, "%d+"))
            
            if player1PPBetAmountValue then
                if player1PPSideBetWin == false then

                    player1PPBetAmount:SetTextColor(1, 0, 0)

                    player1totalLoss = player1totalLoss + tonumber(player1PPBetAmountValue)
                    historyFrame.player1totalLostAmount:SetText(player1totalLoss .. " G")

                    player1totalProfit = player1totalProfit - tonumber(player1PPBetAmountValue)
                    historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

                    if player1totalProfit >= 0 then
                        historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
                    else
                        historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
                    end

                end
            end
        end

        local player1213BetText = player1213BetAmount:GetText()

        if player1213BetText and player1213BetText ~= "" then
            player1213BetAmountValue = tonumber(string.match(player1213BetText, "%d+"))

            if player1213BetAmountValue then
                if player1213SideBetWin == false then

                    player1213BetAmount:SetTextColor(1, 0, 0)

                    player1totalLoss = player1totalLoss + tonumber(player1213BetAmountValue)
                    historyFrame.player1totalLostAmount:SetText(player1totalLoss .. " G")

                    player1totalProfit = player1totalProfit - tonumber(player1213BetAmountValue)
                    historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

                    if player1totalProfit >= 0 then
                        historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
                    else
                        historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
                    end

                end
            end
        end
    end
end

function player1SplitH1Loss()
    player1SplitHand1BetAmountValue = tonumber(string.match(player1SplitH1BetAmount:GetText(), "%d+"))
    if player1SplitHand1BetAmountValue then

        player1totalLoss = player1totalLoss + tonumber(player1SplitHand1BetAmountValue)
        historyFrame.player1totalLostAmount:SetText(player1totalLoss .. " G")

        player1totalProfit = player1totalProfit - tonumber(player1SplitHand1BetAmountValue)
        historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

        if player1totalProfit >= 0 then
            historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
        else
            historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
        end

    end
end

function player1SplitH2Loss()
    player1SplitHand2BetAmountValue = tonumber(string.match(player1SplitH2BetAmount:GetText(), "%d+"))
    if player1SplitHand2BetAmountValue then

        player1totalLoss = player1totalLoss + tonumber(player1SplitHand2BetAmountValue)
        historyFrame.player1totalLostAmount:SetText(player1totalLoss .. " G")

        player1totalProfit = player1totalProfit - tonumber(player1SplitHand2BetAmountValue)
        historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

        if player1totalProfit >= 0 then
            historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
        else
            historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
        end

        local player1PPBetText = player1PPBetAmount:GetText()

        if player1PPBetText and player1PPBetText ~= "" then
            player1PPBetAmountValue = tonumber(string.match(player1PPBetText, "%d+"))
            
            if player1PPBetAmountValue then
                if player1PPSideBetWin == false then

                    player1PPBetAmount:SetTextColor(1, 0, 0)

                    player1totalLoss = player1totalLoss + tonumber(player1PPBetAmountValue)
                    historyFrame.player1totalLostAmount:SetText(player1totalLoss .. " G")

                    player1totalProfit = player1totalProfit - tonumber(player1PPBetAmountValue)
                    historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

                    if player1totalProfit >= 0 then
                        historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
                    else
                        historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
                    end

                end
            end
        end

        local player1213BetText = player1213BetAmount:GetText()

        if player1213BetText and player1213BetText ~= "" then
            player1213BetAmountValue = tonumber(string.match(player1213BetText, "%d+"))

            if player1213BetAmountValue then
                if player1213SideBetWin == false then

                    player1213BetAmount:SetTextColor(1, 0, 0)

                    player1totalLoss = player1totalLoss + tonumber(player1213BetAmountValue)
                    historyFrame.player1totalLostAmount:SetText(player1totalLoss .. " G")

                    player1totalProfit = player1totalProfit - tonumber(player1213BetAmountValue)
                    historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

                    if player1totalProfit >= 0 then
                        historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
                    else
                        historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
                    end

                end
            end
        end
    end
end

function player1Push()
    player1MainBetValue = tonumber(string.match(player1MainBetAmount:GetText(), "%d+"))
    if player1MainBetValue then

        player1TotalBankrollAmount = player1TotalBankrollAmount + tonumber(player1MainBetValue)
        bankrollFrame.player1TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
        cashDeskFrame.player1TotalBankroll:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")

        local player1PPBetText = player1PPBetAmount:GetText()

        if player1PPBetText and player1PPBetText ~= "" then
            player1PPBetAmountValue = tonumber(string.match(player1PPBetText, "%d+"))
            
            if player1PPBetAmountValue then
                if player1PPSideBetWin == false then

                    player1PPBetAmount:SetTextColor(1, 0, 0)

                    player1totalLoss = player1totalLoss + tonumber(player1PPBetAmountValue)
                    historyFrame.player1totalLostAmount:SetText(player1totalLoss .. " G")

                    player1totalProfit = player1totalProfit - tonumber(player1PPBetAmountValue)
                    historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

                    if player1totalProfit >= 0 then
                        historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
                    else
                        historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
                    end

                end
            end
        end

        local player1213BetText = player1213BetAmount:GetText()

        if player1213BetText and player1213BetText ~= "" then
            player1213BetAmountValue = tonumber(string.match(player1213BetText, "%d+"))

            if player1213BetAmountValue then
                if player1213SideBetWin == false then

                    player1213BetAmount:SetTextColor(1, 0, 0)

                    player1totalLoss = player1totalLoss + tonumber(player1213BetAmountValue)
                    historyFrame.player1totalLostAmount:SetText(player1totalLoss .. " G")

                    player1totalProfit = player1totalProfit - tonumber(player1213BetAmountValue)
                    historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

                    if player1totalProfit >= 0 then
                        historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
                    else
                        historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
                    end

                end
            end
        end
    end
end

function player1SplitH1Push()
    player1SplitHand1BetAmountValue = tonumber(string.match(player1SplitH1BetAmount:GetText(), "%d+"))
    if player1SplitHand1BetAmountValue then

        player1TotalBankrollAmount = player1TotalBankrollAmount + tonumber(player1SplitHand1BetAmountValue)
        bankrollFrame.player1TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
        cashDeskFrame.player1TotalBankroll:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
    end
end

function player1SplitH2Push()
    player1SplitHand2BetAmountValue = tonumber(string.match(player1SplitH2BetAmount:GetText(), "%d+"))
    if player1SplitHand2BetAmountValue then

        player1TotalBankrollAmount = player1TotalBankrollAmount + tonumber(player1SplitHand2BetAmountValue)
        bankrollFrame.player1TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
        cashDeskFrame.player1TotalBankroll:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")

        local player1PPBetText = player1PPBetAmount:GetText()

        if player1PPBetText and player1PPBetText ~= "" then
            player1PPBetAmountValue = tonumber(string.match(player1PPBetText, "%d+"))
            
            if player1PPBetAmountValue then
                if player1PPSideBetWin == false then

                    player1PPBetAmount:SetTextColor(1, 0, 0)

                    player1totalLoss = player1totalLoss + tonumber(player1PPBetAmountValue)
                    historyFrame.player1totalLostAmount:SetText(player1totalLoss .. " G")

                    player1totalProfit = player1totalProfit - tonumber(player1PPBetAmountValue)
                    historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

                    if player1totalProfit >= 0 then
                        historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
                    else
                        historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
                    end

                end
            end
        end

        local player1213BetText = player1213BetAmount:GetText()

        if player1213BetText and player1213BetText ~= "" then
            player1213BetAmountValue = tonumber(string.match(player1213BetText, "%d+"))

            if player1213BetAmountValue then
                if player1213SideBetWin == false then

                    player1213BetAmount:SetTextColor(1, 0, 0)

                    player1totalLoss = player1totalLoss + tonumber(player1213BetAmountValue)
                    historyFrame.player1totalLostAmount:SetText(player1totalLoss .. " G")

                    player1totalProfit = player1totalProfit - tonumber(player1213BetAmountValue)
                    historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

                    if player1totalProfit >= 0 then
                        historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
                    else
                        historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
                    end

                end
            end
        end
    end
end

function player1BJWin(message)
    player1MainBetAmountValue = tonumber(string.match(player1MainBetAmount:GetText(), "%d+"))
    if player1MainBetAmountValue then
        player1BJWinAmountValue = player1MainBetAmountValue * 2.5
        player1MainBetAmount:SetText(player1BJWinAmountValue .. " G")
    end

    player1BJProfitvalue = player1BJWinAmountValue - player1MainBetAmountValue

    player1totalWin = player1totalWin + tonumber(player1BJProfitvalue)
    historyFrame.player1totalWonAmount:SetText(player1totalWin .. " G")

    player1totalProfit = player1totalProfit + tonumber(player1BJProfitvalue)
    historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

    if player1totalProfit >= 0 then
        historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
    else
        historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
    end

    player1TotalBankrollAmount = player1TotalBankrollAmount + tonumber(player1BJWinAmountValue)
    bankrollFrame.player1TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
    cashDeskFrame.player1TotalBankroll:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")

    local player1PPBetText = player1PPBetAmount:GetText()

    if player1PPBetText and player1PPBetText ~= "" then
        player1PPBetAmountValue = tonumber(string.match(player1PPBetText, "%d+"))
        
        if player1PPBetAmountValue then
            if player1PPSideBetWin == false then

                player1PPBetAmount:SetTextColor(1, 0, 0)

                player1totalLoss = player1totalLoss + tonumber(player1PPBetAmountValue)
                historyFrame.player1totalLostAmount:SetText(player1totalLoss .. " G")

                player1totalProfit = player1totalProfit - tonumber(player1PPBetAmountValue)
                historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

                if player1totalProfit >= 0 then
                    historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
                else
                    historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
                end

            end
        end
    end

    local player1213BetText = player1213BetAmount:GetText()

    if player1213BetText and player1213BetText ~= "" then
        player1213BetAmountValue = tonumber(string.match(player1213BetText, "%d+"))

        if player1213BetAmountValue then
            if player1213SideBetWin == false then

                player1213BetAmount:SetTextColor(1, 0, 0)

                player1totalLoss = player1totalLoss + tonumber(player1213BetAmountValue)
                historyFrame.player1totalLostAmount:SetText(player1totalLoss .. " G")

                player1totalProfit = player1totalProfit - tonumber(player1213BetAmountValue)
                historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

                if player1totalProfit >= 0 then
                    historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
                else
                    historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
                end

            end
        end
    end

    playerFrame.player1MainBetCoins:Hide()
    playerFrame.player1BJWinCoins:Show()

    player1SessionWin = player1SessionWin + tonumber(player1BJWinAmountValue)

end

function player1SplitH1BJ(message)
    player1SplitHand1BetAmountValue = tonumber(string.match(player1SplitH1BetAmount:GetText(), "%d+"))
    if player1SplitHand1BetAmountValue then
        player1SplitHand1BJWinAmountValue = player1SplitHand1BetAmountValue * 2.5
        player1SplitH1BetAmount:SetText(player1SplitHand1BJWinAmountValue .. " G")
    end

    player1SplitHand1BJProfitValue = player1SplitHand1BJWinAmountValue - player1SplitHand1BetAmountValue

    player1totalWin = player1totalWin + tonumber(player1SplitHand1BJProfitValue)
    historyFrame.player1totalWonAmount:SetText(player1totalWin .. " G")

    player1totalProfit = player1totalProfit + tonumber(player1SplitHand1BJProfitValue)
    historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

    if player1totalProfit >= 0 then
        historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
    else
        historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
    end

    player1TotalBankrollAmount = player1TotalBankrollAmount + tonumber(player1SplitHand1BJWinAmountValue)
    bankrollFrame.player1TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
    cashDeskFrame.player1TotalBankroll:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")

    playerFrame.player1SplitHand1Coins:Hide()
    playerFrame.player1SplitHand1BJWinCoins:Show()

end

function player1SplitH2BJ(message)
    player1SplitHand2BetAmountValue = tonumber(string.match(player1SplitH2BetAmount:GetText(), "%d+"))
    if player1SplitHand2BetAmountValue then
        player1SplitHand2BJWinAmountValue = player1SplitHand2BetAmountValue * 2.5
        player1SplitH2BetAmount:SetText(player1SplitHand2BJWinAmountValue .. " G")
    end

    player1SplitHand2BJProfitValue = player1SplitHand2BJWinAmountValue - player1SplitHand2BetAmountValue

    player1totalWin = player1totalWin + tonumber(player1SplitHand2BJProfitValue)
    historyFrame.player1totalWonAmount:SetText(player1totalWin .. " G")

    player1totalProfit = player1totalProfit + tonumber(player1SplitHand2BJProfitValue)
    historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

    if player1totalProfit >= 0 then
        historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
    else
        historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
    end

    player1TotalBankrollAmount = player1TotalBankrollAmount + tonumber(player1SplitHand2BJWinAmountValue)
    bankrollFrame.player1TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
    cashDeskFrame.player1TotalBankroll:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")

    local player1PPBetText = player1PPBetAmount:GetText()

    if player1PPBetText and player1PPBetText ~= "" then
        player1PPBetAmountValue = tonumber(string.match(player1PPBetText, "%d+"))
        
        if player1PPBetAmountValue then
            if player1PPSideBetWin == false then

                player1PPBetAmount:SetTextColor(1, 0, 0)

                player1totalLoss = player1totalLoss + tonumber(player1PPBetAmountValue)
                historyFrame.player1totalLostAmount:SetText(player1totalLoss .. " G")

                player1totalProfit = player1totalProfit - tonumber(player1PPBetAmountValue)
                historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

                if player1totalProfit >= 0 then
                    historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
                else
                    historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
                end

            end
        end
    end

    local player1213BetText = player1213BetAmount:GetText()

    if player1213BetText and player1213BetText ~= "" then
        player1213BetAmountValue = tonumber(string.match(player1213BetText, "%d+"))

        if player1213BetAmountValue then
            if player1213SideBetWin == false then

                player1213BetAmount:SetTextColor(1, 0, 0)

                player1totalLoss = player1totalLoss + tonumber(player1213BetAmountValue)
                historyFrame.player1totalLostAmount:SetText(player1totalLoss .. " G")

                player1totalProfit = player1totalProfit - tonumber(player1213BetAmountValue)
                historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

                if player1totalProfit >= 0 then
                    historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
                else
                    historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
                end

            end
        end
    end

    playerFrame.player1SplitHand2Coins:Hide()
    playerFrame.player1SplitHand2BJWinCoins:Show()

end

function player1Win(message)
    player1MainBetAmountValue = tonumber(string.match(player1MainBetAmount:GetText(), "%d+"))
    if player1MainBetAmountValue then
        player1NormalWinAmountValue = player1MainBetAmountValue * 2
        player1MainBetAmount:SetText(player1NormalWinAmountValue .. " G")

        player1totalWin = player1totalWin + tonumber(player1MainBetAmountValue)
        historyFrame.player1totalWonAmount:SetText(player1totalWin .. " G")

        player1totalProfit = player1totalProfit + tonumber(player1MainBetAmountValue)
        historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

        if player1totalProfit >= 0 then
            historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
        else
            historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
        end

        player1TotalBankrollAmount = player1TotalBankrollAmount + tonumber(player1NormalWinAmountValue)
        bankrollFrame.player1TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
        cashDeskFrame.player1TotalBankroll:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")

        local player1PPBetText = player1PPBetAmount:GetText()

        if player1PPBetText and player1PPBetText ~= "" then
            player1PPBetAmountValue = tonumber(string.match(player1PPBetText, "%d+"))
            
            if player1PPBetAmountValue then
                if player1PPSideBetWin == false then

                    player1PPBetAmount:SetTextColor(1, 0, 0)

                    player1totalLoss = player1totalLoss + tonumber(player1PPBetAmountValue)
                    historyFrame.player1totalLostAmount:SetText(player1totalLoss .. " G")

                    player1totalProfit = player1totalProfit - tonumber(player1PPBetAmountValue)
                    historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

                    if player1totalProfit >= 0 then
                        historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
                    else
                        historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
                    end

                end
            end
        end

        local player1213BetText = player1213BetAmount:GetText()

        if player1213BetText and player1213BetText ~= "" then
            player1213BetAmountValue = tonumber(string.match(player1213BetText, "%d+"))

            if player1213BetAmountValue then
                if player1213SideBetWin == false then

                    player1213BetAmount:SetTextColor(1, 0, 0)

                    player1totalLoss = player1totalLoss + tonumber(player1213BetAmountValue)
                    historyFrame.player1totalLostAmount:SetText(player1totalLoss .. " G")

                    player1totalProfit = player1totalProfit - tonumber(player1213BetAmountValue)
                    historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

                    if player1totalProfit >= 0 then
                        historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
                    else
                        historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
                    end

                end
            end
        end
    end

    playerFrame.player1MainBetCoins:Hide()
    playerFrame.player1NormalWinCoins:Show()

    player1SessionWin = player1SessionWin + tonumber(player1NormalWinAmountValue)

end

function player1SplitH1Win(message)
    player1SplitHand1BetAmountValue = tonumber(string.match(player1SplitH1BetAmount:GetText(), "%d+"))
    if player1SplitHand1BetAmountValue then
        player1SplitHand1NormalWinAmountValue = player1SplitHand1BetAmountValue * 2
        player1SplitH1BetAmount:SetText(player1SplitHand1NormalWinAmountValue .. " G")
    end

    player1totalWin = player1totalWin + tonumber(player1SplitHand1BetAmountValue)
    historyFrame.player1totalWonAmount:SetText(player1totalWin .. " G")

    player1totalProfit = player1totalProfit + tonumber(player1SplitHand1BetAmountValue)
    historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

    if player1totalProfit >= 0 then
        historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
    else
        historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
    end

    player1TotalBankrollAmount = player1TotalBankrollAmount + tonumber(player1SplitHand1NormalWinAmountValue)
    bankrollFrame.player1TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
    cashDeskFrame.player1TotalBankroll:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")

    playerFrame.player1SplitHand1Coins:Hide()
    playerFrame.player1SplitHand1NormalWinCoins:Show()

end

function player1SplitH2Win(message)
    player1SplitHand2BetAmountValue = tonumber(string.match(player1SplitH2BetAmount:GetText(), "%d+"))
    if player1SplitHand2BetAmountValue then
        player1SplitHand2NormalWinAmountValue = player1SplitHand2BetAmountValue * 2
        player1SplitH2BetAmount:SetText(player1SplitHand2NormalWinAmountValue .. " G")
    end

    player1totalWin = player1totalWin + tonumber(player1SplitHand2BetAmountValue)
    historyFrame.player1totalWonAmount:SetText(player1totalWin .. " G")

    player1totalProfit = player1totalProfit + tonumber(player1SplitHand2BetAmountValue)
    historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

    if player1totalProfit >= 0 then
        historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
    else
        historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
    end

    player1TotalBankrollAmount = player1TotalBankrollAmount + tonumber(player1SplitHand2NormalWinAmountValue)
    bankrollFrame.player1TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
    cashDeskFrame.player1TotalBankroll:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")

    local player1PPBetText = player1PPBetAmount:GetText()

    if player1PPBetText and player1PPBetText ~= "" then
        player1PPBetAmountValue = tonumber(string.match(player1PPBetText, "%d+"))
        
        if player1PPBetAmountValue then
            if player1PPSideBetWin == false then

                player1PPBetAmount:SetTextColor(1, 0, 0)

                player1totalLoss = player1totalLoss + tonumber(player1PPBetAmountValue)
                historyFrame.player1totalLostAmount:SetText(player1totalLoss .. " G")

                player1totalProfit = player1totalProfit - tonumber(player1PPBetAmountValue)
                historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

                if player1totalProfit >= 0 then
                    historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
                else
                    historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
                end

            end
        end
    end

    local player1213BetText = player1213BetAmount:GetText()

    if player1213BetText and player1213BetText ~= "" then
        player1213BetAmountValue = tonumber(string.match(player1213BetText, "%d+"))

        if player1213BetAmountValue then
            if player1213SideBetWin == false then

                player1213BetAmount:SetTextColor(1, 0, 0)

                player1totalLoss = player1totalLoss + tonumber(player1213BetAmountValue)
                historyFrame.player1totalLostAmount:SetText(player1totalLoss .. " G")

                player1totalProfit = player1totalProfit - tonumber(player1213BetAmountValue)
                historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

                if player1totalProfit >= 0 then
                    historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
                else
                    historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
                end

            end
        end
    end

    playerFrame.player1SplitHand2Coins:Hide()
    playerFrame.player1SplitHand2NormalWinCoins:Show()

end

function player1InsuranceWin(message)

    local player1InsuranceBetText = playerFrame.player1InsuranceBetAmount:GetText()

    if player1InsuranceBetText and player1InsuranceBetText ~= "" then
        player1InsuranceBetAmountValue = tonumber(string.match(player1InsuranceBetText, "%d+"))

        if player1InsuranceBetAmountValue then
            player1InsuranceWinAmountValue = player1InsuranceBetAmountValue * 3

            player1InsuranceProfitValue = player1InsuranceWinAmountValue - player1InsuranceBetAmountValue

            player1totalWin = player1totalWin + tonumber(player1InsuranceProfitValue)
            historyFrame.player1totalWonAmount:SetText(player1totalWin .. " G")

            player1totalProfit = player1totalProfit + tonumber(player1InsuranceProfitValue)
            historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

            if player1totalProfit >= 0 then
                historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
            else
                historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
            end
            
            player1TotalBankrollAmount = player1TotalBankrollAmount + tonumber(player1InsuranceWinAmountValue)
            bankrollFrame.player1TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
            cashDeskFrame.player1TotalBankroll:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")

        end
    end
end

function player1InsuranceLoss(message)

    local player1InsuranceBetText = playerFrame.player1InsuranceBetAmount:GetText()

    if player1InsuranceBetText and player1InsuranceBetText ~= "" then
        player1InsuranceBetAmountValue = tonumber(string.match(player1InsuranceBetText, "%d+"))

        if player1InsuranceBetAmountValue then

            player1totalLoss = player1totalLoss + tonumber(player1InsuranceBetAmountValue)
            historyFrame.player1totalLostAmount:SetText(player1totalLoss .. " G")

            player1totalProfit = player1totalProfit - tonumber(player1InsuranceBetAmountValue)
            historyFrame.player1ProfitAmount:SetText(player1totalProfit .. " G")

            if player1totalProfit >= 0 then
                historyFrame.player1ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
            else
                historyFrame.player1ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
            end

        end
    end
end
















-- Function to handle Player 2 PP Win Image
function player2PlaceBetsPPWin(message)
    playerFrame.player2CoinsPPBet:Hide()
    playerFrame.player2CoinsPPWin:Show()
    player2PPBetAmount:SetPoint("CENTER", playerFrame, 121, -2)
end

-- Function to handle Player 2 21+3 Win Image
function player2PlaceBets213Win(message)
    playerFrame.player2Coins213Bet:Hide()
    playerFrame.player2Coins213Win:Show()
    player2213BetAmount:SetPoint("CENTER", playerFrame, 230, 49)
end

function player2MixedPairWin(message)
    player2PPBetAmountValue = tonumber(string.match(player2PPBetAmount:GetText(), "%d+"))
    if player2PPBetAmountValue then
        player2NewPPAmount = player2PPBetAmountValue * 6
        player2PPBetAmount:SetText(player2NewPPAmount .. " G")

        player2PPProfitvalue = player2NewPPAmount - player2PPBetAmountValue

        player2totalWin = player2totalWin + tonumber(player2PPProfitvalue)
        historyFrame.player2totalWonAmount:SetText(player2totalWin .. " G")

        player2totalProfit = player2totalProfit + tonumber(player2PPProfitvalue)
        historyFrame.player2ProfitAmount:SetText(player2totalProfit .. " G")

        if player2totalProfit >= 0 then
            historyFrame.player2ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
        else
            historyFrame.player2ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
        end

        player2TotalBankrollAmount = player2TotalBankrollAmount + tonumber(player2NewPPAmount)
        bankrollFrame.player2TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")
        cashDeskFrame.player2TotalBankroll:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")

    end
    player2PlaceBetsPPWin()
    player2PPSideBetWin = true
end

function player2ColouredPairWin(message)
    player2PPBetAmountValue = tonumber(string.match(player2PPBetAmount:GetText(), "%d+"))
    if player2PPBetAmountValue then
        player2NewPPAmount = player2PPBetAmountValue * 11
        player2PPBetAmount:SetText(player2NewPPAmount .. " G")

        player2PPProfitvalue = player2NewPPAmount - player2PPBetAmountValue

        player2totalWin = player2totalWin + tonumber(player2PPProfitvalue)
        historyFrame.player2totalWonAmount:SetText(player2totalWin .. " G")

        player2totalProfit = player2totalProfit + tonumber(player2PPProfitvalue)
        historyFrame.player2ProfitAmount:SetText(player2totalProfit .. " G")

        if player2totalProfit >= 0 then
            historyFrame.player2ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
        else
            historyFrame.player2ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
        end

        player2TotalBankrollAmount = player2TotalBankrollAmount + tonumber(player2NewPPAmount)
        bankrollFrame.player2TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")
        cashDeskFrame.player2TotalBankroll:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")

    end
    player2PlaceBetsPPWin()
    player2PPSideBetWin = true
end

function player2PerfectPairWin(message)
    player2PPBetAmountValue = tonumber(string.match(player2PPBetAmount:GetText(), "%d+"))
    if player2PPBetAmountValue then
        player2NewPPAmount = player2PPBetAmountValue * 31
        player2PPBetAmount:SetText(player2NewPPAmount .. " G")

        player2PPProfitvalue = player2NewPPAmount - player2PPBetAmountValue

        player2totalWin = player2totalWin + tonumber(player2PPProfitvalue)
        historyFrame.player2totalWonAmount:SetText(player2totalWin .. " G")

        player2totalProfit = player2totalProfit + tonumber(player2PPProfitvalue)
        historyFrame.player2ProfitAmount:SetText(player2totalProfit .. " G")

        if player2totalProfit >= 0 then
            historyFrame.player2ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
        else
            historyFrame.player2ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
        end

        player2TotalBankrollAmount = player2TotalBankrollAmount + tonumber(player2NewPPAmount)
        bankrollFrame.player2TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")
        cashDeskFrame.player2TotalBankroll:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")

    end
    player2PlaceBetsPPWin()
    player2PPSideBetWin = true
end

function player2SuitedThreeOfAKindWin(message)
    player2213BetAmountValue = tonumber(string.match(player2213BetAmount:GetText(), "%d+"))
    if player2213BetAmountValue then
        player2New213Amount = player2213BetAmountValue * 101
        player2213BetAmount:SetText(player2New213Amount .. " G")

        player2213Profitvalue = player2New213Amount - player2213BetAmountValue

        player2totalWin = player2totalWin + tonumber(player2213Profitvalue)
        historyFrame.player2totalWonAmount:SetText(player2totalWin .. " G")

        player2totalProfit = player2totalProfit + tonumber(player2213Profitvalue)
        historyFrame.player2ProfitAmount:SetText(player2totalProfit .. " G")

        if player2totalProfit >= 0 then
            historyFrame.player2ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
        else
            historyFrame.player2ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
        end

        player2TotalBankrollAmount = player2TotalBankrollAmount + tonumber(player2New213Amount)
        bankrollFrame.player2TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")
        cashDeskFrame.player2TotalBankroll:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")

    end
    player2PlaceBets213Win()
    player2213SideBetWin = true
end

function player2StraightFlushWin(message)
    player2213BetAmountValue = tonumber(string.match(player2213BetAmount:GetText(), "%d+"))
    if player2213BetAmountValue then
        player2New213Amount = player2213BetAmountValue * 41
        player2213BetAmount:SetText(player2New213Amount .. " G")

        player2213Profitvalue = player2New213Amount - player2213BetAmountValue

        player2totalWin = player2totalWin + tonumber(player2213Profitvalue)
        historyFrame.player2totalWonAmount:SetText(player2totalWin .. " G")

        player2totalProfit = player2totalProfit + tonumber(player2213Profitvalue)
        historyFrame.player2ProfitAmount:SetText(player2totalProfit .. " G")

        if player2totalProfit >= 0 then
            historyFrame.player2ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
        else
            historyFrame.player2ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
        end

        player2TotalBankrollAmount = player2TotalBankrollAmount + tonumber(player2New213Amount)
        bankrollFrame.player2TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")
        cashDeskFrame.player2TotalBankroll:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")

    end
    player2PlaceBets213Win()
    player2213SideBetWin = true
end

function player2ThreeOfAKindWin(message)
    player2213BetAmountValue = tonumber(string.match(player2213BetAmount:GetText(), "%d+"))
    if player2213BetAmountValue then
        player2New213Amount = player2213BetAmountValue * 31
        player2213BetAmount:SetText(player2New213Amount .. " G")

        player2213Profitvalue = player2New213Amount - player2213BetAmountValue

        player2totalWin = player2totalWin + tonumber(player2213Profitvalue)
        historyFrame.player2totalWonAmount:SetText(player2totalWin .. " G")

        player2totalProfit = player2totalProfit + tonumber(player2213Profitvalue)
        historyFrame.player2ProfitAmount:SetText(player2totalProfit .. " G")

        if player2totalProfit >= 0 then
            historyFrame.player2ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
        else
            historyFrame.player2ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
        end

        player2TotalBankrollAmount = player2TotalBankrollAmount + tonumber(player2New213Amount)
        bankrollFrame.player2TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")
        cashDeskFrame.player2TotalBankroll:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")

    end
    player2PlaceBets213Win()
    player2213SideBetWin = true
end

function player2StraightWin(message)
    player2213BetAmountValue = tonumber(string.match(player2213BetAmount:GetText(), "%d+"))
    if player2213BetAmountValue then
        player2New213Amount = player2213BetAmountValue * 11
        player2213BetAmount:SetText(player2New213Amount .. " G")
        
        player2213Profitvalue = player2New213Amount - player2213BetAmountValue

        player2totalWin = player2totalWin + tonumber(player2213Profitvalue)
        historyFrame.player2totalWonAmount:SetText(player2totalWin .. " G")

        player2totalProfit = player2totalProfit + tonumber(player2213Profitvalue)
        historyFrame.player2ProfitAmount:SetText(player2totalProfit .. " G")

        if player2totalProfit >= 0 then
            historyFrame.player2ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
        else
            historyFrame.player2ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
        end

        player2TotalBankrollAmount = player2TotalBankrollAmount + tonumber(player2New213Amount)
        bankrollFrame.player2TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")
        cashDeskFrame.player2TotalBankroll:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")

    end
    player2PlaceBets213Win()
    player2213SideBetWin = true
end

function player2FlushWin(message)
    player2213BetAmountValue = tonumber(string.match(player2213BetAmount:GetText(), "%d+"))
    if player2213BetAmountValue then
        player2New213Amount = player2213BetAmountValue * 6
        player2213BetAmount:SetText(player2New213Amount .. " G")
        
        player2213Profitvalue = player2New213Amount - player2213BetAmountValue

        player2totalWin = player2totalWin + tonumber(player2213Profitvalue)
        historyFrame.player2totalWonAmount:SetText(player2totalWin .. " G")

        player2totalProfit = player2totalProfit + tonumber(player2213Profitvalue)
        historyFrame.player2ProfitAmount:SetText(player2totalProfit .. " G")

        if player2totalProfit >= 0 then
            historyFrame.player2ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
        else
            historyFrame.player2ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
        end

        player2TotalBankrollAmount = player2TotalBankrollAmount + tonumber(player2New213Amount)
        bankrollFrame.player2TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")
        cashDeskFrame.player2TotalBankroll:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")

    end
    player2PlaceBets213Win()
    player2213SideBetWin = true
end

function player2BlackjackWin(message)
    player2MainBetValue = tonumber(string.match(player2MainBetAmount:GetText(), "%d+"))
    if player2MainBetValue then
        player2NewMainBetAmount = player2MainBetValue * 2.5
        player2MainBetAmount:SetText(player2NewMainBetAmount .. " G")

        player2BJProfitvalue = player2NewMainBetAmount - player2MainBetValue

        player2totalWin = player2totalWin + tonumber(player2BJProfitvalue)
        historyFrame.player2totalWonAmount:SetText(player2totalWin .. " G")

        player2totalProfit = player2totalProfit + tonumber(player2BJProfitvalue)
        historyFrame.player2ProfitAmount:SetText(player2totalProfit .. " G")

        if player2totalProfit >= 0 then
            historyFrame.player2ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
        else
            historyFrame.player2ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
        end

        player2TotalBankrollAmount = player2TotalBankrollAmount + tonumber(player2NewMainBetAmount)
        bankrollFrame.player2TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")
        cashDeskFrame.player2TotalBankroll:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")

        player2PPBetAmountValue = tonumber(string.match(player2PPBetAmount:GetText(), "%d+"))
        if player2PPBetAmountValue then
            if player2PPSideBetWin == false then

                player2totalLoss = player2totalLoss + tonumber(player2PPBetAmountValue)
                historyFrame.player2totalLostAmount:SetText(player2totalLoss .. " G")

                player2totalProfit = player2totalProfit - tonumber(player2PPBetAmountValue)
                historyFrame.player2ProfitAmount:SetText(player2totalProfit .. " G")

                if player2totalProfit >= 0 then
                    historyFrame.player2ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
                else
                    historyFrame.player2ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
                end

            end
        end

        player2213BetAmountValue = tonumber(string.match(player2213BetAmount:GetText(), "%d+"))
        if player2213BetAmountValue then
            if player2213SideBetWin == false then

                player2totalLoss = player2totalLoss + tonumber(player2213BetAmountValue)
                historyFrame.player2totalLostAmount:SetText(player2totalLoss .. " G")

                player2totalProfit = player2totalProfit - tonumber(player2213BetAmountValue)
                historyFrame.player2ProfitAmount:SetText(player2totalProfit .. " G")

                if player2totalProfit >= 0 then
                    historyFrame.player2ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
                else
                    historyFrame.player2ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
                end

            end
        end

    end
    player2PlaceBetsBJWin()
end

function player2RegularWin(message)
    player2MainBetValue = tonumber(string.match(player2MainBetAmount:GetText(), "%d+"))
    if player2MainBetValue then
        player2NewMainBetAmount = player2MainBetValue * 2
        player2MainBetAmount:SetText(player2NewMainBetAmount .. " G")

        player2totalWin = player2totalWin + tonumber(player2MainBetValue)
        historyFrame.player2totalWonAmount:SetText(player2totalWin .. " G")

        player2totalProfit = player2totalProfit + tonumber(player2MainBetValue)
        historyFrame.player2ProfitAmount:SetText(player2totalProfit .. " G")

        if player2totalProfit >= 0 then
            historyFrame.player2ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
        else
            historyFrame.player2ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
        end

        player2TotalBankrollAmount = player2TotalBankrollAmount + tonumber(player2NewMainBetAmount)
        bankrollFrame.player2TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")
        cashDeskFrame.player2TotalBankroll:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")

        player2PPBetAmountValue = tonumber(string.match(player2PPBetAmount:GetText(), "%d+"))
        if player2PPBetAmountValue then
            if player2PPSideBetWin == false then

                player2totalLoss = player2totalLoss + tonumber(player2PPBetAmountValue)
                historyFrame.player2totalLostAmount:SetText(player2totalLoss .. " G")

                player2totalProfit = player2totalProfit - tonumber(player2PPBetAmountValue)
                historyFrame.player2ProfitAmount:SetText(player2totalProfit .. " G")

                if player2totalProfit >= 0 then
                    historyFrame.player2ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
                else
                    historyFrame.player2ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
                end

            end
        end

        player2213BetAmountValue = tonumber(string.match(player2213BetAmount:GetText(), "%d+"))
        if player2213BetAmountValue then
            if player2213SideBetWin == false then

                player2totalLoss = player2totalLoss + tonumber(player2213BetAmountValue)
                historyFrame.player2totalLostAmount:SetText(player2totalLoss .. " G")

                player2totalProfit = player2totalProfit - tonumber(player2213BetAmountValue)
                historyFrame.player2ProfitAmount:SetText(player2totalProfit .. " G")

                if player2totalProfit >= 0 then
                    historyFrame.player2ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
                else
                    historyFrame.player2ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
                end

            end
        end

    end
    player2PlaceBetsRegularWin()
end

function player2InsuranceWin(message)

    local player2InsuranceBetText = playerFrame.player2InsuranceBetAmount:GetText()

    if player2InsuranceBetText and player2InsuranceBetText ~= "" then
        player2InsuranceBetAmountValue = tonumber(string.match(player2InsuranceBetText, "%d+"))
        
        if player2InsuranceBetAmountValue then
            player2InsuranceWinAmountValue = player2InsuranceBetAmountValue * 3

            player2InsuranceProfitValue = player2InsuranceWinAmountValue - player2InsuranceBetAmountValue

            player2totalWin = player2totalWin + tonumber(player2InsuranceProfitValue)
            historyFrame.player2totalWonAmount:SetText(player2totalWin .. " G")

            player2totalProfit = player2totalProfit + tonumber(player2InsuranceProfitValue)
            historyFrame.player2ProfitAmount:SetText(player2totalProfit .. " G")

            if player2totalProfit >= 0 then
                historyFrame.player2ProfitAmount:SetTextColor(0.098, 0.878, 0.098)
            else
                historyFrame.player2ProfitAmount:SetTextColor(0.961, 0.306, 0.306)
            end
            
            player2TotalBankrollAmount = player2TotalBankrollAmount + tonumber(player2InsuranceWinAmountValue)
            bankrollFrame.player2TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")
            cashDeskFrame.player2TotalBankroll:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")

        end
    end
end





-- Function to remove card textures
local function RemoveCardTextures()
    for i = 1, #drawnCards do
        drawnCards[i]:Hide() -- Hide the card texture
        drawnCards[i]:SetTexture(nil)  -- Set the texture to nil
    end

    if player1NewCardImage1 then
        player1NewCardImage1:Hide()
    end

    if player1NewCardImage2 then
        player1NewCardImage2:Hide()
    end

    drawnCards = {} -- Reset the table of card textures
    dealtCards = {}

    playerFrame.player1CardTotalText:Hide()
    playerFrame.player1SplitHand1CardTotalText:Hide()
    playerFrame.player1SplitHand2CardTotalText:Hide()
    playerFrame.player2CardTotalText:Hide()
    playerFrame.player3CardTotalText:Hide()
    playerFrame.player4CardTotalText:Hide()
    playerFrame.player5CardTotalText:Hide()
    playerFrame.dealerCardTotalText:Hide()

    -- Reset Player1Total
    Player1Total = 0
    playerFrame.player1CardTotalText:SetText("")
    playerFrame.player1SplitHand1CardTotalText:SetText("")
    playerFrame.player1SplitHand2CardTotalText:SetText("")
    playerFrame.player2CardTotalText:SetText("")
    playerFrame.player3CardTotalText:SetText("")
    playerFrame.player4CardTotalText:SetText("")
    playerFrame.player4CardTotalText:SetText("")

    -- Reset Dealt Cards Frame
    dealtCardsFramePlayer.player1MainCardImage1:Hide()
    dealtCardsFramePlayer.playerFirstCardText:Hide()
    dealtCardsFramePlayer.player1MainCardImage2:Hide()
    dealtCardsFramePlayer.playerSecondCardText:Hide()
    dealtCardsFramePlayer.player1MainCardImage3:Hide()
    dealtCardsFramePlayer.playerThirdCardText:Hide()
    dealtCardsFramePlayer.player1MainCardImage4:Hide()
    dealtCardsFramePlayer.playerFourthCardText:Hide()
    dealtCardsFramePlayer.player1MainCardImage5:Hide()
    dealtCardsFramePlayer.playerFifthCardText:Hide()
    dealtCardsFramePlayer.player1MainCardImage6:Hide()
    dealtCardsFramePlayer.playerSixthCardText:Hide()
    dealtCardsFramePlayer.player1MainCardImage7:Hide()
    dealtCardsFramePlayer.playerSeventhCardText:Hide()

    dealtCardsFramePlayer1H1.player1H1CardImage1:Hide()
    dealtCardsFramePlayer1H1.playerFirstCardText:Hide()
    dealtCardsFramePlayer1H1.player1H1CardImage2:Hide()
    dealtCardsFramePlayer1H1.playerSecondCardText:Hide()
    dealtCardsFramePlayer1H1.player1H1CardImage3:Hide()
    dealtCardsFramePlayer1H1.playerThirdCardText:Hide()
    dealtCardsFramePlayer1H1.player1H1CardImage4:Hide()
    dealtCardsFramePlayer1H1.playerFourthCardText:Hide()
    dealtCardsFramePlayer1H1.player1H1CardImage5:Hide()
    dealtCardsFramePlayer1H1.playerFifthCardText:Hide()
    dealtCardsFramePlayer1H1.player1H1CardImage6:Hide()
    dealtCardsFramePlayer1H1.playerSixthCardText:Hide()
    dealtCardsFramePlayer1H1.player1H1CardImage7:Hide()
    dealtCardsFramePlayer1H1.playerSeventhCardText:Hide()

    dealtCardsFramePlayer1H2.player1H2CardImage1:Hide()
    dealtCardsFramePlayer1H2.playerFirstCardText:Hide()
    dealtCardsFramePlayer1H2.player1H2CardImage2:Hide()
    dealtCardsFramePlayer1H2.playerSecondCardText:Hide()
    dealtCardsFramePlayer1H2.player1H2CardImage3:Hide()
    dealtCardsFramePlayer1H2.playerThirdCardText:Hide()
    dealtCardsFramePlayer1H2.player1H2CardImage4:Hide()
    dealtCardsFramePlayer1H2.playerFourthCardText:Hide()
    dealtCardsFramePlayer1H2.player1H2CardImage5:Hide()
    dealtCardsFramePlayer1H2.playerFifthCardText:Hide()
    dealtCardsFramePlayer1H2.player1H2CardImage6:Hide()
    dealtCardsFramePlayer1H2.playerSixthCardText:Hide()
    dealtCardsFramePlayer1H2.player1H2CardImage7:Hide()
    dealtCardsFramePlayer1H2.playerSeventhCardText:Hide()

    dealtCardsFrameDealer.dealerCardImage1:Hide()
    dealtCardsFrameDealer.dealerFirstCardText:Hide()
    dealtCardsFrameDealer.dealerCardImage2:Hide()
    dealtCardsFrameDealer.dealerSecondCardText:Hide()
    dealtCardsFrameDealer.dealerCardImage3:Hide()
    dealtCardsFrameDealer.dealerThirdCardText:Hide()
    dealtCardsFrameDealer.dealerCardImage4:Hide()
    dealtCardsFrameDealer.dealerFourthCardText:Hide()
    dealtCardsFrameDealer.dealerCardImage5:Hide()
    dealtCardsFrameDealer.dealerFifthCardText:Hide()
    dealtCardsFrameDealer.dealerCardImage6:Hide()
    dealtCardsFrameDealer.dealerSixthCardText:Hide()
    dealtCardsFrameDealer.dealerCardImage7:Hide()
    dealtCardsFrameDealer.dealerSeventhCardText:Hide()

    dealtCardsFrameDealerSplit.dealerCardImage1:Hide()
    dealtCardsFrameDealerSplit.dealerFirstCardText:Hide()
    dealtCardsFrameDealerSplit.dealerCardImage2:Hide()
    dealtCardsFrameDealerSplit.dealerSecondCardText:Hide()
    dealtCardsFrameDealerSplit.dealerCardImage3:Hide()
    dealtCardsFrameDealerSplit.dealerThirdCardText:Hide()
    dealtCardsFrameDealerSplit.dealerCardImage4:Hide()
    dealtCardsFrameDealerSplit.dealerFourthCardText:Hide()
    dealtCardsFrameDealerSplit.dealerCardImage5:Hide()
    dealtCardsFrameDealerSplit.dealerFifthCardText:Hide()
    dealtCardsFrameDealerSplit.dealerCardImage6:Hide()
    dealtCardsFrameDealerSplit.dealerSixthCardText:Hide()
    dealtCardsFrameDealerSplit.dealerCardImage7:Hide()
    dealtCardsFrameDealerSplit.dealerSeventhCardText:Hide()

    -- Reset DealerTotal
    DealerTotal = 0
    playerFrame.dealerCardTotalText:SetText("")
end

-- Function to get the card image file name from the card name
local function GetCardFileName(cardName)
    for fileName, name in pairs(cardNames) do
        if name == cardName then
            return fileName
        end
    end
end


















-- Chat event to listen for raid leader chat messages
local eventFrame = CreateFrame("Frame")
eventFrame:RegisterEvent("CHAT_MSG_RAID_LEADER")
eventFrame:SetScript("OnEvent", function(self, event, message, sender)

    if sender == "Blackjackk-Earthshaker" or UnitIsGroupLeader(sender,"raid") then
        
        HandleChatMessage(message)
        
        if message == "I have opened the table." then
            EnableJoinButton()
        elseif message == "I have closed the table." then
            PlayerFrameHide()
            resetHistory()
        elseif message == "I have started a new round." then
            betReset()
            RemoveCardTextures()
        elseif message == "{diamond} Insurance is available." then
            insuranceAvailable()
        elseif string.find(message, "{triangle} Split is available") then
            if string.find(message, unitName1) then
                playerFrame.player1SplitButton:Enable()
            end
        elseif message == "{star} Place your bets! You have 30 seconds." then
            StartCountdownTimerBets()
        elseif string.find(message, "added") then
            if string.find(message, unitName1) then
                player1AdditionalBankrollAmount = string.match(message, "([%d%.]+)G")
                player1TotalBankrollAmount = player1TotalBankrollAmount + player1AdditionalBankrollAmount
                cashDeskFrame.player1TotalBankroll:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
                bankrollFrame.player1TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
            elseif string.find(message, unitName2) then
                player2AdditionalBankrollAmount = string.match(message, "([%d%.]+)G")
                player2TotalBankrollAmount = player2TotalBankrollAmount + player2AdditionalBankrollAmount
                cashDeskFrame.player2TotalBankroll:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")
                bankrollFrame.player2TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")
            elseif string.find(message, unitName3) then
                player3AdditionalBankrollAmount = string.match(message, "([%d%.]+)G")
                player3RunningBankrollTotal = player3RunningBankrollTotal + player3AdditionalBankrollAmount
                cashDeskFrame.player3TotalBankroll:SetText("Total Bankroll: " .. player3RunningBankrollTotal .. " G")
                bankrollFrame.player3TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player3RunningBankrollTotal .. " G")
            elseif string.find(message, unitName4) then
                player4AdditionalBankrollAmount = string.match(message, "([%d%.]+)G")
                player4RunningBankrollTotal = player4RunningBankrollTotal + player4AdditionalBankrollAmount
                cashDeskFrame.player4TotalBankroll:SetText("Total Bankroll: " .. player4RunningBankrollTotal .. " G")
                bankrollFrame.player4TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player4RunningBankrollTotal .. " G")
            elseif string.find(message, unitName5) then
                player5AdditionalBankrollAmount = string.match(message, "([%d%.]+)G")
                player5RunningBankrollTotal = player5RunningBankrollTotal + player5AdditionalBankrollAmount
                cashDeskFrame.player5TotalBankroll:SetText("Total Bankroll: " .. player5RunningBankrollTotal .. " G")
                bankrollFrame.player5TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player5RunningBankrollTotal .. " G")
            end
        elseif string.find(message, "withdrew") then
            if string.find(message, unitName1) then
                player1RemovalBankrollAmount = string.match(message, "([%d%.]+)G")
                player1TotalBankrollAmount = player1TotalBankrollAmount - player1RemovalBankrollAmount
                cashDeskFrame.player1TotalBankroll:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
                bankrollFrame.player1TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
            elseif string.find(message, unitName2) then
                player2RemovalBankrollAmount = string.match(message, "([%d%.]+)G")
                player2TotalBankrollAmount = player2TotalBankrollAmount - player2RemovalBankrollAmount
                cashDeskFrame.player2TotalBankroll:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")
                bankrollFrame.player2TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")
            elseif string.find(message, unitName3) then
                player3RemovalBankrollAmount = string.match(message, "([%d%.]+)G")
                player3RunningBankrollTotal = player3RunningBankrollTotal - player3RemovalBankrollAmount
                cashDeskFrame.player3TotalBankroll:SetText("Total Bankroll: " .. player3RunningBankrollTotal .. " G")
                bankrollFrame.player3TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player3RunningBankrollTotal .. " G")
            elseif string.find(message, unitName4) then
                player4RemovalBankrollAmount = string.match(message, "([%d%.]+)G")
                player4RunningBankrollTotal = player4RunningBankrollTotal - player4RemovalBankrollAmount
                cashDeskFrame.player4TotalBankroll:SetText("Total Bankroll: " .. player4RunningBankrollTotal .. " G")
                bankrollFrame.player4TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player4RunningBankrollTotal .. " G")
            elseif string.find(message, unitName5) then
                player5RemovalBankrollAmount = string.match(message, "([%d%.]+)G")
                player5RunningBankrollTotal = player5RunningBankrollTotal - player5RemovalBankrollAmount
                cashDeskFrame.player5TotalBankroll:SetText("Total Bankroll: " .. player5RunningBankrollTotal .. " G")
                bankrollFrame.player5TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player5RunningBankrollTotal .. " G")
            end
        elseif string.find(message, "received") then
            roundStarted()
            gameRunning = true
            if string.find(message, unitName1) then
                -- Players: 1
                if Player1Active and not Player2Active and not Player3Active and not Player4Active and not Player5Active then

                    dealtCardsFramePlayer.notStartedYetText:Hide()
                    dealtCardsFrameDealer.notStartedYetText:Hide()

                    if turn == 1 then -- Player 1: 1st Card
                        player1MainCardName1 = dealtCards[1]
                        player1MainCardFileName1 = GetCardFileName(player1MainCardName1)
                        player1NumberOfCards = player1NumberOfCards + 1
                    elseif turn == 3 then -- Player 1: 2nd Card
                        player1MainCardName2 = dealtCards[3]
                        player1MainCardFileName2 = GetCardFileName(player1MainCardName2)
                        player1H1CardName1 = dealtCards[1]
                        player1H1CardFileName1 = GetCardFileName(player1H1CardName1)
                        player1H2CardName1 = dealtCards[3]
                        player1H2CardFileName1 = GetCardFileName(player1H2CardName1)
                        player1NumberOfCards = player1NumberOfCards + 1
                    elseif turn == 4 or turn == 23 then -- Player 1: 3rd Card or 3rd Card (Double)
                        player1MainCardName3 = dealtCards[4]
                        player1MainCardFileName3 = GetCardFileName(player1MainCardName3)
                        player1NumberOfCards = player1NumberOfCards + 1
                    elseif turn == 5 then -- Player 1: 4th Card
                        player1MainCardName4 = dealtCards[5]
                        player1MainCardFileName4 = GetCardFileName(player1MainCardName4)
                        player1NumberOfCards = player1NumberOfCards + 1
                    elseif turn == 6 then -- Player 1: 5th Card
                        player1MainCardName5 = dealtCards[6]
                        player1MainCardFileName5 = GetCardFileName(player1MainCardName5)
                        player1NumberOfCards = player1NumberOfCards + 1
                    elseif turn == 7 then -- Player 1: 6th Card
                        player1MainCardName6 = dealtCards[7]
                        player1MainCardFileName6 = GetCardFileName(player1MainCardName6)
                        player1NumberOfCards = player1NumberOfCards + 1
                    elseif turn == 8 then -- Player 1: 7th Card
                        player1MainCardName7 = dealtCards[8]
                        player1MainCardFileName7 = GetCardFileName(player1MainCardName7)
                        player1NumberOfCards = player1NumberOfCards + 1
                    elseif turn == 9 then  -- Player 1: 2nd Card (Split H1)
                        player1H1CardName2 = dealtCards[4]
                        player1H1CardFileName2 = GetCardFileName(player1H1CardName2)
                        player1NumberOfCardsH1 = player1NumberOfCardsH1 + 2
                        player1NumberOfCards = player1NumberOfCards + 1
                    elseif turn == 10 then -- Player 1: 2nd Card (Split H2)
                        player1H2CardName2 = dealtCards[5]
                        player1H2CardFileName2 = GetCardFileName(player1H2CardName2)
                        player1NumberOfCards = player1NumberOfCards + 1
                    elseif turn == 11 or turn == 16 then -- Player 1: 3rd Card (Split H1) or 3rd Card (Double) (Split H1)
                        player1H1CardName3 = dealtCards[6]
                        player1H1CardFileName3 = GetCardFileName(player1H1CardName3)
                        player1NumberOfCardsH1 = player1NumberOfCardsH1 + 1
                        player1NumberOfCards = player1NumberOfCards + 1
                    elseif turn == 12 then -- Player 1: 4th Card (Split H1)
                        player1H1CardName4 = dealtCards[7]
                        player1H1CardFileName4 = GetCardFileName(player1H1CardName4)
                        player1NumberOfCardsH1 = player1NumberOfCardsH1 + 1
                        player1NumberOfCards = player1NumberOfCards + 1
                    elseif turn == 13 then -- Player 1: 5th Card (Split H1)
                        player1H1CardName5 = dealtCards[8]
                        player1H1CardFileName5 = GetCardFileName(player1H1CardName5)
                        player1NumberOfCardsH1 = player1NumberOfCardsH1 + 1
                        player1NumberOfCards = player1NumberOfCards + 1
                    elseif turn == 14 then -- Player 1: 6th Card (Split H1)
                        player1H1CardName6 = dealtCards[9]
                        player1H1CardFileName6 = GetCardFileName(player1H1CardName6)
                        player1NumberOfCardsH1 = player1NumberOfCardsH1 + 1
                        player1NumberOfCards = player1NumberOfCards + 1
                    elseif turn == 15 then -- Player 1: 7th Card (Split H1)
                        player1H1CardName7 = dealtCards[10]
                        player1H1CardFileName7 = GetCardFileName(player1H1CardName7)
                        player1NumberOfCardsH1 = player1NumberOfCardsH1 + 1
                        player1NumberOfCards = player1NumberOfCards + 1
                    elseif turn == 17 or turn == 22 then -- Player 1: 3rd Card (Split H2) or 3rd Card (Double) (Split H2)
                        player1H2CardName3 = dealtCards[player1NumberOfCardsH1 + 4]
                        player1H2CardFileName3 = GetCardFileName(player1H2CardName3)
                        player1NumberOfCards = player1NumberOfCards + 1
                    elseif turn == 18 then -- Player 1: 4th Card (Split H2)
                        player1H2CardName4 = dealtCards[player1NumberOfCardsH1 + 5]
                        player1H2CardFileName4 = GetCardFileName(player1H2CardName4)
                        player1NumberOfCards = player1NumberOfCards + 1
                    elseif turn == 19 then -- Player 1: 5th Card (Split H2)
                        player1H2CardName5 = dealtCards[player1NumberOfCardsH1 + 6]
                        player1H2CardFileName5 = GetCardFileName(player1H2CardName5)
                        player1NumberOfCards = player1NumberOfCards + 1
                    elseif turn == 20 then -- Player 1: 6th Card (Split H2)
                        player1H2CardName6 = dealtCards[player1NumberOfCardsH1 + 7]
                        player1H2CardFileName6 = GetCardFileName(player1H2CardName6)
                        player1NumberOfCards = player1NumberOfCards + 1
                    elseif turn == 21 then -- Player 1: 7th Card (Split H2)
                        player1H2CardName7 = dealtCards[player1NumberOfCardsH1 + 8]
                        player1H2CardFileName7 = GetCardFileName(player1H2CardName7)
                        player1NumberOfCards = player1NumberOfCards + 1
                    end

                    dealtCardsFramePlayer.player1MainCardImage1:SetTexture(nil)
                    dealtCardsFramePlayer.playerFirstCardText:Hide()
                    dealtCardsFramePlayer.player1MainCardImage2:SetTexture(nil)
                    dealtCardsFramePlayer.playerSecondCardText:Hide()
                    dealtCardsFramePlayer.player1MainCardImage3:SetTexture(nil)
                    dealtCardsFramePlayer.playerThirdCardText:Hide()
                    dealtCardsFramePlayer.player1MainCardImage4:SetTexture(nil)
                    dealtCardsFramePlayer.playerFourthCardText:Hide()
                    dealtCardsFramePlayer.player1MainCardImage5:SetTexture(nil)
                    dealtCardsFramePlayer.playerFifthCardText:Hide()
                    dealtCardsFramePlayer.player1MainCardImage6:SetTexture(nil)
                    dealtCardsFramePlayer.playerSixthCardText:Hide()
                    dealtCardsFramePlayer.player1MainCardImage7:SetTexture(nil)
                    dealtCardsFramePlayer.playerSeventhCardText:Hide()

                    if player1MainCardName1 and player1MainCardFileName1 then
                        dealtCardsFramePlayer.player1MainCardImage1:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1MainCardFileName1)
                        dealtCardsFramePlayer.player1MainCardImage1:Show()
                        dealtCardsFramePlayer.playerFirstCardText:Show()
                    end
                    if player1MainCardName2 and player1MainCardFileName2 then
                        dealtCardsFramePlayer.player1MainCardImage2:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1MainCardFileName2)
                        dealtCardsFramePlayer.player1MainCardImage2:Show()
                        dealtCardsFramePlayer.playerSecondCardText:Show()
                    end
                    if player1MainCardName3 and player1MainCardFileName3 then
                        dealtCardsFramePlayer.player1MainCardImage3:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1MainCardFileName3)
                        dealtCardsFramePlayer.player1MainCardImage3:Show()
                        dealtCardsFramePlayer.playerThirdCardText:Show()
                    end
                    if player1MainCardName4 and player1MainCardFileName4 then
                        dealtCardsFramePlayer.player1MainCardImage4:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1MainCardFileName4)
                        dealtCardsFramePlayer.player1MainCardImage4:Show()
                        dealtCardsFramePlayer.playerFourthCardText:Show()
                    end
                    if player1MainCardName5 and player1MainCardFileName5 then
                        dealtCardsFramePlayer.player1MainCardImage5:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1MainCardFileName5)
                        dealtCardsFramePlayer.player1MainCardImage5:Show()
                        dealtCardsFramePlayer.playerFifthCardText:Show()
                    end
                    if player1MainCardName6 and player1MainCardFileName6 then
                        dealtCardsFramePlayer.player1MainCardImage6:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1MainCardFileName6)
                        dealtCardsFramePlayer.player1MainCardImage6:Show()
                        dealtCardsFramePlayer.playerSixthCardText:Show()
                    end
                    if player1MainCardName7 and player1MainCardFileName7 then
                        dealtCardsFramePlayer.player1MainCardImage7:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1MainCardFileName7)
                        dealtCardsFramePlayer.player1MainCardImage7:Show()
                        dealtCardsFramePlayer.playerSeventhCardText:Show()
                    end

                    dealtCardsFramePlayer1H1.player1H1CardImage1:SetTexture(nil)
                    dealtCardsFramePlayer1H1.playerFirstCardText:Hide()
                    dealtCardsFramePlayer1H1.player1H1CardImage2:SetTexture(nil)
                    dealtCardsFramePlayer1H1.playerSecondCardText:Hide()
                    dealtCardsFramePlayer1H1.player1H1CardImage3:SetTexture(nil)
                    dealtCardsFramePlayer1H1.playerThirdCardText:Hide()
                    dealtCardsFramePlayer1H1.player1H1CardImage4:SetTexture(nil)
                    dealtCardsFramePlayer1H1.playerFourthCardText:Hide()
                    dealtCardsFramePlayer1H1.player1H1CardImage5:SetTexture(nil)
                    dealtCardsFramePlayer1H1.playerFifthCardText:Hide()
                    dealtCardsFramePlayer1H1.player1H1CardImage6:SetTexture(nil)
                    dealtCardsFramePlayer1H1.playerSixthCardText:Hide()
                    dealtCardsFramePlayer1H1.player1H1CardImage7:SetTexture(nil)
                    dealtCardsFramePlayer1H1.playerSeventhCardText:Hide()

                    if player1H1CardName1 and player1H1CardFileName1 then
                        dealtCardsFramePlayer1H1.player1H1CardImage1:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1H1CardFileName1)
                        dealtCardsFramePlayer1H1.player1H1CardImage1:Show()
                        dealtCardsFramePlayer1H1.playerFirstCardText:Show()
                    end
                    if player1H1CardName2 and player1H1CardFileName2 then
                        dealtCardsFramePlayer1H1.player1H1CardImage2:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1H1CardFileName2)
                        dealtCardsFramePlayer1H1.player1H1CardImage2:Show()
                        dealtCardsFramePlayer1H1.playerSecondCardText:Show()
                    end
                    if player1H1CardName3 and player1H1CardFileName3 then
                        dealtCardsFramePlayer1H1.player1H1CardImage3:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1H1CardFileName3)
                        dealtCardsFramePlayer1H1.player1H1CardImage3:Show()
                        dealtCardsFramePlayer1H1.playerThirdCardText:Show()
                    end
                    if player1H1CardName4 and player1H1CardFileName4 then
                        dealtCardsFramePlayer1H1.player1H1CardImage4:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1H1CardFileName4)
                        dealtCardsFramePlayer1H1.player1H1CardImage4:Show()
                        dealtCardsFramePlayer1H1.playerFourthCardText:Show()
                    end
                    if player1H1CardName5 and player1H1CardFileName5 then
                        dealtCardsFramePlayer1H1.player1H1CardImage5:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1H1CardFileName5)
                        dealtCardsFramePlayer1H1.player1H1CardImage5:Show()
                        dealtCardsFramePlayer1H1.playerFifthCardText:Show()
                    end
                    if player1H1CardName6 and player1H1CardFileName6 then
                        dealtCardsFramePlayer1H1.player1H1CardImage6:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1H1CardFileName6)
                        dealtCardsFramePlayer1H1.player1H1CardImage6:Show()
                        dealtCardsFramePlayer1H1.playerSixthCardText:Show()
                    end
                    if player1H1CardName7 and player1H1CardFileName7 then
                        dealtCardsFramePlayer1H1.player1H1CardImage7:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1H1CardFileName7)
                        dealtCardsFramePlayer1H1.player1H1CardImage7:Show()
                        dealtCardsFramePlayer1H1.playerSeventhCardText:Show()
                    end

                    dealtCardsFramePlayer1H2.player1H2CardImage1:SetTexture(nil)
                    dealtCardsFramePlayer1H2.playerFirstCardText:Hide()
                    dealtCardsFramePlayer1H2.player1H2CardImage2:SetTexture(nil)
                    dealtCardsFramePlayer1H2.playerSecondCardText:Hide()
                    dealtCardsFramePlayer1H2.player1H2CardImage3:SetTexture(nil)
                    dealtCardsFramePlayer1H2.playerThirdCardText:Hide()
                    dealtCardsFramePlayer1H2.player1H2CardImage4:SetTexture(nil)
                    dealtCardsFramePlayer1H2.playerFourthCardText:Hide()
                    dealtCardsFramePlayer1H2.player1H2CardImage5:SetTexture(nil)
                    dealtCardsFramePlayer1H2.playerFifthCardText:Hide()
                    dealtCardsFramePlayer1H2.player1H2CardImage6:SetTexture(nil)
                    dealtCardsFramePlayer1H2.playerSixthCardText:Hide()
                    dealtCardsFramePlayer1H2.player1H2CardImage7:SetTexture(nil)
                    dealtCardsFramePlayer1H2.playerSeventhCardText:Hide()

                    if player1H2CardName1 and player1H2CardFileName1 then
                        dealtCardsFramePlayer1H2.player1H2CardImage1:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1H2CardFileName1)
                        dealtCardsFramePlayer1H2.player1H2CardImage1:Show()
                        dealtCardsFramePlayer1H2.playerFirstCardText:Show()
                    end
                    if player1H2CardName2 and player1H2CardFileName2 then
                        dealtCardsFramePlayer1H2.player1H2CardImage2:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1H2CardFileName2)
                        dealtCardsFramePlayer1H2.player1H2CardImage2:Show()
                        dealtCardsFramePlayer1H2.playerSecondCardText:Show()
                    end
                    if player1H2CardName3 and player1H2CardFileName3 then
                        dealtCardsFramePlayer1H2.player1H2CardImage3:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1H2CardFileName3)
                        dealtCardsFramePlayer1H2.player1H2CardImage3:Show()
                        dealtCardsFramePlayer1H2.playerThirdCardText:Show()
                    end
                    if player1H2CardName4 and player1H2CardFileName4 then
                        dealtCardsFramePlayer1H2.player1H2CardImage4:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1H2CardFileName4)
                        dealtCardsFramePlayer1H2.player1H2CardImage4:Show()
                        dealtCardsFramePlayer1H2.playerFourthCardText:Show()
                    end
                    if player1H2CardName5 and player1H2CardFileName5 then
                        dealtCardsFramePlayer1H2.player1H2CardImage5:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1H2CardFileName5)
                        dealtCardsFramePlayer1H2.player1H2CardImage5:Show()
                        dealtCardsFramePlayer1H2.playerFifthCardText:Show()
                    end
                    if player1H2CardName6 and player1H2CardFileName6 then
                        dealtCardsFramePlayer1H2.player1H2CardImage6:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1H2CardFileName6)
                        dealtCardsFramePlayer1H2.player1H2CardImage6:Show()
                        dealtCardsFramePlayer1H2.playerSixthCardText:Show()
                    end
                    if player1H2CardName7 and player1H2CardFileName7 then
                        dealtCardsFramePlayer1H2.player1H2CardImage7:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1H2CardFileName7)
                        dealtCardsFramePlayer1H2.player1H2CardImage7:Show()
                        dealtCardsFramePlayer1H2.playerSeventhCardText:Show()
                    end
                end
            end

        elseif string.find(message, "turned") then
            -- Players: 1
            if Player1Active and not Player2Active and not Player3Active and not Player4Active and not Player5Active then

                if turn == 2 then
                    dealerCardName1 = dealtCards[2]
                    dealerCardFileName1 = GetCardFileName(dealerCardName1)
                elseif turn == 24 then
                    dealerCardName2 = dealtCards[player1NumberOfCards + 2]
                    dealerCardFileName2 = GetCardFileName(dealerCardName2)
                elseif turn == 25 then
                    dealerCardName3 = dealtCards[player1NumberOfCards + 3]
                    dealerCardFileName3 = GetCardFileName(dealerCardName3)
                elseif turn == 26 then
                    dealerCardName4 = dealtCards[player1NumberOfCards + 4]
                    dealerCardFileName4 = GetCardFileName(dealerCardName4)
                elseif turn == 27 then
                    dealerCardName5 = dealtCards[player1NumberOfCards + 5]
                    dealerCardFileName5 = GetCardFileName(dealerCardName5)
                elseif turn == 28 then
                    dealerCardName6 = dealtCards[player1NumberOfCards + 6]
                    dealerCardFileName6 = GetCardFileName(dealerCardName6)
                elseif turn == 29 then
                    dealerCardName7 = dealtCards[player1NumberOfCards + 7]
                    dealerCardFileName7 = GetCardFileName(dealerCardName7)
                end

                dealtCardsFrameDealer.dealerCardImage1:SetTexture(nil)
                dealtCardsFrameDealer.dealerFirstCardText:Hide()
                dealtCardsFrameDealer.dealerCardImage2:SetTexture(nil)
                dealtCardsFrameDealer.dealerSecondCardText:Hide()
                dealtCardsFrameDealer.dealerCardImage3:SetTexture(nil)
                dealtCardsFrameDealer.dealerThirdCardText:Hide()
                dealtCardsFrameDealer.dealerCardImage4:SetTexture(nil)
                dealtCardsFrameDealer.dealerFourthCardText:Hide()
                dealtCardsFrameDealer.dealerCardImage5:SetTexture(nil)
                dealtCardsFrameDealer.dealerFifthCardText:Hide()
                dealtCardsFrameDealer.dealerCardImage6:SetTexture(nil)
                dealtCardsFrameDealer.dealerSixthCardText:Hide()
                dealtCardsFrameDealer.dealerCardImage7:SetTexture(nil)
                dealtCardsFrameDealer.dealerSeventhCardText:Hide()

                dealtCardsFrameDealerSplit.dealerCardImage1:SetTexture(nil)
                dealtCardsFrameDealerSplit.dealerFirstCardText:Hide()
                dealtCardsFrameDealerSplit.dealerCardImage2:SetTexture(nil)
                dealtCardsFrameDealerSplit.dealerSecondCardText:Hide()
                dealtCardsFrameDealerSplit.dealerCardImage3:SetTexture(nil)
                dealtCardsFrameDealerSplit.dealerThirdCardText:Hide()
                dealtCardsFrameDealerSplit.dealerCardImage4:SetTexture(nil)
                dealtCardsFrameDealerSplit.dealerFourthCardText:Hide()
                dealtCardsFrameDealerSplit.dealerCardImage5:SetTexture(nil)
                dealtCardsFrameDealerSplit.dealerFifthCardText:Hide()
                dealtCardsFrameDealerSplit.dealerCardImage6:SetTexture(nil)
                dealtCardsFrameDealerSplit.dealerSixthCardText:Hide()
                dealtCardsFrameDealerSplit.dealerCardImage7:SetTexture(nil)
                dealtCardsFrameDealerSplit.dealerSeventhCardText:Hide()

                if dealerCardName1 and dealerCardFileName1 then
                    dealtCardsFrameDealer.dealerCardImage1:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. dealerCardFileName1)
                    dealtCardsFrameDealer.dealerCardImage1:Show()
                    dealtCardsFrameDealer.dealerFirstCardText:Show()
                    dealtCardsFrameDealerSplit.dealerCardImage1:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. dealerCardFileName1)
                    dealtCardsFrameDealerSplit.dealerCardImage1:Show()
                    dealtCardsFrameDealerSplit.dealerFirstCardText:Show()
                end
                if dealerCardName2 and dealerCardFileName2 then
                    dealtCardsFrameDealer.dealerCardImage2:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. dealerCardFileName2)
                    dealtCardsFrameDealer.dealerCardImage2:Show()
                    dealtCardsFrameDealer.dealerSecondCardText:Show()
                    dealtCardsFrameDealerSplit.dealerCardImage2:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. dealerCardFileName2)
                    dealtCardsFrameDealerSplit.dealerCardImage2:Show()
                    dealtCardsFrameDealerSplit.dealerSecondCardText:Show()
                end
                if dealerCardName3 and dealerCardFileName3 then
                    dealtCardsFrameDealer.dealerCardImage3:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. dealerCardFileName3)
                    dealtCardsFrameDealer.dealerCardImage3:Show()
                    dealtCardsFrameDealer.dealerThirdCardText:Show()
                    dealtCardsFrameDealerSplit.dealerCardImage3:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. dealerCardFileName3)
                    dealtCardsFrameDealerSplit.dealerCardImage3:Show()
                    dealtCardsFrameDealerSplit.dealerThirdCardText:Show()
                end
                if dealerCardName4 and dealerCardFileName4 then
                    dealtCardsFrameDealer.dealerCardImage4:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. dealerCardFileName4)
                    dealtCardsFrameDealer.dealerCardImage4:Show()
                    dealtCardsFrameDealer.dealerFourthCardText:Show()
                    dealtCardsFrameDealerSplit.dealerCardImage4:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. dealerCardFileName4)
                    dealtCardsFrameDealerSplit.dealerCardImage4:Show()
                    dealtCardsFrameDealerSplit.dealerFourthCardText:Show()
                end
                if dealerCardName5 and dealerCardFileName5 then
                    dealtCardsFrameDealer.dealerCardImage5:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. dealerCardFileName5)
                    dealtCardsFrameDealer.dealerCardImage5:Show()
                    dealtCardsFrameDealer.dealerFifthCardText:Show()
                    dealtCardsFrameDealerSplit.dealerCardImage5:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. dealerCardFileName5)
                    dealtCardsFrameDealerSplit.dealerCardImage5:Show()
                    dealtCardsFrameDealerSplit.dealerFifthCardText:Show()
                end
                if dealerCardName6 and dealerCardFileName6 then
                    dealtCardsFrameDealer.dealerCardImage6:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. dealerCardFileName6)
                    dealtCardsFrameDealer.dealerCardImage6:Show()
                    dealtCardsFrameDealer.dealerSixthCardText:Show()
                    dealtCardsFrameDealerSplit.dealerCardImage6:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. dealerCardFileName6)
                    dealtCardsFrameDealerSplit.dealerCardImage6:Show()
                    dealtCardsFrameDealerSplit.dealerSixthCardText:Show()
                end
                if dealerCardName7 and dealerCardFileName7 then
                    dealtCardsFrameDealer.dealerCardImage7:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. dealerCardFileName7)
                    dealtCardsFrameDealer.dealerCardImage7:Show()
                    dealtCardsFrameDealer.dealerSeventhCardText:Show()
                    dealtCardsFrameDealerSplit.dealerCardImage7:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. dealerCardFileName7)
                    dealtCardsFrameDealerSplit.dealerCardImage7:Show()
                    dealtCardsFrameDealerSplit.dealerSeventhCardText:Show()
                end
            end

        elseif string.find(message, "What is your decision") then
            if string.find(message, "(H1)") then
                if playerName == unitName1 then
                    player1SplitHand1Turn()
                    StartCountdownTimer1()
                else
                end
            elseif string.find(message, "(H2)") then
                if playerName == unitName1 then
                    player1SplitHand2Turn()
                    StartCountdownTimer1()
                else
                end
            end

            if string.find(message, unitName1) and not string.find(message, "(H1)") and not string.find(message, "(H2)") then
                if playerName == unitName1 then
                    player1Turn()
                    StartCountdownTimer1()
                else
                end
            elseif string.find(message, unitName2) and not string.find(message, "(H1)") and not string.find(message, "(H2)") then
                if playerName == unitName2 then
                    playerTurn2()
                    StartCountdownTimer2()
                else
                end
            end
        









        -- >>> BLACKJACK <<<
        -- >>> BLACKJACK <<<
        -- >>> BLACKJACK <<<

        -- Dealer
        elseif string.find(message, "Dealer got Blackjack") then
            PlaySoundFile(soundFilePaths[36]) -- "Dealer - Blackjack"
            playerFrame.dealerCardTotalText:SetText("Blackjack")
            playerFrame.dealerCardTotalText:SetTextColor(1, 1, 0)

        -- Single Hand
        elseif string.find(message, "has Blackjack") and not string.find(message, "Hand 1") and not string.find(message, "Hand 2") then
            if string.find(message, unitName1) then
                PlaySoundFile(soundFilePaths[52]) -- "Player 1 - Blackjack"
                playerFrame.player1CardTotalText:SetText("Blackjack")
                playerFrame.player1CardTotalText:SetTextColor(1, 1, 0)
            end

        -- Split Hand 1
        elseif string.find(message, "Hand 1") and string.find(message, "has Blackjack") then
            if string.find(message, unitName1) then
                PlaySoundFile(soundFilePaths[52]) -- "Player 1 - Blackjack"
                playerFrame.player1SplitHand1CardTotalText:SetText("Blackjack")
                playerFrame.player1SplitHand1CardTotalText:SetTextColor(1, 1, 0)
            end

        -- Split Hand 2
        elseif string.find(message, "Hand 2") and string.find(message, "has Blackjack") then
            if string.find(message, unitName1) then
                PlaySoundFile(soundFilePaths[52]) -- "Player 1 - Blackjack"
                playerFrame.player1SplitHand2CardTotalText:SetText("Blackjack")
                playerFrame.player1SplitHand2CardTotalText:SetTextColor(1, 1, 0)
            end  













        -- >>> RESULTS <<<
        -- >>> RESULTS <<<
        -- >>> RESULTS <<<


        -- Bust (Single Hand)
        elseif string.find(message, "has gone bust with a total of") and not string.find(message, "Hand 1") and not string.find(message, "Hand 2") then
            if string.find(message, unitName1) then
                PlaySoundFile(soundFilePaths[48]) -- "Player 1 - Bust"
                player1MainBetAmount:SetTextColor(1, 0, 0)
                player1Loss()
                player1InsuranceLoss()

                player1Hotstreak = 0
                player1HotStreakCheck()

            end

        -- Bust (Split Hand 1)
        elseif string.find(message, "has gone bust with a total of") and string.find(message, "Hand 1") then
            if string.find(message, unitName1) then
                PlaySoundFile(soundFilePaths[48]) -- "Player 1 - Bust"
                player1SplitH1BetAmount:SetTextColor(1, 0, 0)
            end

        -- Bust (Split Hand 2)
        elseif string.find(message, "has gone bust with a total of") and string.find(message, "Hand 2") then
            if string.find(message, unitName1) then
                PlaySoundFile(soundFilePaths[48]) -- "Player 1 - Bust"
                player1SplitH2BetAmount:SetTextColor(1, 0, 0)
            end

        -- Win (Single Hand)
        elseif string.find(message, "has won this round") then
            if string.find(message, unitName1) then
                PlaySoundFile(soundFilePaths[44]) -- "Player 1 - Win"
                player1MainBetAmount:SetTextColor(0, 1, 0)

                if playerFrame.player1CardTotalText:GetText() == "Blackjack" then
                    player1BJWin()
                else
                    player1Win()
                end

                player1SessionWinAnnouncement()

                player1Hotstreak = player1Hotstreak + 1
                player1HotStreakCheck()

            end

        -- Push (Single Hand)
        elseif string.find(message, "has pushed this round") then
            if string.find(message, unitName1) then
                PlaySoundFile(soundFilePaths[55]) -- "Player 1 - Push"
                player1MainBetAmount:SetTextColor(0.2, 0.7, 1)
                player1Push()

                if playerFrame.dealerCardTotalText:GetText() == "Blackjack" then
                    player1InsuranceWin()
                else
                    player1InsuranceLoss()
                end
                
            end

        -- Loss (Single Hand)
        elseif string.find(message, "has lost this round") then
            if string.find(message, unitName1) then
                PlaySoundFile(soundFilePaths[46]) -- "Player 1 - Loss"
                player1MainBetAmount:SetTextColor(1, 0, 0)
                player1Loss()

                if playerFrame.dealerCardTotalText:GetText() == "Blackjack" then
                    player1InsuranceWin()
                else
                    player1InsuranceLoss()
                end

                player1Hotstreak = 0
                player1HotStreakCheck()

            end

        -- Win/Win (Split Hand)
        elseif string.find(message, "has won both Hand 1 and Hand 2") then
            if string.find(message, unitName1) then
                PlaySoundFile(soundFilePaths[57]) -- "Player 1 - H1 Win, H2 Win"
                player1SplitH1BetAmount:SetTextColor(0, 1, 0)
                player1SplitH2BetAmount:SetTextColor(0, 1, 0)

                if playerFrame.player1SplitHand2CardTotalText:GetText() == "Blackjack" then
                    player1SplitH2BJ()
                else
                    player1SplitH2Win()
                end

                if playerFrame.player1SplitHand1CardTotalText:GetText() == "Blackjack" then
                    player1SplitH1BJ()
                else
                    player1SplitH1Win()
                end

                if playerFrame.dealerCardTotalText:GetText() == "Blackjack" then
                    player1InsuranceWin()
                else
                    player1InsuranceLoss()
                end

                player1Hotstreak = player1Hotstreak + 2
                player1HotStreakCheck()
                
            end

        -- Win/Push (Split Hand)
        elseif string.find(message, "has won Hand 1 and pushes on Hand 2") then
            if string.find(message, unitName1) then
                PlaySoundFile(soundFilePaths[59]) -- "Player 1 - H1 Win, H2 Push"
                player1SplitH1BetAmount:SetTextColor(0, 1, 0)
                player1SplitH2BetAmount:SetTextColor(0.2, 0.7, 1)
                player1SplitH2Push()

                if playerFrame.player1SplitHand1CardTotalText:GetText() == "Blackjack" then
                    player1SplitH1BJ()
                else
                    player1SplitH1Win()
                end

                if playerFrame.dealerCardTotalText:GetText() == "Blackjack" then
                    player1InsuranceWin()
                else
                    player1InsuranceLoss()
                end

                player1Hotstreak = player1Hotstreak + 1
                player1HotStreakCheck()

            end

        -- Win/Loss (Split Hand)
        elseif string.find(message, "has won Hand 1 and lost Hand 2") then
            if string.find(message, unitName1) then
                PlaySoundFile(soundFilePaths[58]) -- "Player 1 - H1 Win, H2 Loss"
                player1SplitH1BetAmount:SetTextColor(0, 1, 0)
                player1SplitH2BetAmount:SetTextColor(1, 0, 0)
                player1SplitH2Loss()

                if playerFrame.player1SplitHand1CardTotalText:GetText() == "Blackjack" then
                    player1SplitH1BJ()
                else
                    player1SplitH1Win()
                end

                if playerFrame.dealerCardTotalText:GetText() == "Blackjack" then
                    player1InsuranceWin()
                else
                    player1InsuranceLoss()
                end

                player1Hotstreak = 0
                player1HotStreakCheck()
            end

        -- Push/Push (Split Hand)
        elseif string.find(message, "pushes on both Hand 1 and Hand 2") then
            if string.find(message, unitName1) then
                PlaySoundFile(soundFilePaths[62]) -- "Player 1 - H1 Push, H2 Push"
                player1SplitH1BetAmount:SetTextColor(0.2, 0.7, 1)
                player1SplitH2BetAmount:SetTextColor(0.2, 0.7, 1)
                player1SplitH2Push()
                player1SplitH1Push()

                if playerFrame.dealerCardTotalText:GetText() == "Blackjack" then
                    player1InsuranceWin()
                else
                    player1InsuranceLoss()
                end

            end

        -- Push/Win (Split Hand)
        elseif string.find(message, "pushes on Hand 1 and has won Hand 2") then
            if string.find(message, unitName1) then
                PlaySoundFile(soundFilePaths[60]) -- "Player 1 - H1 Push, H2 Win"
                player1SplitH1BetAmount:SetTextColor(0.2, 0.7, 1)
                player1SplitH2BetAmount:SetTextColor(0, 1, 0)
                
                if playerFrame.player1SplitHand2CardTotalText:GetText() == "Blackjack" then
                    player1SplitH2BJ()
                else
                    player1SplitH2Win()
                end

                player1SplitH1Push()

                if playerFrame.dealerCardTotalText:GetText() == "Blackjack" then
                    player1InsuranceWin()
                else
                    player1InsuranceLoss()
                end

                player1Hotstreak = player1Hotstreak + 1
                player1HotStreakCheck()
            end

        -- Push/Loss (Split Hand)
        elseif string.find(message, "pushes on Hand 1 and has lost Hand 2") then
            if string.find(message, unitName1) then
                PlaySoundFile(soundFilePaths[61]) -- "Player 1 - H1 Push, H2 Loss"
                player1SplitH1BetAmount:SetTextColor(0.2, 0.7, 1)
                player1SplitH2BetAmount:SetTextColor(1, 0, 0)
                player1SplitH2Loss()
                player1SplitH1Push()

                if playerFrame.dealerCardTotalText:GetText() == "Blackjack" then
                    player1InsuranceWin()
                else
                    player1InsuranceLoss()
                end

                player1Hotstreak = 0
                player1HotStreakCheck()
            end
        
        -- Loss/Loss (Split Hand)
        elseif string.find(message, "has lost both Hand 1 and Hand 2") then
            if string.find(message, unitName1) then
                PlaySoundFile(soundFilePaths[64]) -- "Player 1 - H1 Loss, H2 Loss"
                player1SplitH1BetAmount:SetTextColor(1, 0, 0)
                player1SplitH2BetAmount:SetTextColor(1, 0, 0)
                player1SplitH2Loss()
                player1SplitH1Loss()

                if playerFrame.dealerCardTotalText:GetText() == "Blackjack" then
                    player1InsuranceWin()
                else
                    player1InsuranceLoss()
                end

                player1Hotstreak = 0
                player1HotStreakCheck()
            end

        -- Loss/Push (Split Hand)
        elseif string.find(message, "has lost Hand 1 and pushes on Hand 2") then
            if string.find(message, unitName1) then
                PlaySoundFile(soundFilePaths[65]) -- "Player 1 - H1 Loss, H2 Push"
                player1SplitH1BetAmount:SetTextColor(1, 0, 0)
                player1SplitH2BetAmount:SetTextColor(0.2, 0.7, 1)
                player1SplitH2Push()
                player1SplitH1Loss()

                if playerFrame.dealerCardTotalText:GetText() == "Blackjack" then
                    player1InsuranceWin()
                else
                    player1InsuranceLoss()
                end

                player1Hotstreak = 0
                player1HotStreakCheck()
            end

        -- Loss/Win (Split Hand)
        elseif string.find(message, "has lost Hand 1 and won Hand 2") then
            if string.find(message, unitName1) then
                PlaySoundFile(soundFilePaths[63]) -- "Player 1 - H1 Loss, H2 Win"
                player1SplitH1BetAmount:SetTextColor(1, 0, 0)
                player1SplitH2BetAmount:SetTextColor(0, 1, 0)
                
                if playerFrame.player1SplitHand1CardTotalText:GetText() == "Blackjack" then
                    player1SplitH2BJ()
                else
                    player1SplitH2Win()
                end

                player1SplitH1Loss()
                
                if playerFrame.dealerCardTotalText:GetText() == "Blackjack" then
                    player1InsuranceWin()
                else
                    player1InsuranceLoss()
                end

                player1Hotstreak = 0
                player1HotStreakCheck()
            end
















        -- >>> SIDE BETS <<<
        -- >>> SIDE BETS <<<
        -- >>> SIDE BETS <<<

        elseif string.find(message, "hit a Suited Three of a Kind") then
            if string.find(message, "Player 1") and playerName == unitName1 then 

                -- Players: 1
                if Player1Active and not Player2Active and not Player3Active and not Player4Active and not Player5Active then   

                    player1213CardName1 = dealtCards[1]
                    dealer213CardName1 = dealtCards[2]
                    player1213CardName2 = dealtCards[3]

                    player1213CardFileName1 = GetCardFileName(player1213CardName1)
                    dealer213CardFileName1 = GetCardFileName(dealer213CardName1)
                    player1213CardFileName2 = GetCardFileName(player1213CardName2)

                -- Players: 1, 2
                elseif Player1Active and Player2Active and not Player3Active and not Player4Active and not Player5Active then 

                    player1213CardName1 = dealtCards[1]
                    dealer213CardName1 = dealtCards[3]
                    player1213CardName2 = dealtCards[4]

                    player1213CardFileName1 = GetCardFileName(player1213CardName1)
                    dealer213CardFileName1 = GetCardFileName(dealer213CardName1)
                    player1213CardFileName2 = GetCardFileName(player1213CardName2)

                end

                if player1213CardFileName1 then
                    sideBetWinFrame213.player1213CardImage1:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1213CardFileName1)
                else
                    print("Card image filename not found for " .. player1213CardName1)
                end
                if dealer213CardFileName1 then
                    sideBetWinFrame213.dealer213CardImage1:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. dealer213CardFileName1)
                else
                    print("Card image filename not found for " .. dealer213CardName1)
                end
                if player1213CardFileName2 then
                    sideBetWinFrame213.player1213CardImage2:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1213CardFileName2)
                else
                    print("Card image filename not found for " .. player1213CardName2)
                end

                player1SuitedThreeOfAKindNotification()

                if string.find(message, "congratulations") then
                    player1SuitedThreeOfAKindWin()
                else
                    print("")
                end
            elseif string.find(message, "Player 2") and playerName == unitName2 then

                -- Players: 1, 2
                if Player1Active and Player2Active and not Player3Active and not Player4Active and not Player5Active then 

                    player2213CardName1 = dealtCards[2]
                    dealer213CardName1 = dealtCards[3]
                    player2213CardName2 = dealtCards[5]

                    player2213CardFileName1 = GetCardFileName(player2213CardName1)
                    dealer213CardFileName1 = GetCardFileName(dealer213CardName1)
                    player2213CardFileName2 = GetCardFileName(player2213CardName2)

                end

                if player2213CardFileName1 then
                    sideBetWinFrame213.player2213CardImage1:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player2213CardFileName1)
                else
                    print("Card image filename not found for " .. player2213CardName1)
                end
                if dealer213CardFileName1 then
                    sideBetWinFrame213.dealer213CardImage1:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. dealer213CardFileName1)
                else
                    print("Card image filename not found for " .. dealer213CardName1)
                end
                if player2213CardFileName2 then
                    sideBetWinFrame213.player2213CardImage2:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player2213CardFileName2)
                else
                    print("Card image filename not found for " .. player2213CardName2)
                end

                player2SuitedThreeOfAKindNotification()

                if string.find(message, "congratulations") then
                    player2SuitedThreeOfAKindWin()
                else
                    print("")
                end  
            end
        elseif string.find(message, "hit a Straight Flush") then
            if string.find(message, "Player 1") and playerName == unitName1 then 

                -- Players: 1
                if Player1Active and not Player2Active and not Player3Active and not Player4Active and not Player5Active then   

                    player1213CardName1 = dealtCards[1]
                    dealer213CardName1 = dealtCards[2]
                    player1213CardName2 = dealtCards[3]

                    player1213CardFileName1 = GetCardFileName(player1213CardName1)
                    dealer213CardFileName1 = GetCardFileName(dealer213CardName1)
                    player1213CardFileName2 = GetCardFileName(player1213CardName2)

                -- Players: 1, 2
                elseif Player1Active and Player2Active and not Player3Active and not Player4Active and not Player5Active then 

                    player1213CardName1 = dealtCards[1]
                    dealer213CardName1 = dealtCards[3]
                    player1213CardName2 = dealtCards[4]

                    player1213CardFileName1 = GetCardFileName(player1213CardName1)
                    dealer213CardFileName1 = GetCardFileName(dealer213CardName1)
                    player1213CardFileName2 = GetCardFileName(player1213CardName2)

                end

                if player1213CardFileName1 then
                    sideBetWinFrame213.player1213CardImage1:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1213CardFileName1)
                else
                    print("Card image filename not found for " .. player1213CardName1)
                end
                if dealer213CardFileName1 then
                    sideBetWinFrame213.dealer213CardImage1:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. dealer213CardFileName1)
                else
                    print("Card image filename not found for " .. dealer213CardName1)
                end
                if player1213CardFileName2 then
                    sideBetWinFrame213.player1213CardImage2:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1213CardFileName2)
                else
                    print("Card image filename not found for " .. player1213CardName2)
                end

                player1StraightFlushNotification()

                if string.find(message, "congratulations") then
                    player1StraightFlushWin()
                else
                    print("")
                end
            elseif string.find(message, "Player 2") and playerName == unitName2 then

                -- Players: 1, 2
                if Player1Active and Player2Active and not Player3Active and not Player4Active and not Player5Active then 

                    player2213CardName1 = dealtCards[2]
                    dealer213CardName1 = dealtCards[3]
                    player2213CardName2 = dealtCards[5]

                    player2213CardFileName1 = GetCardFileName(player2213CardName1)
                    dealer213CardFileName1 = GetCardFileName(dealer213CardName1)
                    player2213CardFileName2 = GetCardFileName(player2213CardName2)

                end

                if player2213CardFileName1 then
                    sideBetWinFrame213.player2213CardImage1:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player2213CardFileName1)
                else
                    print("Card image filename not found for " .. player2213CardName1)
                end
                if dealer213CardFileName1 then
                    sideBetWinFrame213.dealer213CardImage1:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. dealer213CardFileName1)
                else
                    print("Card image filename not found for " .. dealer213CardName1)
                end
                if player2213CardFileName2 then
                    sideBetWinFrame213.player2213CardImage2:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player2213CardFileName2)
                else
                    print("Card image filename not found for " .. player2213CardName2)
                end

                player2StraightFlushNotification()

                if string.find(message, "congratulations") then
                    player2StraightFlushWin()
                else
                    print("")
                end  
            end
        elseif string.find(message, "hit a Flush") then
            if string.find(message, "Player 1") and playerName == unitName1 then 

                -- Players: 1
                if Player1Active and not Player2Active and not Player3Active and not Player4Active and not Player5Active then   

                    player1213CardName1 = dealtCards[1]
                    dealer213CardName1 = dealtCards[2]
                    player1213CardName2 = dealtCards[3]

                    player1213CardFileName1 = GetCardFileName(player1213CardName1)
                    dealer213CardFileName1 = GetCardFileName(dealer213CardName1)
                    player1213CardFileName2 = GetCardFileName(player1213CardName2)

                -- Players: 1, 2
                elseif Player1Active and Player2Active and not Player3Active and not Player4Active and not Player5Active then 

                    player1213CardName1 = dealtCards[1]
                    dealer213CardName1 = dealtCards[3]
                    player1213CardName2 = dealtCards[4]

                    player1213CardFileName1 = GetCardFileName(player1213CardName1)
                    dealer213CardFileName1 = GetCardFileName(dealer213CardName1)
                    player1213CardFileName2 = GetCardFileName(player1213CardName2)

                end

                if player1213CardFileName1 then
                    sideBetWinFrame213.player1213CardImage1:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1213CardFileName1)
                else
                    print("Card image filename not found for " .. player1213CardName1)
                end
                if dealer213CardFileName1 then
                    sideBetWinFrame213.dealer213CardImage1:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. dealer213CardFileName1)
                else
                    print("Card image filename not found for " .. dealer213CardName1)
                end
                if player1213CardFileName2 then
                    sideBetWinFrame213.player1213CardImage2:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1213CardFileName2)
                else
                    print("Card image filename not found for " .. player1213CardName2)
                end

                player1FlushNotification()

                if string.find(message, "congratulations") then
                    player1FlushWin()
                else
                    print("")
                end
            elseif string.find(message, "Player 2") and playerName == unitName2 then

                -- Players: 1, 2
                if Player1Active and Player2Active and not Player3Active and not Player4Active and not Player5Active then 

                    player2213CardName1 = dealtCards[2]
                    dealer213CardName1 = dealtCards[3]
                    player2213CardName2 = dealtCards[5]

                    player2213CardFileName1 = GetCardFileName(player2213CardName1)
                    dealer213CardFileName1 = GetCardFileName(dealer213CardName1)
                    player2213CardFileName2 = GetCardFileName(player2213CardName2)

                end

                if player2213CardFileName1 then
                    sideBetWinFrame213.player2213CardImage1:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player2213CardFileName1)
                else
                    print("Card image filename not found for " .. player2213CardName1)
                end
                if dealer213CardFileName1 then
                    sideBetWinFrame213.dealer213CardImage1:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. dealer213CardFileName1)
                else
                    print("Card image filename not found for " .. dealer213CardName1)
                end
                if player2213CardFileName2 then
                    sideBetWinFrame213.player2213CardImage2:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player2213CardFileName2)
                else
                    print("Card image filename not found for " .. player2213CardName2)
                end

                player2FlushNotification()

                if string.find(message, "congratulations") then
                    player2FlushWin()
                else
                    print("")
                end  
            end
        elseif string.find(message, "hit a Three of a Kind") then
            if string.find(message, "Player 1") and playerName == unitName1 then 

                -- Players: 1
                if Player1Active and not Player2Active and not Player3Active and not Player4Active and not Player5Active then   

                    player1213CardName1 = dealtCards[1]
                    dealer213CardName1 = dealtCards[2]
                    player1213CardName2 = dealtCards[3]

                    player1213CardFileName1 = GetCardFileName(player1213CardName1)
                    dealer213CardFileName1 = GetCardFileName(dealer213CardName1)
                    player1213CardFileName2 = GetCardFileName(player1213CardName2)

                -- Players: 1, 2
                elseif Player1Active and Player2Active and not Player3Active and not Player4Active and not Player5Active then 

                    player1213CardName1 = dealtCards[1]
                    dealer213CardName1 = dealtCards[3]
                    player1213CardName2 = dealtCards[4]

                    player1213CardFileName1 = GetCardFileName(player1213CardName1)
                    dealer213CardFileName1 = GetCardFileName(dealer213CardName1)
                    player1213CardFileName2 = GetCardFileName(player1213CardName2)

                end

                if player1213CardFileName1 then
                    sideBetWinFrame213.player1213CardImage1:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1213CardFileName1)
                else
                    print("Card image filename not found for " .. player1213CardName1)
                end
                if dealer213CardFileName1 then
                    sideBetWinFrame213.dealer213CardImage1:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. dealer213CardFileName1)
                else
                    print("Card image filename not found for " .. dealer213CardName1)
                end
                if player1213CardFileName2 then
                    sideBetWinFrame213.player1213CardImage2:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1213CardFileName2)
                else
                    print("Card image filename not found for " .. player1213CardName2)
                end

                player1ThreeOfAKindNotification()

                if string.find(message, "congratulations") then
                    player1ThreeOfAKindWin()
                else
                    print("")
                end
            elseif string.find(message, "Player 2") and playerName == unitName2 then

                -- Players: 1, 2
                if Player1Active and Player2Active and not Player3Active and not Player4Active and not Player5Active then 

                    player2213CardName1 = dealtCards[2]
                    dealer213CardName1 = dealtCards[3]
                    player2213CardName2 = dealtCards[5]

                    player2213CardFileName1 = GetCardFileName(player2213CardName1)
                    dealer213CardFileName1 = GetCardFileName(dealer213CardName1)
                    player2213CardFileName2 = GetCardFileName(player2213CardName2)

                end

                if player2213CardFileName1 then
                    sideBetWinFrame213.player2213CardImage1:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player2213CardFileName1)
                else
                    print("Card image filename not found for " .. player2213CardName1)
                end
                if dealer213CardFileName1 then
                    sideBetWinFrame213.dealer213CardImage1:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. dealer213CardFileName1)
                else
                    print("Card image filename not found for " .. dealer213CardName1)
                end
                if player2213CardFileName2 then
                    sideBetWinFrame213.player2213CardImage2:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player2213CardFileName2)
                else
                    print("Card image filename not found for " .. player2213CardName2)
                end

                player2ThreeOfAKindNotification()

                if string.find(message, "congratulations") then
                    player2ThreeOfAKindWin()
                else
                    print("")
                end  
            end
        elseif string.find(message, "hit a Straight") then
            if string.find(message, "Player 1") and playerName == unitName1 then 

                -- Players: 1
                if Player1Active and not Player2Active and not Player3Active and not Player4Active and not Player5Active then   

                    player1213CardName1 = dealtCards[1]
                    dealer213CardName1 = dealtCards[2]
                    player1213CardName2 = dealtCards[3]

                    player1213CardFileName1 = GetCardFileName(player1213CardName1)
                    dealer213CardFileName1 = GetCardFileName(dealer213CardName1)
                    player1213CardFileName2 = GetCardFileName(player1213CardName2)

                -- Players: 1, 2
                elseif Player1Active and Player2Active and not Player3Active and not Player4Active and not Player5Active then 

                    player1213CardName1 = dealtCards[1]
                    dealer213CardName1 = dealtCards[3]
                    player1213CardName2 = dealtCards[4]

                    player1213CardFileName1 = GetCardFileName(player1213CardName1)
                    dealer213CardFileName1 = GetCardFileName(dealer213CardName1)
                    player1213CardFileName2 = GetCardFileName(player1213CardName2)

                end

                if player1213CardFileName1 then
                    sideBetWinFrame213.player1213CardImage1:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1213CardFileName1)
                else
                    print("Card image filename not found for " .. player1213CardName1)
                end
                if dealer213CardFileName1 then
                    sideBetWinFrame213.dealer213CardImage1:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. dealer213CardFileName1)
                else
                    print("Card image filename not found for " .. dealer213CardName1)
                end
                if player1213CardFileName2 then
                    sideBetWinFrame213.player1213CardImage2:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1213CardFileName2)
                else
                    print("Card image filename not found for " .. player1213CardName2)
                end

                player1StraightNotification()

                if string.find(message, "congratulations") then
                    player1StraightWin()
                else
                    print("")
                end
            elseif string.find(message, "Player 2") and playerName == unitName2 then

                -- Players: 1, 2
                if Player1Active and Player2Active and not Player3Active and not Player4Active and not Player5Active then 

                    player2213CardName1 = dealtCards[2]
                    dealer213CardName1 = dealtCards[3]
                    player2213CardName2 = dealtCards[5]

                    player2213CardFileName1 = GetCardFileName(player2213CardName1)
                    dealer213CardFileName1 = GetCardFileName(dealer213CardName1)
                    player2213CardFileName2 = GetCardFileName(player2213CardName2)

                end

                if player2213CardFileName1 then
                    sideBetWinFrame213.player2213CardImage1:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player2213CardFileName1)
                else
                    print("Card image filename not found for " .. player2213CardName1)
                end
                if dealer213CardFileName1 then
                    sideBetWinFrame213.dealer213CardImage1:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. dealer213CardFileName1)
                else
                    print("Card image filename not found for " .. dealer213CardName1)
                end
                if player2213CardFileName2 then
                    sideBetWinFrame213.player2213CardImage2:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player2213CardFileName2)
                else
                    print("Card image filename not found for " .. player2213CardName2)
                end

                player2StraightNotification()

                if string.find(message, "congratulations") then
                    player2StraightWin()
                else
                    print("")
                end  
            end
        elseif string.find(message, "hit a Perfect Pair") then
            if string.find(message, "Player 1") and playerName == unitName1 then 

                -- Players: 1
                if Player1Active and not Player2Active and not Player3Active and not Player4Active and not Player5Active then   

                    player1PPCardName1 = dealtCards[1]
                    player1PPCardName2 = dealtCards[3]

                    player1PPCardFileName1 = GetCardFileName(player1PPCardName1)
                    player1PPCardFileName2 = GetCardFileName(player1PPCardName2)

                -- Players: 1, 2
                elseif Player1Active and Player2Active and not Player3Active and not Player4Active and not Player5Active then 

                    player1PPCardName1 = dealtCards[1]
                    player1PPCardName2 = dealtCards[4]

                    player1PPCardFileName1 = GetCardFileName(player1PPCardName1)
                    player1PPCardFileName2 = GetCardFileName(player1PPCardName2)

                end

                if player1PPCardFileName1 then
                    sideBetWinFramePP.player1PPCardImage1:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1PPCardFileName1)
                else
                    print("Card image filename not found for " .. player1PPCardName1)
                end
                if player1PPCardFileName2 then
                    sideBetWinFramePP.player1PPCardImage2:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1PPCardFileName2)
                else
                    print("Card image filename not found for " .. player1PPCardName2)
                end

                player1PerfectPairNotification()

                if string.find(message, "congratulations") then
                    player1PerfectPairWin()
                else
                    print("")
                end
            elseif string.find(message, "Player 2") and playerName == unitName2 then

                -- Players: 1, 2
                if Player1Active and Player2Active and not Player3Active and not Player4Active and not Player5Active then 

                    player2PPCardName1 = dealtCards[2]
                    player2PPCardName2 = dealtCards[5]

                    player2PPCardFileName1 = GetCardFileName(player2PPCardName1)
                    player2PPCardFileName2 = GetCardFileName(player2PPCardName2)

                end

                if player2PPCardFileName1 then
                    sideBetWinFramePP.player2PPCardImage1:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player2PPCardFileName1)
                else
                    print("Card image filename not found for " .. player2PPCardName1)
                end
                if player2PPCardFileName2 then
                    sideBetWinFramePP.player2PPCardImage2:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player2PPCardFileName2)
                else
                    print("Card image filename not found for " .. player2PPCardName2)
                end

                player2PerfectPairNotification()

                if string.find(message, "congratulations") then
                    player2PerfectPairWin()
                else
                    print("")
                end  
            end
        elseif string.find(message, "hit a Coloured Pair") then
            if string.find(message, "Player 1") and playerName == unitName1 then 

                -- Players: 1
                if Player1Active and not Player2Active and not Player3Active and not Player4Active and not Player5Active then   

                    player1PPCardName1 = dealtCards[1]
                    player1PPCardName2 = dealtCards[3]

                    player1PPCardFileName1 = GetCardFileName(player1PPCardName1)
                    player1PPCardFileName2 = GetCardFileName(player1PPCardName2)

                -- Players: 1, 2
                elseif Player1Active and Player2Active and not Player3Active and not Player4Active and not Player5Active then 

                    player1PPCardName1 = dealtCards[1]
                    player1PPCardName2 = dealtCards[4]

                    player1PPCardFileName1 = GetCardFileName(player1PPCardName1)
                    player1PPCardFileName2 = GetCardFileName(player1PPCardName2)

                end

                if player1PPCardFileName1 then
                    sideBetWinFramePP.player1PPCardImage1:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1PPCardFileName1)
                else
                    print("Card image filename not found for " .. player1PPCardName1)
                end
                if player1PPCardFileName2 then
                    sideBetWinFramePP.player1PPCardImage2:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1PPCardFileName2)
                else
                    print("Card image filename not found for " .. player1PPCardName2)
                end

                player1ColouredPairNotification()

                if string.find(message, "congratulations") then
                    player1ColouredPairWin()
                else
                    print("")
                end
            elseif string.find(message, "Player 2") and playerName == unitName2 then

                -- Players: 1, 2
                if Player1Active and Player2Active and not Player3Active and not Player4Active and not Player5Active then 

                    player2PPCardName1 = dealtCards[2]
                    player2PPCardName2 = dealtCards[5]

                    player2PPCardFileName1 = GetCardFileName(player2PPCardName1)
                    player2PPCardFileName2 = GetCardFileName(player2PPCardName2)

                end

                if player2PPCardFileName1 then
                    sideBetWinFramePP.player2PPCardImage1:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player2PPCardFileName1)
                else
                    print("Card image filename not found for " .. player2PPCardName1)
                end
                if player2PPCardFileName2 then
                    sideBetWinFramePP.player2PPCardImage2:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player2PPCardFileName2)
                else
                    print("Card image filename not found for " .. player2PPCardName2)
                end

                player2ColouredPairNotification()

                if string.find(message, "congratulations") then
                    player2ColouredPairWin()
                else
                    print("")
                end  
            end
        elseif string.find(message, "hit a Mixed Pair") then
            if string.find(message, "Player 1") and playerName == unitName1 then 

                -- Players: 1
                if Player1Active and not Player2Active and not Player3Active and not Player4Active and not Player5Active then   

                    player1PPCardName1 = dealtCards[1]
                    player1PPCardName2 = dealtCards[3]

                    player1PPCardFileName1 = GetCardFileName(player1PPCardName1)
                    player1PPCardFileName2 = GetCardFileName(player1PPCardName2)

                -- Players: 1, 2
                elseif Player1Active and Player2Active and not Player3Active and not Player4Active and not Player5Active then 

                    player1PPCardName1 = dealtCards[1]
                    player1PPCardName2 = dealtCards[4]

                    player1PPCardFileName1 = GetCardFileName(player1PPCardName1)
                    player1PPCardFileName2 = GetCardFileName(player1PPCardName2)

                end

                if player1PPCardFileName1 then
                    sideBetWinFramePP.player1PPCardImage1:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1PPCardFileName1)
                else
                    print("Card image filename not found for " .. player1PPCardName1)
                end
                if player1PPCardFileName2 then
                    sideBetWinFramePP.player1PPCardImage2:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player1PPCardFileName2)
                else
                    print("Card image filename not found for " .. player1PPCardName2)
                end

                player1MixedPairNotification()

                if string.find(message, "congratulations") then
                    player1MixedPairWin()
                else
                    print("")
                end
            elseif string.find(message, "Player 2") and playerName == unitName2 then

                -- Players: 1, 2
                if Player1Active and Player2Active and not Player3Active and not Player4Active and not Player5Active then 

                    player2PPCardName1 = dealtCards[2]
                    player2PPCardName2 = dealtCards[5]

                    player2PPCardFileName1 = GetCardFileName(player2PPCardName1)
                    player2PPCardFileName2 = GetCardFileName(player2PPCardName2)

                end

                if player2PPCardFileName1 then
                    sideBetWinFramePP.player2PPCardImage1:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player2PPCardFileName1)
                else
                    print("Card image filename not found for " .. player2PPCardName1)
                end
                if player2PPCardFileName2 then
                    sideBetWinFramePP.player2PPCardImage2:SetTexture("Interface\\AddOns\\BlackjackPlayer\\Images\\" .. player2PPCardFileName2)
                else
                    print("Card image filename not found for " .. player2PPCardName2)
                end

                player2MixedPairNotification()

                if string.find(message, "congratulations") then
                    player2MixedPairWin()
                else
                    print("")
                end  
            end
        end
    end
    AddMessageToScrollFrame(message, sender)
end)

-- Register the event handler for system messages
local eventFrame = CreateFrame("Frame")
eventFrame:RegisterEvent("CHAT_MSG_SYSTEM")
eventFrame:SetScript("OnEvent", function(self, event, arg1)
    if event == "CHAT_MSG_SYSTEM" then
        -- Extract sender from the system message
        local sender = string.match(arg1, "(%S+) rolls %d+ %(.-%d+%-(%d+)%)")
        if sender then
            AddMessageToScrollFrame(arg1, sender)
        end
    end
end)















playerFrame.player1InsuranceYesButton:SetScript("OnClick", function()

    player1MainBet = tonumber(player1MainBetEditBox:GetText())
    player1InsuranceValue = player1MainBet / 2
    player1currentBankroll = tonumber(string.match(bankrollFrame.player1TotalBankrollTableDisplay:GetText(), "%d+"))

    if player1currentBankroll - player1InsuranceValue < 0 then
        print("You do not have enough gold in your bankroll to take insurance. Please visit the Cash Desk.")
    else
        player1InsuranceYesIcon:Show()
        playerFrame.player1InsuranceYesButton:Disable()
        playerFrame.player1InsuranceNoButton:Disable()
        playerFrame.player1HitButton:Enable()
        playerFrame.player1StandButton:Enable()
        playerFrame.player1DoubleButton:Enable()
        countdownDuration = 30
        playerFrame.timerText1:SetText("")
        playerFrame.timerText1:Hide()
        betInsuranceAmount1 = 0

        if player1MainBet then
            SendChatMessage("[P1] YES to Insurance - adding " .. player1InsuranceValue .. "G", "RAID")         
            playerFrame.player1InsuranceBetAmount:SetText(player1InsuranceValue .. " G")
        end

        player1totalBetAmount = player1totalBetAmount + tonumber(player1InsuranceValue)
        historyFrame.player1totalWageredAmount:SetText(player1totalBetAmount .. " G")

        player1TotalBankrollAmount = player1TotalBankrollAmount - tonumber(player1InsuranceValue)
        bankrollFrame.player1TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
        cashDeskFrame.player1TotalBankroll:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
    end
end)

playerFrame.player1InsuranceNoButton:SetScript("OnClick", function()
    player1InsuranceNoIcon:Show()
    playerFrame.player1InsuranceYesButton:Disable()
    playerFrame.player1InsuranceNoButton:Disable()
    playerFrame.player1HitButton:Enable()
    playerFrame.player1StandButton:Enable()
    playerFrame.player1DoubleButton:Enable()
    countdownDuration = 30
    playerFrame.timerText1:SetText("")
    playerFrame.timerText1:Hide()
    SendChatMessage("[P1] NO to Insurance", "RAID")
end)


playerFrame.player1HitButton:SetScript("OnClick", function()
    -- Handle the "hit" button action
    SendChatMessage("[P1] Hit", "RAID")
    playerFrame.player1HitButton:Disable()
    playerFrame.player1StandButton:Disable()
    playerFrame.player1DoubleButton:Disable()
    playerFrame.player1SplitButton:Disable()
    if playerFrame.dealerCardTotalText:GetText() == "1 or 11" and playerFrame.player1InsuranceYesButton:IsEnabled() and playerFrame.player1InsuranceNoButton:IsEnabled() then
        SendChatMessage("[P1] NO to Insurance", "RAID")
        playerFrame.player1InsuranceYesButton:Disable()
        playerFrame.player1InsuranceNoButton:Disable()
        player1InsuranceNoIcon:Show()
    end
    PlaySoundFile(soundFilePaths[39])
    player1DoubleToggle = true
    timerReset()
end)

playerFrame.player1HitButtonSplitH1:SetScript("OnClick", function()
    SendChatMessage("[P1] (H1) Hit", "RAID")
    playerFrame.player1HitButtonSplitH1:Disable()
    playerFrame.player1StandButtonSplitH1:Disable()
    playerFrame.player1DoubleButtonSplitH1:Disable()
    PlaySoundFile(soundFilePaths[39])
    player1DoubleHand1Toggle = true
    timerReset()
end)

playerFrame.player1HitButtonSplitH2:SetScript("OnClick", function()
    SendChatMessage("[P1] (H2) Hit", "RAID")
    playerFrame.player1HitButtonSplitH2:Disable()
    playerFrame.player1StandButtonSplitH2:Disable()
    playerFrame.player1DoubleButtonSplitH2:Disable()
    PlaySoundFile(soundFilePaths[39])
    player1DoubleHand2Toggle = true
    timerReset()
end)

playerFrame.player1StandButton:SetScript("OnClick", function()
    -- Handle the "stand" button action
    SendChatMessage("[P1] Stand", "RAID")
    playerFrame.player1HitButton:Disable()
    playerFrame.player1StandButton:Disable()
    playerFrame.player1DoubleButton:Disable()
    playerFrame.player1SplitButton:Disable()
    playerFrame.timerText1:SetText("")
    playerFrame.timerText1:Hide()
    if playerFrame.player1CardTotalText:GetText() == "1 or 11" then
        playerFrame.player1CardTotalText:SetText("11")
    elseif playerFrame.player1CardTotalText:GetText() == "2 or 12" then
        playerFrame.player1CardTotalText:SetText("12")
    elseif playerFrame.player1CardTotalText:GetText() == "3 or 13" then
        playerFrame.player1CardTotalText:SetText("13")
    elseif playerFrame.player1CardTotalText:GetText() == "4 or 14" then
        playerFrame.player1CardTotalText:SetText("14")
    elseif playerFrame.player1CardTotalText:GetText() == "5 or 15" then
        playerFrame.player1CardTotalText:SetText("15")
    elseif playerFrame.player1CardTotalText:GetText() == "6 or 16" then
        playerFrame.player1CardTotalText:SetText("16")
    elseif playerFrame.player1CardTotalText:GetText() == "7 or 17" then
        playerFrame.player1CardTotalText:SetText("17")
    elseif playerFrame.player1CardTotalText:GetText() == "8 or 18" then
        playerFrame.player1CardTotalText:SetText("18")
    elseif playerFrame.player1CardTotalText:GetText() == "9 or 19" then
        playerFrame.player1CardTotalText:SetText("19")
    elseif playerFrame.player1CardTotalText:GetText() == "10 or 20" then
        playerFrame.player1CardTotalText:SetText("20")
    end
    if playerFrame.dealerCardTotalText:GetText() == "1 or 11" and playerFrame.player1InsuranceYesButton:IsEnabled() and playerFrame.player1InsuranceNoButton:IsEnabled() then
        SendChatMessage("[P1] NO to Insurance", "RAID")
        playerFrame.player1InsuranceYesButton:Disable()
        playerFrame.player1InsuranceNoButton:Disable()
        player1InsuranceNoIcon:Show()
    end
    PlaySoundFile(soundFilePaths[40])
    player1DoubleToggle = true
    timerReset()
end)

playerFrame.player1StandButtonSplitH1:SetScript("OnClick", function()
    SendChatMessage("[P1] (H1) Stand", "RAID")
    playerFrame.player1HitButtonSplitH1:Disable()
    playerFrame.player1StandButtonSplitH1:Disable()
    playerFrame.player1DoubleButtonSplitH1:Disable()
    PlaySoundFile(soundFilePaths[40])
    player1DoubleHand1Toggle = true
    timerReset()
end)

playerFrame.player1StandButtonSplitH2:SetScript("OnClick", function()
    SendChatMessage("[P1] (H2) Stand", "RAID")
    playerFrame.player1HitButtonSplitH2:Disable()
    playerFrame.player1StandButtonSplitH2:Disable()
    playerFrame.player1DoubleButtonSplitH2:Disable()
    PlaySoundFile(soundFilePaths[40])
    player1DoubleHand2Toggle = true
    timerReset()
end)

playerFrame.player1DoubleButton:SetScript("OnClick", function()

    player1MainBet = tonumber(player1MainBetEditBox:GetText())
    player1currentBankroll = tonumber(string.match(bankrollFrame.player1TotalBankrollTableDisplay:GetText(), "%d+"))

    if player1currentBankroll - player1MainBet < 0 then
        print("You do not have enough gold in your bankroll to double your bet. Please visit the Cash Desk.")
    else
        local betDoubleAmount1 = 0
        betAmount1 = tonumber(player1MainBetEditBox:GetText()) -- Get the entered bet amount
        if betAmount1 then
            betDoubleAmount1 = betAmount1 * 2
            SendChatMessage("[P1] Double my bet to " ..betDoubleAmount1.. "G", "RAID")
            player1MainBetEditBox:SetText(betDoubleAmount1)
            player1MainBetAmount:SetText(betDoubleAmount1)
            playerFrame.player1HitButton:Disable()
            playerFrame.player1StandButton:Disable()
            playerFrame.player1DoubleButton:Disable() 
            playerFrame.timerText1:SetText("")
            playerFrame.timerText1:Hide()
            countdownDuration = 30

            player1TotalBankrollAmount = player1TotalBankrollAmount - tonumber(betAmount1)
            bankrollFrame.player1TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
            cashDeskFrame.player1TotalBankroll:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")

            player1totalBetAmount = player1totalBetAmount + tonumber(betAmount1)
            historyFrame.player1totalWageredAmount:SetText(player1totalBetAmount .. " G")

        end
        if playerFrame.dealerCardTotalText:GetText() == "1 or 11" and playerFrame.player1InsuranceYesButton:IsEnabled() and playerFrame.player1InsuranceNoButton:IsEnabled() then
            SendChatMessage("[P1] NO to Insurance", "RAID")
            playerFrame.player1InsuranceYesButton:Disable()
            playerFrame.player1InsuranceNoButton:Disable()
            player1InsuranceNoIcon:Show()
        end
        PlaySoundFile(soundFilePaths[41])
        player1DoubleToggle = true
        timerReset()

    end
end)

playerFrame.player1DoubleButtonSplitH1:SetScript("OnClick", function()
    
    player1SplitH1MainBet = tonumber(player1SplitH1EditBox:GetText())
    player1currentBankroll = tonumber(string.match(bankrollFrame.player1TotalBankrollTableDisplay:GetText(), "%d+"))

    if player1currentBankroll - player1SplitH1MainBet < 0 then
        print("You do not have enough gold in your bankroll to double your bet. Please visit the Cash Desk.")
    else
    
        local betDoubleAmountSplitH1 = 0
        betAmountSplitH1 = tonumber(string.match(player1SplitH1BetAmount:GetText(), "%d+"))
        if betAmountSplitH1 then
            betDoubleAmountSplitH1 = betAmountSplitH1 * 2
            SendChatMessage("[P1] (H1) Double my bet to " ..betDoubleAmountSplitH1.. "G", "RAID")
            player1SplitH1BetAmount:SetText(betDoubleAmountSplitH1 .. " G")
            playerFrame.player1HitButtonSplitH1:Disable()
            playerFrame.player1StandButtonSplitH1:Disable()
            playerFrame.player1DoubleButtonSplitH1:Disable()
            player1DoubleHand1Toggle = true
            timerReset()

            player1SplitH1EditBox:SetText(betDoubleAmountSplitH1)

            player1TotalBankrollAmount = player1TotalBankrollAmount - tonumber(betAmountSplitH1)
            bankrollFrame.player1TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
            cashDeskFrame.player1TotalBankroll:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")

            player1totalBetAmount = player1totalBetAmount + tonumber(betAmountSplitH1)
            historyFrame.player1totalWageredAmount:SetText(player1totalBetAmount .. " G")

        end
    end
end)

playerFrame.player1DoubleButtonSplitH2:SetScript("OnClick", function()
    
    player1SplitH2MainBet = tonumber(player1SplitH2EditBox:GetText())
    player1currentBankroll = tonumber(string.match(bankrollFrame.player1TotalBankrollTableDisplay:GetText(), "%d+"))

    if player1currentBankroll - player1SplitH2MainBet < 0 then
        print("You do not have enough gold in your bankroll to double your bet. Please visit the Cash Desk.")
    else

        local betDoubleAmountSplitH2 = 0
        betAmountSplitH2 = tonumber(string.match(player1SplitH2BetAmount:GetText(), "%d+"))
        if betAmountSplitH2 then
            betDoubleAmountSplitH2 = betAmountSplitH2 * 2
            SendChatMessage("[P1] (H2) Double my bet to " ..betDoubleAmountSplitH2.. "G", "RAID")
            player1SplitH2BetAmount:SetText(betDoubleAmountSplitH2 .. " G")
            playerFrame.player1HitButtonSplitH2:Disable()
            playerFrame.player1StandButtonSplitH2:Disable()
            playerFrame.player1DoubleButtonSplitH2:Disable()
            player1DoubleHand2Toggle = true
            timerReset()

            player1SplitH2EditBox:SetText(betDoubleAmountSplitH2)

            player1TotalBankrollAmount = player1TotalBankrollAmount - tonumber(betAmountSplitH2)
            bankrollFrame.player1TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")
            cashDeskFrame.player1TotalBankroll:SetText("Total Bankroll: " .. player1TotalBankrollAmount .. " G")

            player1totalBetAmount = player1totalBetAmount + tonumber(betAmountSplitH2)
            historyFrame.player1totalWageredAmount:SetText(player1totalBetAmount .. " G")

        end
    end
end)

playerFrame.player1SplitButton:SetScript("OnClick", function()
    
    player1MainBet = tonumber(player1MainBetEditBox:GetText())
    player1currentBankroll = tonumber(string.match(bankrollFrame.player1TotalBankrollTableDisplay:GetText(), "%d+"))

    if player1currentBankroll - player1MainBet < 0 then
        print("You do not have enough gold in your bankroll to split your hand. Please visit the Cash Desk.")
    else

        SendChatMessage("[P1] Split", "RAID")
        playerFrame.player1HitButton:Hide()
        playerFrame.player1StandButton:Hide()
        playerFrame.player1DoubleButton:Hide()
        playerFrame.player1SplitButton:Hide()
        playerFrame.player1InsuranceYesButton:Hide()
        playerFrame.player1InsuranceNoButton:Hide()
        playerFrame.player1InsuranceTitle:Hide()
        playerFrame.player1InsuranceSubtitle:Hide()
        player1ConfirmMainBetButton:Hide()
        player1MainBetEditBox:Hide()
        playerFrame.player1MainBetTitle:Hide()
        

        playerFrame.player1SplitH1Title:Show()
        playerFrame.player1SplitH2Title:Show()
        player1SplitH1EditBox:Show()
        player1SplitH2EditBox:Show()
        playerFrame.player1HitButtonSplitH1:Show()
        playerFrame.player1StandButtonSplitH1:Show()
        playerFrame.player1DoubleButtonSplitH1:Show()
        playerFrame.player1HitButtonSplitH2:Show()
        playerFrame.player1StandButtonSplitH2:Show()
        playerFrame.player1DoubleButtonSplitH2:Show()

        betAmount1 = tonumber(player1MainBetEditBox:GetText())
        if betAmount1 then
            player1SplitH1EditBox:SetText(betAmount1)
            player1SplitH2EditBox:SetText(betAmount1)
        end

        if playerFrame.dealerCardTotalText:GetText() == "1 or 11" and playerFrame.player1InsuranceYesButton:IsEnabled() and playerFrame.player1InsuranceNoButton:IsEnabled() then
            SendChatMessage("[P1] NO to Insurance", "RAID")
            playerFrame.player1InsuranceYesButton:Disable()
            playerFrame.player1InsuranceNoButton:Disable()
            player1InsuranceNoIcon:Show()
        end

        timerReset()
    end
end)




playerFrame.player2InsuranceYesButton:SetScript("OnClick", function()
    insuranceYesIcon2:Show()
    playerFrame.player2InsuranceYesButton:Disable()
    playerFrame.player2InsuranceNoButton:Disable()
    countdownDuration = 30
    playerFrame.timerText2:SetText("")
    playerFrame.timerText2:Hide()
    betInsuranceAmount2 = 0
    betMainAmount2 = tonumber(player2MainBetEditBox:GetText())
    if betMainAmount2 then
        betInsuranceAmount2 = betMainAmount2 / 2
        SendChatMessage("[P2] YES to Insurance - adding " .. betInsuranceAmount2 .. "G", "RAID")
        playerFrame.player2InsuranceBetAmount:SetText(betInsuranceAmount2 .. " G")
    end

    player1totalBetAmount = player1totalBetAmount + tonumber(betInsuranceAmount2)
    historyFrame.player1totalWageredAmount:SetText(player1totalBetAmount .. " G")

end)

playerFrame.player2InsuranceNoButton:SetScript("OnClick", function()
    insuranceNoIcon2:Show()
    playerFrame.player2InsuranceYesButton:Disable()
    playerFrame.player2InsuranceNoButton:Disable()
    countdownDuration = 30
    playerFrame.timerText2:SetText("")
    playerFrame.timerText2:Hide()
    SendChatMessage("[P2] NO to Insurance", "RAID")
end)

playerFrame.player2HitButton:SetScript("OnClick", function()
    -- Handle the "hit" button action
    SendChatMessage("[P2] Hit", "RAID")
    playerFrame.player2HitButton:Disable()
    playerFrame.player2StandButton:Disable()
    playerFrame.player2DoubleButton:Disable()
    playerFrame.player2SplitButton:Disable()
    playerFrame.timerText2:SetText("")
    playerFrame.timerText2:Hide()
    if playerFrame.dealerCardTotalText:GetText() == "1 or 11" and playerFrame.player2InsuranceYesButton:IsEnabled() and playerFrame.player2InsuranceNoButton:IsEnabled() then
        SendChatMessage("[P2] NO to Insurance", "RAID")
        playerFrame.player2InsuranceYesButton:Disable()
        playerFrame.player2InsuranceNoButton:Disable()
        insuranceNoIcon2:Show()
    end
    PlaySoundFile(soundFilePaths[39])
    double2Flag = true
    timerReset()
end)

playerFrame.player2StandButton:SetScript("OnClick", function()
    -- Handle the "stand" button action
    SendChatMessage("[P2] Stand", "RAID")
    playerFrame.player2HitButton:Disable()
    playerFrame.player2StandButton:Disable()
    playerFrame.player2DoubleButton:Disable()
    playerFrame.player2SplitButton:Disable()
    playerFrame.timerText2:SetText("")
    playerFrame.timerText2:Hide()
    if playerFrame.player2CardTotalText:GetText() == "1 or 11" then
        playerFrame.player2CardTotalText:SetText("11")
    elseif playerFrame.player2CardTotalText:GetText() == "2 or 12" then
        playerFrame.player2CardTotalText:SetText("12")
    elseif playerFrame.player2CardTotalText:GetText() == "3 or 13" then
        playerFrame.player2CardTotalText:SetText("13")
    elseif playerFrame.player2CardTotalText:GetText() == "4 or 14" then
        playerFrame.player2CardTotalText:SetText("14")
    elseif playerFrame.player2CardTotalText:GetText() == "5 or 15" then
        playerFrame.player2CardTotalText:SetText("15")
    elseif playerFrame.player2CardTotalText:GetText() == "6 or 16" then
        playerFrame.player2CardTotalText:SetText("16")
    elseif playerFrame.player2CardTotalText:GetText() == "7 or 17" then
        playerFrame.player2CardTotalText:SetText("17")
    elseif playerFrame.player2CardTotalText:GetText() == "8 or 18" then
        playerFrame.player2CardTotalText:SetText("18")
    elseif playerFrame.player2CardTotalText:GetText() == "9 or 19" then
        playerFrame.player2CardTotalText:SetText("19")
    elseif playerFrame.player2CardTotalText:GetText() == "10 or 20" then
        playerFrame.player2CardTotalText:SetText("20")
    end
    if playerFrame.dealerCardTotalText:GetText() == "1 or 11" and playerFrame.player2InsuranceYesButton:IsEnabled() and playerFrame.player2InsuranceNoButton:IsEnabled() then
        SendChatMessage("[P2] NO to Insurance", "RAID")
        playerFrame.player2InsuranceYesButton:Disable()
        playerFrame.player2InsuranceNoButton:Disable()
        insuranceNoIcon2:Show()
    end
    PlaySoundFile(soundFilePaths[40])
    if Player1Active and Player2Active and not Player3Active and not Player4Active and not Player5Active then
        turn = 17
    end
    double2Flag = true
    timerReset()
end)

playerFrame.player2DoubleButton:SetScript("OnClick", function()
    local betDoubleAmount2 = 0
    betAmount2 = tonumber(player2MainBetEditBox:GetText()) -- Get the entered bet amount
    if betAmount2 then
        betDoubleAmount2 = betAmount2 * 2
        SendChatMessage("[P2] Double my bet to " ..betDoubleAmount2.. "G", "RAID")
        player2MainBetEditBox:SetText(betDoubleAmount2)
        player2MainBetAmount:SetText(betDoubleAmount2)
        playerFrame.player2HitButton:Disable()
        playerFrame.player2StandButton:Disable()
        playerFrame.player2DoubleButton:Disable() 
        playerFrame.timerText2:SetText("")
        playerFrame.timerText2:Hide()
        countdownDuration = 30

        player2TotalBankrollAmount = player2TotalBankrollAmount - tonumber(betAmount2)
        bankrollFrame.player2TotalBankrollTableDisplay:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")
        cashDeskFrame.player2TotalBankroll:SetText("Total Bankroll: " .. player2TotalBankrollAmount .. " G")

        player2totalBetAmount = player2totalBetAmount + tonumber(betAmount2)
        historyFrame.player2totalWageredAmount:SetText(player2totalBetAmount .. " G")

    end
    if playerFrame.dealerCardTotalText:GetText() == "1 or 11" and playerFrame.player2InsuranceYesButton:IsEnabled() and playerFrame.player2InsuranceNoButton:IsEnabled() then
        SendChatMessage("[P2] NO to Insurance", "RAID")
        playerFrame.player2InsuranceYesButton:Disable()
        playerFrame.player2InsuranceNoButton:Disable()
        insuranceNoIcon2:Show()
    end
    PlaySoundFile(soundFilePaths[41])
    double2Flag = true
    timerReset()
end)




playerFrame.leaveTableButton:SetScript("OnClick", function()
    -- Handle the "leaving" action, communicate with players, and change game state
    SendChatMessage("{circle} I am leaving the table.", "RAID")
    playerFrame:Hide()
    historyFrame:Hide()
    rebetFrame:Hide()
    sideBetWinFramePP:Hide()
    sideBetWinFrame213:Hide()
    rulesFrame:Hide()
    payoutsFrame:Hide()
    initialFrame:Show()
end)

-- Add a click event handler to the "Join Table" button
initialFrame.joinButton:SetScript("OnClick", function(self, button, down)
    if button == "LeftButton" then
        -- Hide the initial frame
        initialFrame:Hide()
        -- Show the playerFrame
        playerFrame:Show()
        bankrollFrame:Show()
        SendChatMessage("{circle} I have joined the table.", "RAID")
        -- You can add more code here to initialize the playerFrame or start the game.
    end
end)




cashDeskFrame.joinButtonCashDesk:SetScript("OnClick", function(self, button, down)
    if button == "LeftButton" then
        cashDeskFrame:Hide()
        initialFrame:Hide()
        stepsFrame:Hide()
        stepsFrame.dealerImage:Hide()
        stepsFrame2:Hide()
        stepsFrame2.dealerImage2:Hide()
        playerFrame:Show()
        bankrollFrame:Show()
        buyInEditBox:SetText("")
        cashOutEditBox:SetText("")
        SendChatMessage("{circle} I have joined the table.", "RAID")
    end
end)

initialFrame.cashDeskButton:SetScript("OnClick", function(self, button, down)
    if button == "LeftButton" then
        initialFrame:Hide()
        cashDeskFrame:Show()
        stepsFrame:Show()
        stepsFrame.dealerImage:Show()
        stepsFrame2:Show()
        stepsFrame2.dealerImage2:Show()
    end
end)

cashDeskFrame.backButton:SetScript("OnClick", function(self, button, down)
    if button == "LeftButton" then
        initialFrame:Show()
        cashDeskFrame:Hide()
        stepsFrame:Hide()
        stepsFrame.dealerImage:Hide()
        stepsFrame2:Hide()
        stepsFrame2.dealerImage2:Hide()
        buyInEditBox:SetText("")
        cashOutEditBox:SetText("")
    end
end)

cashDeskFrame.cashOutButton:SetScript("OnClick", function(self, button, down)
    if playerName == unitName1 then
        player1CashOut()
    elseif playerName == unitName2 then
        player2CashOut()
    elseif playerName == unitName3 then
        player3CashOut()
    elseif playerName == unitName4 then
        player4CashOut()
    elseif playerName == unitName5 then
        player5CashOut()
    else
        print("You are not sitting at the table.")
    end
end)

cashDeskFrame.buyInButton:SetScript("OnClick", function(self, button, down)
    if playerName == unitName1 then
        player1BuyIn()
    elseif playerName == unitName2 then
        player2BuyIn()
    elseif playerName == unitName3 then
        player3BuyIn()
    elseif playerName == unitName4 then
        player4BuyIn()
    elseif playerName == unitName5 then
        player5BuyIn()
    else
        print("You are not sitting at the table.")
    end
end)






dealtCardsFrameDealer.playerCardsButton:SetScript("OnClick", function(self, button, down)

    dealtCardsFramePlayer:Show()
    dealtCardsFramePlayer.playerCardsButton:Show()
    dealtCardsFramePlayer.dealerCardsButton:Show()
    if gameRunning == false then
        dealtCardsFramePlayer.notStartedYetText:Show()
    else
    end
    dealtCardsFrameDealer:Hide()

end)

dealtCardsFramePlayer.dealerCardsButton:SetScript("OnClick", function(self, button, down)

    dealtCardsFrameDealer:Show()
    dealtCardsFrameDealer.playerCardsButton:Show()
    dealtCardsFrameDealer.dealerCardsButton:Show()
    if gameRunning == false then
        dealtCardsFrameDealer.notStartedYetText:Show()
    else
    end
    dealtCardsFramePlayer:Hide()

end)

dealtCardsFramePlayer1H1.playerH2CardsButton:SetScript("OnClick", function(self, button, down)

    dealtCardsFramePlayer1H2:Show()
    dealtCardsFramePlayer1H2.playerH1CardsButton:Show()
    dealtCardsFramePlayer1H2.playerH2CardsButton:Show()
    dealtCardsFramePlayer1H2.dealerCardsButton:Show()
    dealtCardsFramePlayer1H1:Hide()
    dealtCardsFramePlayer1H1.playerH1CardsButton:Hide()
    dealtCardsFramePlayer1H1.playerH2CardsButton:Hide()
    dealtCardsFramePlayer1H1.dealerCardsButton:Hide()

end)

dealtCardsFramePlayer1H1.dealerCardsButton:SetScript("OnClick", function(self, button, down)

    dealtCardsFrameDealerSplit:Show()
    dealtCardsFrameDealerSplit.playerH1CardsButton:Show()
    dealtCardsFrameDealerSplit.playerH2CardsButton:Show()
    dealtCardsFrameDealerSplit.dealerCardsButton:Show()
    dealtCardsFramePlayer1H1:Hide()
    dealtCardsFramePlayer1H1.playerH1CardsButton:Hide()
    dealtCardsFramePlayer1H1.playerH2CardsButton:Hide()
    dealtCardsFramePlayer1H1.dealerCardsButton:Hide()

end)

dealtCardsFramePlayer1H2.playerH1CardsButton:SetScript("OnClick", function(self, button, down)

    dealtCardsFramePlayer1H1:Show()
    dealtCardsFramePlayer1H1.playerH1CardsButton:Show()
    dealtCardsFramePlayer1H1.playerH2CardsButton:Show()
    dealtCardsFramePlayer1H1.dealerCardsButton:Show()
    dealtCardsFramePlayer1H2:Hide()
    dealtCardsFramePlayer1H2.playerH1CardsButton:Hide()
    dealtCardsFramePlayer1H2.playerH2CardsButton:Hide()
    dealtCardsFramePlayer1H2.dealerCardsButton:Hide()

end)

dealtCardsFramePlayer1H2.dealerCardsButton:SetScript("OnClick", function(self, button, down)

    dealtCardsFrameDealerSplit:Show()
    dealtCardsFrameDealerSplit.playerH1CardsButton:Show()
    dealtCardsFrameDealerSplit.playerH2CardsButton:Show()
    dealtCardsFrameDealerSplit.dealerCardsButton:Show()
    dealtCardsFramePlayer1H2:Hide()
    dealtCardsFramePlayer1H2.playerH1CardsButton:Hide()
    dealtCardsFramePlayer1H2.playerH2CardsButton:Hide()
    dealtCardsFramePlayer1H2.dealerCardsButton:Hide()

end)

dealtCardsFrameDealerSplit.playerH1CardsButton:SetScript("OnClick", function(self, button, down)

    dealtCardsFramePlayer1H1:Show()
    dealtCardsFramePlayer1H1.playerH1CardsButton:Show()
    dealtCardsFramePlayer1H1.playerH2CardsButton:Show()
    dealtCardsFramePlayer1H1.dealerCardsButton:Show()
    dealtCardsFrameDealerSplit:Hide()
    dealtCardsFrameDealerSplit.playerH1CardsButton:Hide()
    dealtCardsFrameDealerSplit.playerH2CardsButton:Hide()
    dealtCardsFrameDealerSplit.dealerCardsButton:Hide()

end)

dealtCardsFrameDealerSplit.playerH2CardsButton:SetScript("OnClick", function(self, button, down)

    dealtCardsFramePlayer1H2:Show()
    dealtCardsFramePlayer1H2.playerH1CardsButton:Show()
    dealtCardsFramePlayer1H2.playerH2CardsButton:Show()
    dealtCardsFramePlayer1H2.dealerCardsButton:Show()
    dealtCardsFrameDealerSplit:Hide()
    dealtCardsFrameDealerSplit.playerH1CardsButton:Hide()
    dealtCardsFrameDealerSplit.playerH2CardsButton:Hide()
    dealtCardsFrameDealerSplit.dealerCardsButton:Hide()

end)





-- "Rules" button click
playerFrame.RulesButton:SetScript("OnClick", function()
    if rulesFrame:IsShown() then
        rulesFrame:Hide()
        rulesFrame.rulesText1:Hide()
        rulesFrame.rulesText2:Hide()
        rulesFrame.rulesText3:Hide()
        rulesFrame.rulesText4:Hide()
        rulesFrame.rulesText5:Hide()
        rulesFrame.rulesText6:Hide()
        rulesFrame.rulesText7:Hide()
        rulesFrame.rulesText8:Hide()
        rulesFrame.rulesText9:Hide()
        rulesFrame.rulesText10:Hide()
        rulesFrame.rulesText11:Hide()
        rulesFrame.HeadingText1:Hide()
        rulesFrame.HeadingText2:Hide()
        rulesFrame.HeadingText3:Hide()
        rulesFrame.HeadingText4:Hide()
        rulesFrame.HeadingText5:Hide()
        rulesFrame.HeadingText6:Hide()
        rulesFrame.HeadingText7:Hide()
        rulesFrame.HeadingText8:Hide()
        rulesFrame.HeadingText9:Hide()
    else
        rulesFrame:Show()
        rulesFrame.rulesText1:Show()
        rulesFrame.rulesText2:Show()
        rulesFrame.rulesText3:Show()
        rulesFrame.rulesText4:Show()
        rulesFrame.rulesText5:Show()
        rulesFrame.rulesText6:Show()
        rulesFrame.rulesText7:Show()
        rulesFrame.rulesText8:Show()
        rulesFrame.rulesText9:Show()
        rulesFrame.rulesText10:Show()
        rulesFrame.rulesText11:Show()
        rulesFrame.HeadingText1:Show()
        rulesFrame.HeadingText2:Show()
        rulesFrame.HeadingText3:Show()
        rulesFrame.HeadingText4:Show()
        rulesFrame.HeadingText5:Show()
        rulesFrame.HeadingText6:Show()
        rulesFrame.HeadingText7:Show()
        rulesFrame.HeadingText8:Show()
        rulesFrame.HeadingText9:Show()
    end
end)

-- "Payouts" button click
playerFrame.payoutsButton:SetScript("OnClick", function()
    if payoutsFrame:IsShown() then
        payoutsFrame:Hide()
        payoutsFrame.mainBetsTitle:Hide()
        payoutsFrame.sideBetsTitle:Hide()
        payoutsFrame.perfectPairsTitle:Hide()
        payoutsFrame.perfectPairsExplain:Hide()
        payoutsFrame.t213Title:Hide()
        payoutsFrame.t213Explain:Hide()
        payoutsFrame.t213Explain2:Hide()
        payoutsFrame.t213Explain3:Hide()
        payoutsFrame.t213Explain4:Hide()
        payoutsFrame.t213Explain5:Hide()
        payoutsFrame.t213Explain6:Hide()
        payoutsFrame.mainBetStandard:Hide()
        payoutsFrame.standardPayout:Hide()
        payoutsFrame.mainBetBlackjack:Hide()
        payoutsFrame.blackjackPayout:Hide()
        payoutsFrame.mixedPairPP:Hide()
        payoutsFrame.mixedPairPayout:Hide()
        payoutsFrame.colouredPairPP:Hide()
        payoutsFrame.colouredPairPayout:Hide()
        payoutsFrame.perfectPairPP:Hide()
        payoutsFrame.perfectPairPayout:Hide()
        payoutsFrame.flush213:Hide()
        payoutsFrame.flushPayout:Hide()
        payoutsFrame.straight213:Hide()
        payoutsFrame.straightPayout:Hide()
        payoutsFrame.threeOfAKind213:Hide()
        payoutsFrame.threeOfAKindPayout:Hide()
        payoutsFrame.straightFlush213:Hide()
        payoutsFrame.straightFlushPayout:Hide()
        payoutsFrame.suitedThreeOfAKind213:Hide()
        payoutsFrame.suitedThreeOfAKindPayout:Hide()
        payoutsFrame.card1image:Hide()
        payoutsFrame.card2image:Hide()
        payoutsFrame.card3image:Hide()
        payoutsFrame.card4image:Hide()
        payoutsFrame.card5image:Hide()
        payoutsFrame.card6image:Hide()
        payoutsFrame.card7image:Hide()
        payoutsFrame.card8image:Hide()
        payoutsFrame.card9image:Hide()
        payoutsFrame.card10image:Hide()
        payoutsFrame.card11image:Hide()
        payoutsFrame.card12image:Hide()
        payoutsFrame.card13image:Hide()
        payoutsFrame.card14image:Hide()
        payoutsFrame.card15image:Hide()
        payoutsFrame.card16image:Hide()
        payoutsFrame.card17image:Hide()
        payoutsFrame.card18image:Hide()
        payoutsFrame.card19image:Hide()
        payoutsFrame.card20image:Hide()
        payoutsFrame.card21image:Hide()
        payoutsFrame.card22image:Hide()
        payoutsFrame.card23image:Hide()
        payoutsFrame.card24image:Hide()
        payoutsFrame.card25image:Hide()
    else
        payoutsFrame:Show()
        payoutsFrame.mainBetsTitle:Show()
        payoutsFrame.sideBetsTitle:Show()
        payoutsFrame.perfectPairsTitle:Show()
        payoutsFrame.perfectPairsExplain:Show()
        payoutsFrame.t213Title:Show()
        payoutsFrame.t213Explain:Show()
        payoutsFrame.t213Explain2:Show()
        payoutsFrame.t213Explain3:Show()
        payoutsFrame.t213Explain4:Show()
        payoutsFrame.t213Explain5:Show()
        payoutsFrame.t213Explain6:Show()
        payoutsFrame.mainBetStandard:Show()
        payoutsFrame.standardPayout:Show()
        payoutsFrame.mainBetBlackjack:Show()
        payoutsFrame.blackjackPayout:Show()
        payoutsFrame.mixedPairPP:Show()
        payoutsFrame.mixedPairPayout:Show()
        payoutsFrame.colouredPairPP:Show()
        payoutsFrame.colouredPairPayout:Show()
        payoutsFrame.perfectPairPP:Show()
        payoutsFrame.perfectPairPayout:Show()
        payoutsFrame.flush213:Show()
        payoutsFrame.flushPayout:Show()
        payoutsFrame.straight213:Show()
        payoutsFrame.straightPayout:Show()
        payoutsFrame.threeOfAKind213:Show()
        payoutsFrame.threeOfAKindPayout:Show()
        payoutsFrame.straightFlush213:Show()
        payoutsFrame.straightFlushPayout:Show()
        payoutsFrame.suitedThreeOfAKind213:Show()
        payoutsFrame.suitedThreeOfAKindPayout:Show()
        payoutsFrame.card1image:Show()
        payoutsFrame.card2image:Show()
        payoutsFrame.card3image:Show()
        payoutsFrame.card4image:Show()
        payoutsFrame.card5image:Show()
        payoutsFrame.card6image:Show()
        payoutsFrame.card7image:Show()
        payoutsFrame.card8image:Show()
        payoutsFrame.card9image:Show()
        payoutsFrame.card10image:Show()
        payoutsFrame.card11image:Show()
        payoutsFrame.card12image:Show()
        payoutsFrame.card13image:Show()
        payoutsFrame.card14image:Show()
        payoutsFrame.card15image:Show()
        payoutsFrame.card16image:Show()
        payoutsFrame.card17image:Show()
        payoutsFrame.card18image:Show()
        payoutsFrame.card19image:Show()
        payoutsFrame.card20image:Show()
        payoutsFrame.card21image:Show()
        payoutsFrame.card22image:Show()
        payoutsFrame.card23image:Show()
        payoutsFrame.card24image:Show()
        payoutsFrame.card25image:Show()
    end
end)

-- "History" button click
playerFrame.historyButton:SetScript("OnClick", function()

    if historyFrame:IsShown() then
        historyFrame:Hide()
        historyFrame.totalWageredText:Hide()
        historyFrame.totalWonText:Hide()
        historyFrame.totalLostText:Hide()
        historyFrame.ProfitText:Hide()

        if playerName == unitName1 then
            historyFrame.player1totalWageredAmount:Hide()
            historyFrame.player1totalWonAmount:Hide()
            historyFrame.player1totalLostAmount:Hide()
            historyFrame.player1ProfitAmount:Hide()
        elseif playerName == unitName2 then
            historyFrame.player2totalWageredAmount:Hide()
            historyFrame.player2totalWonAmount:Hide()
            historyFrame.player2totalLostAmount:Hide()
            historyFrame.player2ProfitAmount:Hide()
        end

    else
        historyFrame:Show()
        historyFrame.totalWageredText:Show()
        historyFrame.totalWonText:Show()
        historyFrame.totalLostText:Show()
        historyFrame.ProfitText:Show()

        if playerName == unitName1 then
            historyFrame.player1totalWageredAmount:Show()
            historyFrame.player1totalWonAmount:Show()
            historyFrame.player1totalLostAmount:Show()
            historyFrame.player1ProfitAmount:Show()
        elseif playerName == unitName2 then
            historyFrame.player2totalWageredAmount:Show()
            historyFrame.player2totalWonAmount:Show()
            historyFrame.player2totalLostAmount:Show()
            historyFrame.player2ProfitAmount:Show()
        end

    end
end)

-- "Rebet" button click
playerFrame.rebetButton:SetScript("OnClick", function()

    if rebetFrame:IsShown() then
        rebetFrame:Hide()
        rebetFrame.preloadMainBetText:Hide()
        rebetFrame.preloadPPBetText:Hide()
        rebetFrame.preload213BetText:Hide()

        if playerName == unitName1 then
            player1PreloadEditBoxMainBet:Hide()
            player1PreloadEditBoxPPBet:Hide()
            player1PreloadEditBox213Bet:Hide()
            player1PreloadBetButton:Hide()
        elseif playerName == unitName2 then
            player2PreloadEditBoxMainBet:Hide()
            player2PreloadEditBoxPPBet:Hide()
            player2PreloadEditBox213Bet:Hide()
            player2PreloadBetButton:Hide()
        end

    else
        rebetFrame:Show()
        rebetFrame.preloadMainBetText:Show()
        rebetFrame.preloadPPBetText:Show()
        rebetFrame.preload213BetText:Show()

        if playerName == unitName1 then
            player1PreloadEditBoxMainBet:Show()
            player1PreloadEditBoxPPBet:Show()
            player1PreloadEditBox213Bet:Show()
            player1PreloadBetButton:Show()
        elseif playerName == unitName2 then
            player2PreloadEditBoxMainBet:Show()
            player2PreloadEditBoxPPBet:Show()
            player2PreloadEditBox213Bet:Show()
            player2PreloadBetButton:Show()
        end

    end
end)

playerFrame.cardsButton:SetScript("OnClick", function()

    if dealtCardsFramePlayer:IsShown() then
        dealtCardsFramePlayer:Hide()
        dealtCardsFramePlayer.playerCardsButton:Hide()
        dealtCardsFramePlayer.dealerCardsButton:Hide()
    else
        if player1SplitToggle == true then
            dealtCardsFramePlayer1H1:Show()
            dealtCardsFramePlayer1H1.playerH1CardsButton:Show()
            dealtCardsFramePlayer1H1.playerH2CardsButton:Show()
            dealtCardsFramePlayer1H1.dealerCardsButton:Show()
        else
            dealtCardsFramePlayer:Show()
            dealtCardsFramePlayer.playerCardsButton:Show()
            dealtCardsFramePlayer.dealerCardsButton:Show()
            if gameRunning == false then
                dealtCardsFramePlayer.notStartedYetText:Show()
            else
            end
        end
    end

    if dealtCardsFrameDealer:IsShown() then
        dealtCardsFrameDealer:Hide()
        dealtCardsFrameDealer.playerCardsButton:Hide()
        dealtCardsFrameDealer.dealerCardsButton:Hide()
        dealtCardsFramePlayer:Hide()
        dealtCardsFramePlayer.playerCardsButton:Hide()
        dealtCardsFramePlayer.dealerCardsButton:Hide()
    end
end)

playerFrame.chatLogButton:SetScript("OnClick", function()

    if chatWindowFrame:IsShown() then
        chatWindowFrame:Hide()
    else
        chatWindowFrame:Show()
    end

end)







-- Slash command handler for the player
SlashCmdList["BJ"] = function(msg)
    if msg == "join" then
        initialFrame:Show()
        -- Handle the "/blackjack join" command
    else
        print("Invalid command. Usage: /bj join")
    end
end

-- Register the slash command
SLASH_BJ1 = "/bj"