283
Hello! Today, you will learn how to create a shop with custom commands and variables that allow players to have money and buy items!
What We Are Doing:
Today, we will be producing code that will look something like this:
if (money >= itemCost) {
money =- itemCost
give @p item itemAmount itemValue
} else {
tellraw @p {"text":"You do not have enough money!","color":"red"}
}
If you didn't understand that, don't worry, it will all be explained through the tutorial.
Creating a Variable:
Variables in programming hold a value, and depending on this value, certain actions will be run.
Lets create a variable:
/scoreboard objectives add money dummy
If a variable, or score, is a dummy, then it will only increase or decrease whenever it is needed to.
Now, lets make the variable value appear above a players head:
/scoreboard objectives setdisplay belowName money
The variable money will now display above every player's head, which you may notice if you are in multiplayer.
Set your money value to two:
/scoreboard players set @p money 2
And if we want to add an amount, you can do the following:
/scoreboard players add @p money 2
Place a command block that is repeating and always active and enter:
/give @a[score_buy_min=1,score_buy=1,score_money_min=2] diamond 1 0
Add the following variable:
/scoreboard objectives add buy trigger
A trigger variable can act as a command, that can be run by players with and without OP.
Run this command in a repeating and always active command block:
/scoreboard players enable @a buy
In a chain command block above this, enter:
/scoreboard players remove @a[score_buy_min=1,score_buy=1,score_money=2] money 2
In a chain command block, that is always active, on top of the last command block, enter:
/scoreboard players set@a[score_buy_min=1,score_buy=1,score_money=2] buy 0
And now, you can repeat this chain, and if the money is at the minimum amount required to buy the item, then you will get the item and money will be deducted.
For example:
/give @a[score_buy_min=2,score_buy=2,score_money_min=5] emerald 1 0
/scoreboard players remove @a[score_buy_min=2,score_buy=2,score_money=5] money 5
/scoreboard players set @a[score_buy_min=2,score_buy=2,score_money=5] buy 0
Credits:
By Code202
Notes:
For 1.11.2+
What We Are Doing:
Today, we will be producing code that will look something like this:
if (money >= itemCost) {
money =- itemCost
give @p item itemAmount itemValue
} else {
tellraw @p {"text":"You do not have enough money!","color":"red"}
}
If you didn't understand that, don't worry, it will all be explained through the tutorial.
Creating a Variable:
Variables in programming hold a value, and depending on this value, certain actions will be run.
Lets create a variable:
/scoreboard objectives add money dummy
If a variable, or score, is a dummy, then it will only increase or decrease whenever it is needed to.
Now, lets make the variable value appear above a players head:
/scoreboard objectives setdisplay belowName money
The variable money will now display above every player's head, which you may notice if you are in multiplayer.
Set your money value to two:
/scoreboard players set @p money 2
And if we want to add an amount, you can do the following:
/scoreboard players add @p money 2
Place a command block that is repeating and always active and enter:
/give @a[score_buy_min=1,score_buy=1,score_money_min=2] diamond 1 0
Add the following variable:
/scoreboard objectives add buy trigger
A trigger variable can act as a command, that can be run by players with and without OP.
Run this command in a repeating and always active command block:
/scoreboard players enable @a buy
In a chain command block above this, enter:
/scoreboard players remove @a[score_buy_min=1,score_buy=1,score_money=2] money 2
In a chain command block, that is always active, on top of the last command block, enter:
/scoreboard players set@a[score_buy_min=1,score_buy=1,score_money=2] buy 0
And now, you can repeat this chain, and if the money is at the minimum amount required to buy the item, then you will get the item and money will be deducted.
For example:
/give @a[score_buy_min=2,score_buy=2,score_money_min=5] emerald 1 0
/scoreboard players remove @a[score_buy_min=2,score_buy=2,score_money=5] money 5
/scoreboard players set @a[score_buy_min=2,score_buy=2,score_money=5] buy 0
Credits:
By Code202
Notes:
For 1.11.2+
Tags |
tools/tracking
3959566
6
how-to-create-a-shop-command-block-tutorial
Create an account or sign in to comment.