TransWikia.com

Is there a way to set up a shop with scoreboard commands, that you can sell items at?

Arqade Asked by Jason_ on December 28, 2020

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?

3 Answers

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}

Answered by ash4fun on December 28, 2020

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

Answered by Chris CALS on December 28, 2020

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.

Answered by IronAnvil on December 28, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP