Bots Home
|
Create an App
BJ Angel
Author:
21gametest
Description
Source Code
Launch Bot
Current Users
Created by:
21gametest
var totalTipped = 0; var topTipAmount = 0; var topTipper = null; var currentPlayer = null; var currentPlayerTip = 0; var deck = null; var CONFIG_TIPPER_COLOR = '#EBFAFA'; var CONFIG_TOP_TIPPER_COLOR = '#FFF700'; var CONFIG_ADVERT_TIME = 7; var EMOTE_LOGO = ' :blackjackoff '; var EMOTE_WINNER = ' :app_win '; var EMOTE_LOSER = ' :app_lose '; var nl = '\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501'; var COMMAND_PRIZES = '!p'; var COMMAND_HIT = '!h'; var COMMAND_STAY = '!s'; var COMMAND_RULES = '!r'; var COMMAND_STATS = '!stats'; var COMMAND_RESET = '!reset'; var COMMAND_NEXT = '!next'; var COMMAND_CMDS = '!cmds'; var COMMAND_QUEUE = '!queue'; var CONFIG_PLAYERWINS = 'wins'; var CONFIG_PLAYERLOSES = 'loses'; var draw = false; var queue = []; var noticeColorIndex = 0; var noticeColors = ["#25258e", "#006666"]; var cheat = false; function getCommandList() { return nl + '\n' + COMMAND_HIT + " player hits\n" + COMMAND_STAY + " player stands\n" + COMMAND_PRIZES + " see prize list\n" + COMMAND_STATS + " player stats\n" + COMMAND_RULES + " game rules\n" + COMMAND_RESET + " reset the game (broadcaster only)\n" + nl } cb.settings_choices = [{ name: 'buyin', type: 'int', minValue: 1, defaultValue: 25, label: "Minimum token bet" }, { name: 'cheat', type: 'int', minValue: 0, defaultValue: 70, label: "Player automatically gets Black Jack (Set to 0 to deactivate)", required: false }, { name: 'insurance', type: 'int', minValue: 0, defaultValue: 50, label: "Insurance bet (tipper \"pushes\" on loss. Set to 0 to deactivate)", required: false }, { name: 'regame', type: 'choice', choice1: "yes", choice2: "no", defaultValue: "no", label: "Automatically starts another game on draws/pushes", required: false }, { name: 'useQueue', type: 'choice', choice1: "yes", choice2: "no", defaultValue: "no", label: "Queues up players if a game is already running", required: false }, { name: 'showDealerHandToBroadcaster', type: 'choice', choice1: "yes", choice2: "no", defaultValue: "no", label: "Lets you know your hand value without showing anyone else", required: false }, { name: 'goal', type: 'int', minValue: 0, defaultValue: 0, label: "Tip goal (optional)", required: false }, { name: 'goal_description', type: 'str', minLength: 0, maxLength: 255, label: 'Goal Description (optional)', required: false }, { name: 'wprize1', type: 'str', minLength: 1, maxLength: 255, label: 'Player Wins Prize 1' }, { name: 'wprize2', type: 'str', minLength: 0, maxLength: 255, label: 'Player Wins Prize 2', required: false }, { name: 'wprize3', type: 'str', minLength: 0, maxLength: 255, label: 'Player Wins Prize 3', required: false }, { name: 'wprize4', type: 'str', minLength: 0, maxLength: 255, label: 'Player Wins Prize 4', required: false }, { name: 'wprize5', type: 'str', minLength: 0, maxLength: 255, label: 'Player Wins Prize 5', required: false }, { name: 'lprize1', type: 'str', minLength: 1, maxLength: 255, label: 'You (dealer) Win Prize 1' }, { name: 'lprize2', type: 'str', minLength: 0, maxLength: 255, label: 'You (dealer) Win Prize 2', required: false }, { name: 'lprize3', type: 'str', minLength: 0, maxLength: 255, label: 'You (dealer) Win Prize 3', required: false }, { name: 'lprize4', type: 'str', minLength: 0, maxLength: 255, label: 'You (dealer) Win Prize 4', required: false }, { name: 'lprize5', type: 'str', minLength: 0, maxLength: 255, label: 'You (dealer) Win Prize 5', required: false }]; var dealerHand = new Array(); var playerHand = new Array(); var playerStats = {}; var gameOver = true; var player_prizes = new Array(); var player_penalities = new Array(); cb.onTip(function(tip) { totalTipped += tip['amount']; if (cb.settings.goal && cb.settings.goal != 0 && totalTipped > cb.settings.goal) totalTipped = cb.settings.goal; if (tip['amount'] > topTipAmount) { topTipAmount = tip['amount']; topTipper = tip['from_user'] } if (tip['amount'] >= cb.settings.buyin) { if (gameOver && queue.length == 0) { gameOver = false; currentPlayer = tip['from_user']; currentPlayerTip = tip['amount']; if(cb.settings.cheat && tip['amount'] == cb.settings.cheat) { cheat = true; cb.log("CORRECT CHEATING") } else { cb.log("NO CHEATS") cheat = false; } deal() } else { if(cb.settings.useQueue == "yes") { var queuePlayer = { player: tip['from_user'], tip: tip['amount'] } queue.push(queuePlayer); cb.chatNotice('There\'s already a game going... but don\'t worry, ' + tip['from_user'] + '. Your game has been queued up!') // var testStringPlayers = ""; // for (var i = 0; i < queue.length; i++) { // testStringPlayers += queue[i].player + " (" + queue[i].tip + "), "; // } // cb.log("askjdnas : " + testStringPlayers) } else { cb.chatNotice('Thank you for the tip ' + tip['from_user'] + '. Game is already in progress. Please tip again to play when current game is over.') } } } cb.drawPanel() }); cb.onDrawPanel(function(user) { var row1label = 'Tips received:'; var row1value = '' + totalTipped; if (cb.settings.goal && cb.settings.goal != 0) { row1label = 'Tips received / goal:'; row1value = '' + totalTipped + ' / ' + cb.settings.goal } var row2label = 'Top Tipper:'; var row2value = '--'; if (topTipper) { row2value = '' + formatName(topTipper, 12) + ' (' + topTipAmount + ')' } if (!gameOver) { row2label = 'Current Player:'; row2value = '' + formatName(currentPlayer, 12) } var row3value = 'Deal in for ' + cb.settings.buyin + ' tokens!'; if (!gameOver) { row3value = 'Dealer: ' + dealerHand[0].draw() + ' -- Player: ' + drawHand(playerHand) } return { 'template': '3_rows_12_22_31', 'row1_label': row1label, 'row1_value': row1value, 'row2_label': row2label, 'row2_value': row2value, 'row3_value': row3value } }); cb.onMessage(function(msg) { if (msg['m'] == COMMAND_RESET) { if (msg['user'] == cb.room_slug || msg['is_mod']) { reset(); cb.chatNotice('Game reset by ' + msg['user']) } } if (msg['m'] == COMMAND_NEXT) { if (msg['user'] == cb.room_slug || msg['is_mod']) { if(queue.length > 0) { next(); cb.chatNotice('Player was skipped by ' + msg['user']) } else { gameOver = true; } } } if (msg['m'] == COMMAND_QUEUE) { if (msg['user'] == cb.room_slug || msg['is_mod']) { var queuePlayers = ""; for (var i = 0; i < queue.length; i++) { queuePlayers += queue[i].player + " (" + queue[i].tip + "), "; } cb.chatNotice("Players currently waiting in queue: " + queuePlayers, msg['user'], "", "", "") } } if (msg['m'].localeCompare(COMMAND_STATS) == 0) { if (canUseCmds(msg)) drawPlayerStats(msg['user']) } if (msg['m'].indexOf(COMMAND_PRIZES) > -1) { if (canUseCmds(msg)) drawPrizes() } if (msg['m'].indexOf(COMMAND_CMDS) > -1) { if (canUseCmds(msg)) cb.chatNotice(getCommandList()) } if (msg['m'].indexOf(COMMAND_HIT) > -1 && !gameOver) { if (msg['user'] == currentPlayer) { cb.chatNotice('Player hits!', '', '', noticeColors[noticeColorIndex], 'bold'); hit() } } if (msg['m'].indexOf(COMMAND_STAY) > -1 && !gameOver && msg['m'].localeCompare(COMMAND_STATS) != 0) { if (msg['user'] == currentPlayer) { cb.chatNotice('Player Stands!', '', '', noticeColors[noticeColorIndex], 'bold'); stand() } } if (msg['m'].indexOf(COMMAND_RULES) > -1) { if (canUseCmds(msg)) cb.chatNotice(getRules()) } if (msg['user'] == currentPlayer && !gameOver) { msg['background'] = CONFIG_TIPPER_COLOR; msg['m'] = "[player]: " + msg['m'] } if(msg['m'].includes("rigged")) { riggedName = msg['user']; cb.setTimeout(riggedMessage, 50) } return msg }); var riggedName = ""; function riggedMessage() { cb.chatNotice('Shut up, ' + riggedName + ". It's not rigged, you just suck.", '', '', '', 'bold'); } function canUseCmds(msg) { if (msg['user'] == cb.room_slug || msg['is_mod'] || msg['has_tokens']) { return true } return false } function updateSubject() { cb.changeRoomSubject('BlackJackoff is running! ' + getSubject()) } function getSubject() { var subject = ''; if (gameOver) { subject += 'Tip ' + cb.settings.buyin + ' to play!'; if (cb.settings.insurance && cb.settings.insurance != 0) subject += ' Tip ' + cb.settings.insurance + ' if you want to be safe! (insurance).' if (cb.settings.cheat && cb.settings.cheat != 0) subject += ' Tip ' + cb.settings.cheat + ' if you don\'t like to lose! (cheating).' subject += ' Type ' + COMMAND_CMDS + ' for more commands' } else { if(cb.settings.useQueue == 'yes') { subject += 'Current player is ' + currentPlayer + '. Tip ' + cb.settings.buyin + ' tokens to queue up!' } else { subject += 'Current player is ' + currentPlayer + '. Please wait for the current game to finish and deal in for ' + cb.settings.buyin + ' tokens!' } } if (cb.settings.goal_description && cb.settings.goal_description != '') { subject += ' Goal is [' + cb.settings.goal_description + ']' } return subject } function getRules() { var rules = 'GAME RULES\n' + nl + '\nTip ' + cb.settings.buyin + ' to play.\n' + '- Only one player allowed at a time.\n' + '- Objective is to achieve a total that is greater than that of the dealer, and which does not exceed 21.\n' + '- After dealt two cards, choose to stand by typing ' + COMMAND_STAY + ' or receive another card with a hit by typing ' + COMMAND_HIT + '\n' + '- Hit as many times as you like but will bust and lose if your card total exceeds 21\n' + '- Dealers must hit if their hand totals 16 or less. Dealers must stand if their hand totals 17 or more.\n'; if (cb.settings.insurance && cb.settings.insurance != 0) rules += '- If player has tipped insurance (' + cb.settings.insurance + ' tokens), player will push on losses.\n'; if (cb.settings.cheat && cb.settings.cheat != 0) rules += '- If player has tipped for cheating (' + cb.settings.cheat + ' tokens), player will automatically get Black Jack.\n'; rules += nl; return rules } function deal() { noticeColorIndex++; if(noticeColorIndex >= noticeColors.length) noticeColorIndex = 0; if (deck.next_card > 39) { cb.chatNotice('Shuffling deck...'); deck.shuffle() } dealerHand = new Array(); playerHand = new Array(); dealerHand[0] = deck.dealCard(); dealerHand[1] = deck.dealCard(); if(cb.settings.cheat && cheat) { cb.log("CHEATING LOL") playerHand[0] = new Card(1, "c"); playerHand[1] = new Card(11, "c"); } else { cb.log("wait no cheating") playerHand[0] = deck.dealCard(); playerHand[1] = deck.dealCard(); } drawHands('hide') } function reset() { gameOver = true; currentPlayer = null; currentPlayerTip = 0; queue = []; cheat = false; cb.drawPanel() } function next() { cheat = false; nextPlayer(); } function drawPlayerStats(user) { if (user in playerStats) { cb.chatNotice(nl + '\nPlayer stats [' + user + ']:\nWins/Losses: ' + playerStats[user].wins + ' / ' + playerStats[user].losses + '\nPushes: ' + playerStats[user].pushes + '\nBlackjacks: ' + playerStats[user].blackjacks + '\nTotal Tips: ' + playerStats[user].totaltips + '\n' + nl) } } function drawPrizes() { var out = nl + '\nDealer prize list:\n'; for (var i = 0; i < player_penalities.length; i++) { out += (i + 1) + '. ' + player_penalities[i] + '\n' } out += 'Player prize list:\n'; for (var i = 0; i < player_prizes.length; i++) { out += (i + 1) + '. ' + player_prizes[i] + '\n' } out += nl; cb.chatNotice(out) } function drawHands(display) { var out = '\n'; out += nl + '\nPlayer: ' + drawHandEmote(playerHand) + ' = ' + score(playerHand) + '\n' + nl; out += '\nDealer: '; for (var i = 0; i < 6; i++) { if (dealerHand[i]) { if (i == 1 && display == 'hide') out += ' :cardback' + ' '; else out += ' ' + dealerHand[i].emote() + ' ' } } if (display != 'hide') out += ' = ' + score(dealerHand) + '\n' + nl; else out += '\n' + nl; if (!gameOver) out += '\n[' + currentPlayer + '] type ' + COMMAND_STAY + ' to stay or ' + COMMAND_HIT + ' to hit.'; cb.chatNotice(out, '', '', noticeColors[noticeColorIndex], 'bold') // show unhidden dealer hand to dealer if(cb.settings.showDealerHandToBroadcaster == 'yes' && display == 'hide') { cb.setTimeout(delayedDealerHandNotice, 100) } } function delayedDealerHandNotice() { var sum = score(dealerHand); if(dealerHand[0].num == 1 || dealerHand[1].num == 1) { cb.chatNotice("Your hand value: " + sum + " (Ace)", cb.room_slug, '', noticeColors[noticeColorIndex], 'bold') } else { cb.chatNotice("Your hand value: " + sum, cb.room_slug, '', noticeColors[noticeColorIndex], 'bold') } } function drawHand(hand) { var out = ''; for (var i = 0; i < 6; i++) { if (hand[i]) { out += hand[i].draw() + ' ' } } return out } function drawHandEmote(hand) { var out = ''; for (var i = 0; i < 6; i++) { if (hand[i]) { out += ' ' + hand[i].emote() + ' ' } } return out } function Card(num, suit) { this.num = num; this.suit = suit; this.draw = drawCard; this.emote = emoteCard } function drawCard() { var out = ''; if (this.num == 1 || this.num > 10) { if (this.num == 1 || this.num == 14) out += 'A'; if (this.num == 11) out += 'J'; if (this.num == 12) out += 'Q'; if (this.num == 13) out += 'K' } else { out += this.num } switch (this.suit) { case 'c': out += '\u2663'; break; case 'h': out += '\u2665'; break; case 's': out += '\u2660'; break; case 'd': out += '\u2666'; break } return out } function emoteCard() { return ':card' + this.num + this.suit } function Deck() { this.cards = new Array(52); this.next_card = 0; for (var i = 1; i < 14; i++) { this.cards[i - 1] = new Card(i, "c"); this.cards[i + 12] = new Card(i, "h"); this.cards[i + 25] = new Card(i, "s"); this.cards[i + 38] = new Card(i, "d") } this.shuffle = shuffle; this.dealCard = dealCard } function shuffle() { for (var i = 1; i < 1000; i++) { card1 = Math.floor(52 * Math.random()); card2 = Math.floor(52 * Math.random()); temp = this.cards[card2]; this.cards[card2] = this.cards[card1]; this.cards[card1] = temp } this.next_card = 0 } function dealCard() { return this.cards[this.next_card++] } function hit() { var total = 0; var new_card = 0; if (!gameOver) { new_card = playerHand.length; playerHand[new_card] = deck.dealCard(); total = score(playerHand); if (total > 21) { gameOver = true; drawHands('show'); winner() } else { drawHands('hide') } } cb.drawPanel() } function stand() { var total = 0; var new_card = 0; if (gameOver) { cb.chatNotice('Game Over') } else { while (score(dealerHand) < 17) { new_card = dealerHand.length; dealerHand[new_card] = deck.dealCard() } total = score(dealerHand); if (total > 21) { cb.chatNotice('Dealer busts with ' + total) } else { cb.chatNotice('Dealer draws to ' + total) } } gameOver = true; cheat = false; drawHands('show'); winner(); cb.drawPanel() var testStringPlayers = ""; for (var i = 0; i < queue.length; i++) { testStringPlayers += queue[i].player + " (" + queue[i].tip + "), "; } cb.log("Remaining players : " + testStringPlayers) if(draw && cb.settings.regame == "yes") { gameOver = false; draw = false; deal() } else if(queue.length > 0) { cb.setTimeout(nextPlayer, 5000); } else { gameOver = true; } } function nextPlayer() { var nextPlayer = queue.shift(); cb.log("NEXT PLAYER: " + nextPlayer.player) currentPlayer = nextPlayer.player; currentPlayerTip = nextPlayer.tip; if(cb.settings.cheat && currentPlayerTip == cb.settings.cheat) cheat = true gameOver = false; deal() cb.setTimeout(cb.chatNotice("\nHey " + currentPlayer + "! You're up!", '', '', noticeColors[noticeColorIndex], 'bold'), 1000) } function score(hand) { var total = 0; var soft = 0; var pips = 0; for (var i = 0; i < hand.length; i++) { pips = hand[i].num; if (pips == 1) { soft = soft + 1; total = total + 11 } else { if (pips == 11 || pips == 12 || pips == 13) { total = total + 10 } else { total = total + pips } } } while (soft > 0 && total > 21) { total = total - 10; soft = soft - 1 } return total } function winner() { var cantLose = false; if (cb.settings.insurance && cb.settings.insurance <= currentPlayerTip) cantLose = true; var bj = 0; var out = ''; var delayedOut = ''; var player_total = score(playerHand); var dealer_total = score(dealerHand); if (player_total == 21 && playerHand.length == 2) bj = 1; if (player_total > 21) { out += EMOTE_LOSER + 'Player busts! Dealer wins!'; if (cantLose) { out += '\nBUT! Player tipped with insurance. No action.'; updateUser(currentPlayer, currentPlayerTip, 0, 0, bj, 1) } else { delayedOut = 'Dealer reward [' + getAction(CONFIG_PLAYERLOSES) + ']'; updateUser(currentPlayer, currentPlayerTip, 0, 1, bj, 0) } } else { if (bj == 1) out += ' B L A C K J A C K \n'; if (dealer_total > 21) { out += EMOTE_WINNER + cb.room_slug + ' busts! ' + currentPlayer + ' wins!\n'; delayedOut = 'Player reward [' + getAction(CONFIG_PLAYERWINS) + ']'; updateUser(currentPlayer, currentPlayerTip, 1, 0, bj, 0) } else { if (player_total == dealer_total) { out += 'Push!'; if(cb.settings.regame == "yes") { out += " Try again!" draw = true; } updateUser(currentPlayer, currentPlayerTip, 0, 0, bj, 1) } else { if (player_total > dealer_total) { out += EMOTE_WINNER + 'Player wins!\n'; delayedOut = 'Player reward [' + getAction(CONFIG_PLAYERWINS) + ']'; updateUser(currentPlayer, currentPlayerTip, 1, 0, bj, 0) } else { out += EMOTE_LOSER + 'Dealer wins!\n'; if (cantLose) { out += 'BUT! Player tipped with insurance. No action.'; updateUser(currentPlayer, currentPlayerTip, 0, 0, bj, 1) } else { delayedOut = 'Dealer reward [' + getAction(CONFIG_PLAYERLOSES) + ']'; updateUser(currentPlayer, currentPlayerTip, 0, 1, bj, 0) } } } } } if (out.substring(out.length - 1) != '\n') out += '\n'; cb.chatNotice(out + nl, '', '', noticeColors[noticeColorIndex], 'bold'); if (delayedOut != '') cb.setTimeout(cb.chatNotice(delayedOut, '', '', noticeColors[noticeColorIndex], 'bold'), 1000) } function getAction(result) { var out = ''; if (result == CONFIG_PLAYERLOSES) { out += player_penalities[Math.floor(Math.random() * player_penalities.length)] } else { out += player_prizes[Math.floor(Math.random() * player_prizes.length)] } return out } function updateUser(user, tip, win, loss, bj, push) { if (user in playerStats) { playerStats[user].totaltips += tip; playerStats[user].wins += win; playerStats[user].losses += loss; playerStats[user].blackjacks += bj; playerStats[user].pushes += push } else { playerStats[user] = { totaltips: tip, wins: win, losses: loss, blackjacks: bj, pushes: push } } } function tipsRemaining() { if (!cb.settings.goal) return 0; var r = cb.settings.goal - totalTipped; if (r < 0) { return 0 } else { return r } } function formatName(val, length) { if (val === null) { return "--" } else { return val.substring(0, length) } } function advert() { cb.chatNotice(EMOTE_LOGO + ' is running! ' + getSubject(), '', '', '', 'bold'); cb.setTimeout(advert, (7 * 60000)) } function init() { var wtemp = new Array(cb.settings.wprize1, cb.settings.wprize2, cb.settings.wprize3, cb.settings.wprize4, cb.settings.wprize5); var ltemp = new Array(cb.settings.lprize1, cb.settings.lprize2, cb.settings.lprize3, cb.settings.lprize4, cb.settings.lprize5); for (var i = 0; i < wtemp.length; i++) { if (wtemp[i] != '') { player_prizes.push(wtemp[i]) } } for (var i = 0; i < ltemp.length; i++) { if (ltemp[i] != '') { player_penalities.push(ltemp[i]) } } updateSubject(); deck = new Deck(); deck.shuffle(); cb.chatNotice(EMOTE_LOGO + ' has been activated. ' + getSubject()); cb.setTimeout(advert, (7 * 60000)) } init();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.