Skip to main content

Slot Machine

This command runs the slot machine game.

caution

This command assumes that you have an existing currency system set up to provide credits to users.

Triggerā€‹

Type: Command
Trigger: slotmachine

Usageā€‹

  • slotmachine <amount> - Runs the slot machine, betting amount credits.

Configurationā€‹

  • šŸ“Œ $dbName
    Database entry name that stores the user's credits.

  • $gameName
    What the game should be called.

  • $user
    What the player should be called.

  • $spinName
    What to show to users when the slot machine is currently spinning.

  • $lose
    Text to show users when they lose.

  • $win
    Text to show users when they win.

  • $profit
    What 'profit' should be called.

  • $currency
    Name of the currency.

  • $payOut
    What 'pay out' should be called.

  • $youHave
    What 'you have' should be called.

  • $helper
    Helper text title.

  • $helpText
    Help text for the command.

  • $notEnough
    Message to show to users when they do not have sufficient credits.

  • $betBelow1
    Message to show to users when they bet less than one credit.

  • šŸ“Œ $bettingChannel
    Channel ID where users can play the game.

  • $minMax
    Whether there should be a minimum/maximum amount users can bet (see the options below).

  • $minBet
    Minimum amount people can bet.

  • $maxBet
    Maximum amount people can bet.

  • $outOfRange
    Message to show to users when they bet an amount that is less than the minimum / greater than the maximum.

  • šŸ“Œ $channels
    A list of arbitrary channel IDs in your server to prevent the game from lagging.

Codeā€‹

{{/*
Slot machine game that integrates with an existing currency system.
See <https://yagpdb-cc.github.io/fun/slot-machine> for more information.

Author: Pedro Pessoa <https://github.com/Pedro-Pessoa>
*/}}

{{/* Configurable values */}}
{{ $dbName := "CREDITS" }}
{{ $gameName := "Slot Machine" }}
{{ $user := "User" }}
{{ $spinName := "SPINNING" }}
{{ $lose := "You lost :(" }}
{{ $win := "YOU WON!" }}
{{ $profit := "Profit" }}
{{ $currency := "Credits" }}
{{ $payOut := "Pay Out" }}
{{ $youHave := "you have " }}
{{ $helper := "Usage" }}
{{ $helpText := "-bet <amount>\nFor example: **-bet 10**\nThis way you would be betting 10 credits." }}
{{ $notEnough := "Insuficient credits" }}
{{ $betBelow1 := "You have to bet 1 credit at least" }}
{{ $bettingChannel := 640790412986023949 }}
{{ $minMax := true }}
{{ $minBet := 100 }}
{{ $maxBet := 200 }}
{{ $outOfRange := "You have to bet between 100 and 200!" }}
{{ $channels := cslice
650881854722932746
663411278139883520
641092472423972864
642429118633213953
678827664135553044
}}
{{/* End of configurable values */}}

{{ $template := "**-------------------\n %s | %s | %s |\n-------------------\n- %s -**" }}
{{ $header := printf "%s | %s: %s" $gameName $user .User.Username }}
{{ $slotEmoji := "<a:slotmoney:1058566805427322900>" }}
{{ $g := 65280 }}{{ $y := 16776960 }}{{ $r := 16711680 }}{{ $b := 65534 }}
{{ $emojis := cslice "šŸ„‡" "šŸ„‡" "šŸ„‡" "šŸ„‡" "šŸ„‡" "šŸ„‡" "šŸ„‡"
"šŸ’Ž" "šŸ’Ž" "šŸ’Ž" "šŸ’Ž" "šŸ’Ž" "šŸ’Ž"
"šŸ’Æ" "šŸ’Æ" "šŸ’Æ" "šŸ’Æ"
"šŸ’µ" "šŸ’µ" "šŸ’µ"
"šŸ’°" "šŸ’°" }}
{{ $choosen := index (shuffle $emojis) 0 }}
{{ $choosen2 := index (shuffle $emojis) 0 }}
{{ $choosen3 := index (shuffle $emojis) 0 }}
{{ $bal := toInt (dbGet .User.ID $dbName).Value }}
{{ $embed := sdict
"color" $g
"fields" (cslice (sdict
"name" $header
"value" (printf $template $slotEmoji $slotEmoji $slotEmoji $spinName)
"inline" false
)) }}
{{ if and (not .ExecData) (eq .Channel.ID $bettingChannel) (not (dbGet .User.ID "block_slot_123456")) }}
{{ if .CmdArgs }}
{{ $bet := toInt (index .CmdArgs 0) }}
{{ $ok := true }}
{{ if $minMax }}
{{ if or (lt $bet $minBet) (gt $bet $maxBet) }}
{{ $ok = false }}
{{ $outOfRange }}
{{ end }}
{{ end }}
{{ if $ok }}
{{ if ge $bet 1 }}
{{ if ge $bal $bet }}
{{ dbSet .User.ID "block_slot_123456" true }}
{{ $silent := dbIncr .User.ID $dbName (mult -1 $bet) }}
{{ $id := sendMessageRetID nil (cembed $embed) }}
{{ execCC .CCID (index (shuffle $channels) 0) 2 (sdict
"depth" 1
"id" $id
"bet" $bet
) }}
{{ else }} {{ $notEnough }}, {{ .User.Mention }}! {{ end }}
{{ else }} {{ $betBelow1 }}, {{ .User.Mention }}! {{ end }}
{{ end }}
{{ else }}
{{ $embedHelp := cembed
"title" $gameName
"fields" (cslice
(sdict
"name" $payOut
"value" "**šŸ„‡šŸ„‡ā“ - 1x\nšŸ’ŽšŸ’Žā“ - 2x\nšŸ’ÆšŸ’Æā“ - 3x\nšŸ„‡šŸ„‡šŸ„‡ - 3x\nšŸ’ŽšŸ’ŽšŸ’Ž - 4x\nšŸ’µšŸ’µā“ - 4x\nšŸ’ÆšŸ’ÆšŸ’Æ - 5x\nšŸ’°šŸ’°ā“ - 5x\nšŸ’µšŸ’µšŸ’µ - 10x\nšŸ’°šŸ’°šŸ’° - 15x**"
"inline" false
)
(sdict "name" $helper "value" $helpText "inline" false)
)
"color" $y
}}
{{ sendMessage nil $embedHelp }}
{{ end }}
{{ end }}

