Skip to content
home/templates/crate key system (rarity-weighted)
cratesBeginnernewmc 1.20.x – 1.21.x23 lines

crate key system (rarity-weighted)

right-click a crate key to roll a random reward. diamond/emerald/gold rarity weights. configurable rewards table.

vanilla Skriptno addons required.
crate-key.sk23 lines
command /givekey:
    permission: crate.admin
    trigger:
        give 1 tripwire hook named "&6Crate Key" with lore "&7Right-click to open!" to player
        send "&aGave you a crate key." to player

on right click holding tripwire hook:
    if name of player's tool is "&6Crate Key":
        cancel event
        remove 1 tripwire hook from player's inventory
        # Weighted roll: 60% common / 30% rare / 10% legendary
        set {_roll} to a random integer between 1 and 100
        if {_roll} <= 60:
            give 16 cooked beef to player
            send "&7You opened a crate! Reward: &fCommon — 16x cooked beef" to player
        else if {_roll} <= 90:
            give 1 diamond to player
            send "&aYou opened a crate! Reward: &bRare — 1x diamond" to player
        else:
            give 1 netherite ingot to player
            send "&6You opened a crate! &lReward: Legendary &r&6— 1x netherite ingot" to player
            broadcast "&6%player% &fjust won a &6&lLegendary &fcrate reward!"

get it running

crate-key.sk · 23 lines · vanilla Skript
  1. 1

    copy or download

    grab the .sk file with the buttons up top.

    crate-key.sk· ready to drop in
  2. 2

    drop it in your scripts folder

    save it exactly here on your server — no typos, just copy the path:

    …/plugins/Skript/scripts/crate-key.sk
  3. 3

    reload in-game

    run this in chat or console — your script goes live instantly:

    /sk reload crate-key
that's it — your script is live. hop in-game to try it.

comments