2

I'm aware of a way to buy items with a Money system with couple commands. But can you sell items to gain money?

Here is what I used for a buying system:

/scoreboard objectives add Money dummy (name)

Set Display:

/scoreboard objectives setdisplay sidebar Money

Changing Player Score:

Set Money amount:

/scoreboard players set @p Money 10

Add Money:

/scoreboard players add @p Money 10

Remove Money:

/scoreboard players remove @p Money 10

Add New Player to Money System:

Add Objective:

/scoreboard objectives add newplayer dummy

/scoreboard players add @p[score_newplayer_min=0,score_newplayer­=1] Money 100

/scoreboard players set @p newplayer 2

Then you buy:

/scoreboard players remove @p[r=5,score_Money_min=10] Money 10

/give @p[r=5,score_Money_min=10] minecraft:cobblestone 3

But can you sell items to gain money?

  • 1
    The best way is with basic redstone. Hopper filter system then Comparator to run a command. – Judge2020 Feb 13 '16 at 5:55
2

The big problem with taking items from players is verifying they have the minimum amount before using the clear command. Here is a method to do that. This solution uses a scoreboard and command stats to determine if a player has a minimum amount of items. It could be used to sell/trade items with players.

First you need to manually create a scoreboard objective:

/scoreboard objectives add ITEMS dummy

This will use four command blocks, all chained. I used a button on the impulse block so the player could initiate. The first block uses the clear command with a value of 0. It does nothing but allows command stats to determine how many items were affected/looked at. The second block stores how many items were affected in the objective ITEMS. This objective now has total number of the specified item in the players inventory. The third block clears 100 custom named paper from the inventory only if the player has at least 100. The fourth block would then be used to output to the player(give currency/items).

Blocks

First block is Impulse Unconditional Needs Redstone with command:

clear @p minecraft:diamond 0 0

Second block is Chain Conditional Always Active with command:

stats block ~1 ~ ~ set AffectedItems @p ITEMS

Third block is Chain Conditional Always Active with command:

clear @p[score_ITEMS_min=100] minecraft:diamond 0 1 

Fourth block is Chain Conditional Always Active it's command:

scoreboard players add @p Money 10

All this to see if the player has at least the specified amount before using the clear command. The clear command, when used alone, will succeed if the player has even one of the specified item in their inventory.

This is someone else's idea. I just verified it actually works, and tweaked the commands a little. Here is the page I found the original commands on.

| improve this answer | |
0

you can use /clear like this:

/clear @p[r=5] minecraft:cobblestone 3

comparator to

/scoreboard players add @p[r=5] Money 10

/setblock (wherever the clear commandblock is) minecraft:command_block 0 {Command:"/clear @p[r=5] minecraft:cobblestone 3",SuccessCount:0}

| improve this answer | |
  • Needs Clarification, – Kingsley Zhong Jul 11 '17 at 17:19
  • Your first command would succeed even if there were only 1 cobblestone in the inventory. This defeats the point. Also, to note, the last command could be replaced with blockdata <x> <y> <z> {SuccessCount:0} – IronAnvil Sep 30 '17 at 5:38
0

Yes you can. I just came up with an exchange sysetem, heres an example

/testfor @p {Inventory:[{id:"minecraft:iron_ingot"}]}

/clear @p minecraft:iron_ingot 0 1

/scoreboard players add @p Cash 1
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.