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
weightabove0compete, and one of them runs based on its weight. - Random pick: the entries without a
weightcompete, and one of them runs, each with the same chance.
1. Where does it go?
Section titled “1. Where does it go?”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 runweight: 45.0# The commands to runcommands:- "give {player} gold_ingot {random}:1-5""2":# The chance for these to runweight: 25.0# The commands to runcommands:- "give {player} iron_ingot {random}:5-10""3":# The chance for these to runweight: 15.0# The commands to runcommands:- "give {player} emerald {random}:16-32""4":# The chance for these to runweight: 10.0# The commands to runcommands:- "give {player} lapis_lazuli {random}:32-64""5":# The chance for these to runweight: 5.0# The commands to runcommands:- "give {player} netherite_scrap {random}:64-128"# No chance is provided, thus we will pick random commands."6":# The commands to runcommands:- "give {player} diamond {random}:128-256"random-commands sits under the root voucher-code: key, as in the shipped codes/Starter-Money.yml.
voucher-code:# The code to use in /crazyvouchers redeem <code>code: 'startermoney'# Run normal commands when the code is redeemed.commands:- 'eco give {player} 10000'random-commands:"1":# The chance for these to runweight: 45.0# The commands to runcommands:- "give {player} gold_ingot {random}:1-5""2":# The chance for these to runweight: 25.0# The commands to runcommands:- "give {player} iron_ingot {random}:5-10""3":# The chance for these to runweight: 15.0# The commands to runcommands:- "give {player} emerald {random}:16-32""4":# The chance for these to runweight: 10.0# The commands to runcommands:- "give {player} lapis_lazuli {random}:32-64""5":# The chance for these to runweight: 5.0# The commands to runcommands:- "give {player} netherite_scrap {random}:64-128"# No chance is provided, thus we will pick random commands."6":# The commands to runcommands:- "give {player} diamond {random}:128-256"2. How is an entry picked?
Section titled “2. How is an entry picked?”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.
Only entries without a weight take part. One of them runs, each with the same chance.
In the shipped example, "6" is the only entry without a weight, so it runs on every use, on top of the weighted pick.
When a voucher is used or a code is redeemed, the plugin runs:
- Every line in
commands. - The random pick, if it has any entries.
- The weighted pick, if it has any entries.
At most two entries from random-commands run per use: one from each pick.
3. Tips
Section titled “3. Tips”- Leave the
weightoption out to put an entry in the random pick. - Give every weighted entry a
weightabove0. - Files that still use the old list form of
random-commandsorchance-commandscan be converted with/crazyvouchers migrate -mt VouchersDeprecated.