{{ with .ExecData }}
{{ if eq .depth 1 }}
{{ $embed.Set "fields" (cslice (sdict
"name" $header
"value" (printf $template $choosen $slotEmoji $slotEmoji $spinName)
"inline" false
)) }}
{{ editMessage $bettingChannel .id (cembed $embed) }}
{{ execCC $.CCID (index (shuffle $channels) 0) 1 (sdict
"depth" 2
"id" .id
"choosen" $choosen
"bet" .bet
) }}
{{ else if eq .depth 2 }}
{{ $embed.Set "fields" (cslice
(sdict
"name" $header
"value" (printf $template .choosen $choosen2 $slotEmoji $spinName)
"inline" false
)
) }}
{{ editMessage $bettingChannel .id (cembed $embed) }}
{{ execCC $.CCID (index (shuffle $channels) 0) 1 (sdict
"depth" 3
"id" .id
"choosen" .choosen
"choosen2" $choosen2
"bet" .bet
) }}
{{ else if eq .depth 3 }}
{{ $announce := $lose }}
{{ $multiplier := 1 }}
{{ if (and (eq .choosen "šŸ’Ž") (eq .choosen2 "šŸ’Ž") (ne $choosen3 "šŸ’Ž")) }}
{{ $multiplier = 2 }}
{{ else if or (and (eq .choosen "šŸ„‡") (eq .choosen2 "šŸ„‡") (eq $choosen3 "šŸ„‡")) (and (eq .choosen "šŸ’Æ") (eq .choosen2 "šŸ’Æ") (ne $choosen3 "šŸ’Æ")) }}
{{ $multiplier = 3 }}
{{ else if or (and (eq .choosen "šŸ’Ž") (eq .choosen2 "šŸ’Ž") (eq $choosen3 "šŸ’Ž")) (and (eq .choosen "šŸ’µ") (eq .choosen2 "šŸ’µ") (ne $choosen3 "šŸ’µ")) }}
{{ $multiplier = 4 }}
{{ else if or (and (eq .choosen "šŸ’Æ") (eq .choosen2 "šŸ’Æ") (eq $choosen3 "šŸ’Æ")) (and (eq .choosen "šŸ’°") (eq .choosen2 "šŸ’°") (ne $choosen3 "šŸ’°")) }}
{{ $multiplier = 5 }}
{{ else if and (eq .choosen "šŸ’µ") (eq .choosen2 "šŸ’µ") (eq $choosen3 "šŸ’µ") }}
{{ $multiplier = 10 }}
{{ else if and (eq .choosen "šŸ’°") (eq .choosen2 "šŸ’°") (eq $choosen3 "šŸ’°") }}
{{ $multiplier = 15 }}
{{ end }}
{{ $pag1 := sdict "name" $profit "value" (joinStr "" "**-" .bet " " (lower $currency) "**") "inline" true }}
{{ $c := $r }}
{{ if eq .choosen .choosen2 }}
{{ $c = $b }}
{{ $announce = $win }}
{{ $pag1 = (sdict "name" $profit "value" (joinStr "" "**" (mult .bet $multiplier) " " (lower $currency) "**") "inline" true) }}
{{ $silent2 := dbIncr $.User.ID $dbName (mult .bet $multiplier) }}
{{ end }}
{{ $embed.Set "fields" (cslice
(sdict
"name" $header
"value" (printf $template .choosen .choosen2 $choosen3 $announce)
"inline" false
)
) }}
{{ $embed.Set "color" $c }}
{{ $embed.Set "fields" ($embed.fields.Append $pag1) }}
{{ $saldo := toInt (dbGet $.User.ID $dbName).Value }}
{{ $pag2 := sdict
"name" $currency
"value" (joinStr "" $youHave " **" $saldo " " (lower $currency) "**")
"inline" true
}}
{{ $embed.Set "fields" ($embed.fields.Append $pag2) }}
{{ editMessage $bettingChannel .id (cembed $embed) }}
{{ dbDel $.User.ID "block_slot_123456" }}
{{ end }}
{{ end }}

Authorā€‹

This custom command was written by @Pedro-Pessoa.