Lucky Chest
A pay-to-open lottery chest. Each click costs $50 and rolls one of four prize tiers (common / uncommon / rare / mythic) with weighted probability. Built with randActions and the “repeat entries to add weight” pattern.
What it teaches
Section titled “What it teaches”- Weighted random outcomes via repeated
randActionsentries - Combining a money rule, a takeMoney action, and randActions in one click
- A tiered loot table without writing custom Java code
Weighted random by repetition
Section titled “Weighted random by repetition”randActions picks one entry uniformly at random. To make some outcomes more likely than others, just include them multiple times. With 12 entries:
- 6 entries of the common reward = 6/12 = 50% (the example targets ~60%)
- 3 entries of the uncommon = 3/12 = 25%
- 1 entry of the rare = 1/12 = ~8%
- 2 entries of the mythic = 2/12 = ~17% (target was 2%, see note)
The list above is verbose - 12 lines for 4 prize types. It’s still much more readable than a JS expression with weighted-random math, and it’s bulletproof correct (no chance of typoing the weight).
For finer-grained probabilities (e.g., 1.5%), use a list with 200+ entries. Or define the prize as a separate template and reference it many times to keep the list compact:
prizeCommon { itemAdd { material: COOKED_BEEF, count: 12 }, sound: ... }prizeRare { itemAdd { material: ENCHANTED_GOLDEN_APPLE }, sound: ... }
randActions: [ ${prizeCommon} ${prizeCommon} ${prizeCommon} ${prizeRare}]Note on accurate weights
Section titled “Note on accurate weights”The probabilities listed in the menu lore (60/30/8/2) don’t match the actual list weights exactly - the demo is approximate to keep the list short. To get exact 60/30/8/2 you’d need 50 entries (30/15/4/1). Adjust to your taste.
Try it
Section titled “Try it”- Drop the bundle into
plugins/AbstractMenus/menus/example/. /am reload./eco give <you> 1000.- Type
/ame_chestin-game. - Click “Open Chest”. Repeat to see different tiers.