Slot Machine
This command runs the slot machine game.
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, bettingamount
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.