I am creating a farming mini-game. I would like people to be able to sell items for points. I have a system that works with command blocks that have a specific price for each item, but if I want to change prices, it involves going around to each command block and manually editing it.
Is there a way to set prices like this with a global variable? Is it possible with gamerule variables for instance? I don't know enough about them to make it work.
Stand on top of the first command block and type this into chat:
/stats block ~ ~-1 ~ set QueryResult #WHEAT price
Now same for the second block:
/stats block ~ ~-1 ~ set QueryResult #CARROT price
Repeat for every type of crop you wish to add.
Using soldCrop scoreboards allow players to sell as many of the crop at the same time and then set their score to the number they sold. Their money will be increased by the price of that crop this many times. So using the example gamerule values I gave at the top, if a player sold 15 wheat, their money score would increase by 75.
The gamerules can be changed at any time and will apply to all future sales.
Edit: Forgot the initial setting of the price scores for the #fake players. Be sure to set any scores to any value, to simply add the fake player to the scoreboard or the /stats command will not be able to set the value of the gamerule to the corresponding objective.
Just pointing out, you might want to have a single objective and change the names of the fake players, so that you don't have to have a large number of objectives.
Just pointing out, you might want to have a single objective and change the names of the fake players, so that you don't have to have a large number of objectives.
Hello,
I am creating a farming mini-game. I would like people to be able to sell items for points. I have a system that works with command blocks that have a specific price for each item, but if I want to change prices, it involves going around to each command block and manually editing it.
Is there a way to set prices like this with a global variable? Is it possible with gamerule variables for instance? I don't know enough about them to make it work.
Thanks
I don't know if it would work with /gamerule, but it would definetly work with a scoreboard. It actually depends on how give the money to the player.
If you are using a scoreboard, you could just do
My projects: https://blockbench.net/hub
I think that should work nicely, thank you
Can you think of a way to display the price in a message to a player?
like /msg @p The price of potatoes is {potato: price}
I don't speak json
Thanks again!
You can create a gamerule for each different item, here is an example for wheat and carrots.
Example of what you would type:
/gamerule priceWheat 5
/gamerule priceCarrots 10
Setting up the scoreboard:
/scoreboard objectives add price dummy
/scoreboard objectives add soldWheat dummy
/scoreboard objectives add soldCarrot dummy
/scoreboard objectives add money dummy Money
/scoreboard players set #WHEAT price 0
/scoreboard players set #CARROT price 0
Commands:
/gamerule priceWheat
/gamerule priceCarrot
/scoreboard players operation @a[score_soldWheat_min=1] money += #WHEAT price
/scoreboard players remove @a[score_soldWheat_min=1] soldWheat 1
/scoreboard players operation @a[score_soldCarrot_min=1] money += #CARROT price
/scoreboard players remove @a[score_soldCarrot_min=1] soldCarrot 1
Stand on top of the first command block and type this into chat:
/stats block ~ ~-1 ~ set QueryResult #WHEAT price
Now same for the second block:
/stats block ~ ~-1 ~ set QueryResult #CARROT price
Repeat for every type of crop you wish to add.
Using soldCrop scoreboards allow players to sell as many of the crop at the same time and then set their score to the number they sold. Their money will be increased by the price of that crop this many times. So using the example gamerule values I gave at the top, if a player sold 15 wheat, their money score would increase by 75.
The gamerules can be changed at any time and will apply to all future sales.
Edit: Forgot the initial setting of the price scores for the #fake players. Be sure to set any scores to any value, to simply add the fake player to the scoreboard or the /stats command will not be able to set the value of the gamerule to the corresponding objective.
Edit2: Edited as per Skylinerw's suggestion.
Just pointing out, you might want to have a single objective and change the names of the fake players, so that you don't have to have a large number of objectives.
Minecraft-things: http://skylinerw.com
More Minecraft-things: https://sourceblock.net
Guides for command-related features (eventually moving to Source Block): https://github.com/skylinerw/guides
I primarily hang out in the /r/MinecraftCommands discord, where there's a lot of people that help with commands: https://discord.gg/QAFXFtZ
Their corresponding subreddit: https://www.reddit.com/r/MinecraftCommands/
nvm ... did a little googling and I think i figured it out
That's a good point, thanks.