Skip to content

Weight System

random-commands is a section on a voucher or a code. Each entry in it has a commands list and an optional weight option.

The section runs two picks that are independent of each other:

  • Weighted pick: the entries with a weight above 0 compete, and one of them runs based on its weight.
  • Random pick: the entries without a weight compete, and one of them runs, each with the same chance.

random-commands sits under the root voucher: key, as in the shipped vouchers/Example.yml.

voucher:
# The material.
item: 'diamond_helmet'
# The commands to send.
commands:
- 'msg {player} wow you claimed a voucher.'
random-commands:
"1":
# The chance for these to run
weight: 45.0
# The commands to run
commands:
- "give {player} gold_ingot {random}:1-5"
"2":
# The chance for these to run
weight: 25.0
# The commands to run
commands:
- "give {player} iron_ingot {random}:5-10"
"3":
# The chance for these to run
weight: 15.0
# The commands to run
commands:
- "give {player} emerald {random}:16-32"
"4":
# The chance for these to run
weight: 10.0
# The commands to run
commands:
- "give {player} lapis_lazuli {random}:32-64"
"5":
# The chance for these to run
weight: 5.0
# The commands to run
commands:
- "give {player} netherite_scrap {random}:64-128"
# No chance is provided, thus we will pick random commands.
"6":
# The commands to run
commands:
- "give {player} diamond {random}:128-256"

Only entries with a weight above 0 take part.

The max range is the sum of those weights. The plugin rolls a random number between 0 and that sum, then subtracts each entry’s weight in order until it lands on one. Each entry’s chance is its weight divided by the sum.

Weights are relative to each other, so they do not need to add up to 100. The shipped example adds up to exactly 100, so each weight reads as a percentage:

Entry weight Chance
"1" 45.0 45%
"2" 25.0 25%
"3" 15.0 15%
"4" 10.0 10%
"5" 5.0 5%

Exactly one weighted entry runs per use.

  • Leave the weight option out to put an entry in the random pick.
  • Give every weighted entry a weight above 0.
  • Files that still use the old list form of random-commands or chance-commands can be converted with /crazyvouchers migrate -mt VouchersDeprecated.