HyperScript
Docs

← All of the Docs What players see

Trading

structureopen trades <title>:since 1.7.23

Opens the trading window for the player; open trades <title> for <who>: for someone else. The lines under it are the offers

command /baker:
    players only: true
    trigger:
        open trades "&eBaker":
            1 emerald for 6 bread
            3 emerald for 1 cake
Try it
expression<cost> for <result>since 1.7.23

An offer: what is paid on the left, what is got on the right. Any item with its amount, name and enchantments, or one named with item <name>:

command /miner:
    players only: true
    trigger:
        open trades "&7Miner":
            16 cobblestone for 1 emerald
Try it
expression<cost> and <cost> for <result>since 1.7.23

An offer that takes two things

command /smith:
    players only: true
    trigger:
        open trades "&6Smith":
            4 emerald and 1 stick for 1 iron sword
Try it
Guide and examples

The window villagers trade in, with offers of your own:

command /blacksmith:
    players only: true
    trigger:
        open trades "&6Blacksmith":
            5 emerald for 1 iron sword
            8 emerald and 1 stick for 1 diamond sword named "&bFrostbite" enchanted with sharpness 2
            1 diamond for 12 emerald
WrittenMeaning
open trades <title>:Opens the trading window for the player; open trades <title> for <who>: for someone else. The lines under it are the offers
<cost> for <result>An offer: what is paid on the left, what is got on the right. Any item with its amount, name and enchantments, or one named with item <name>:
<cost> and <cost> for <result>An offer that takes two things
  • The game does the trading itself: it checks that the player has what an offer costs, takes it and hands over the result, as with a villager. Nothing has to be scripted for that.
  • An offer can be used as often as the player can pay. A script that wants to sell something only once gives it out with give instead.
  • Money from an economy plugin cannot be an offer's cost: offers are item for item. Sell for money from a menu, with balance of player.