I created a currency system in my adventure map using a dummy score Money. I've got everything set where you press a button to buy an item and in return you get subtracted x money. problem is, testfor no longer exists, and I cannot figure out how to prevent the transaction form happening if the player does not have enough money. As it stands they can keep buying and buying, while their money dips into the negatives.
/execute as @p if score @s money matches 5.. run tag @s add sel
/give @p[tag=sel] minecraft:diamond 1
/scoreboard players remove @p[tag=sel] money 5
/tag @p[tag=sel] remove sel
Rollback Post to RevisionRollBack
I'm a programmer. I use C/C++, BASIC, Assembly, and Python. If i sound too technicial, that's because it's the way i think.
I'm trying to wrap my brain around this...
I created a currency system in my adventure map using a dummy score Money. I've got everything set where you press a button to buy an item and in return you get subtracted x money. problem is, testfor no longer exists, and I cannot figure out how to prevent the transaction form happening if the player does not have enough money. As it stands they can keep buying and buying, while their money dips into the negatives.
any and all help is greatly appreciated.
Hi,
Instead of "/testfor", now you use the "/execute".
So if you want to testfor a player with 5 or more money and give him a diamond, you would do:
and then you need a chain command block attached to the first one that will remove x money from the player:
(Note: this is for singleplayer only)
Command block engineer // Developer // #TeamTrees
nice! that worked. thanks for that, I never would've figured it out.
you say this only works for singleplayer. what about LAN? There's going to be 4 of us playing this adventure world.
Use tags
I'm a programmer. I use C/C++, BASIC, Assembly, and Python. If i sound too technicial, that's because it's the way i think.
My Suggestions
Perfect! thank you very much.
one last question, since i'm having trouble figuring it out.
how would you do it if you wanted to sell the diamond?
oh wait, I believe I figured it out. that one was a bit easier.
/execute at @p[nbt={Inventory:[{id:"minecraft:diamond"}]}] run clear @p minecraft:diamond 1
/scoreboard players add @p money 5
Make sure to tag the seller and then use "/scoreboard players add @p[tag=seller] money 5", otherwise the money could go to the wrong player.
Command block engineer // Developer // #TeamTrees
good point. thanks for that tip, I overlooked that