Skip to main content

Wheel of Fortune

This command runs the wheel of fortune game.

caution

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

Trigger

Type: Regex
Trigger: \A\-(?i)wheel(offortune)?

Usage

  • wheeloffortune <bet> - Runs the wheel of fortune game, betting bet.
Aliases

Instead of wheeloffortune, you can also use wheel and wheelOfFortune (the command is case insensitive).

Configuration

  • 📌 $dbName
    Database entry name that stores the user's credits.

  • $limit
    The message to show users when they don't have enough credits to play.

  • $bb1
    The message to show users when they attempt to bet less than 1 credit.

  • $helpText
    The help text for the command.

Code

{{/*
Wheel of fortune game that integrates with an existing currency system.
See <https://yagpdb-cc.github.io/fun/wheel-of-fortune> for more information.

Author: Hyakki999 <https://github.com/Hyakki999>
*/}}

{{/* Configurable values */}}
{{ $dbName := "CREDITS" }}
{{ $limit := " insufficient 🦆" }}
{{ $bb1 := " you have to bet at least 1 🦆" }}
{{ $helpText := "-wheel <amount>\nFor example: **-wheel 10**\nThis way you would be betting 10 🦆." }}
{{/* End of configurable values */}}

{{/* Do not change anything below */}}
{{ $pos := 1.0 }}
{{ if lt (randInt 0 11) 7 }}
{{ $pos = (index (shuffle (cslice 0.1 0.3 0.5 0.2)) 0) }}
{{ else }}
{{ $pos = (index (shuffle (cslice 1.2 2.4 1.7 1.5)) 0) }}
{{ end }}

{{ $a := dict 0.1 `\↙️` 0.2 "←" 0.3 "↓" 0.5 `\↘️` 1.2 "→" 1.5 `\↖️` 1.7 "↑" 2.4 `\↗️` }}
{{ $arrow := $a.Get $pos }}

{{ $fh := "🦆\n\n 『1.5』 『1.7』 『2.4』\n\n『0.2』 " }}
{{ $sh := " 『1.2』\n\n 『0.1』 『0.3』 『0.5』" }}
{{ $bal := toInt (dbGet .User.ID $dbName).Value }}
{{ $red := 0xff2627 }}
{{ $gre := 0x76ff03 }}

{{ if .CmdArgs}}
{{ $bet := index .CmdArgs 0 | toInt }}
{{ if ge $bet 1 }}
{{ if ge $bal $bet }}
{{ $silent := dbIncr .User.ID $dbName ( mult -1 $bet ) }}
{{ $amount := toInt ( round ( mult ( toFloat $bet ) $pos ) ) }}
{{ $silent := dbIncr .User.ID $dbName $amount }}
{{ sendMessage nil ( cembed "color" $gre "title" ( print .User.String " won: " $amount $fh $arrow $sh ) ) }}
{{ else }}
{{ sendMessage nil ( cembed "color" $red "title" ( print .User.String $limit ) ) }}
{{ end }}
{{ else }}
{{ sendMessage nil ( cembed "color" $red "title" ( print .User.String $bb1 ) ) }}
{{ end }}
{{ else }}
{{ sendMessage nil ( cembed "color" $red "title" ( print "Usage: \n" $helpText ) ) }}
{{ end }}

Author

This custom command was written by @Hyakki999.