And so on. It has problems of course, since it would also create a maximum, and is time-consuming, but if you use lots you could make that quite high.
I have no doubt there's a better way to do it, in fact I feel a tickle at the back of my mind right now on something that would work better, but it's being elusive.
Rollback Post to RevisionRollBack
AKA: OwenConner
Don't be surprised if one day I take over the front page of the Forum Games, and then disappear for months at a time. It happens.
You can use CommandStats to accomplish this, which also supports multiplayer tracking.
Prerequisites:
Objective for each player to hold their own score:
/scoreboard objectives add ITEMS dummy
In order for CommandStats to modify a score, the target must be tracked prior to triggering. You may need to run the following on a clock if new players are able to enter the game at any time. Adding 0 will force players to be tracked with a default score of 0, while not affecting previously-tracked scores:
/scoreboard players add @a ITEMS 0
And finally, the players will need a necessary CommandStat trigger, in this case "AffectedItems". This may also need to be on a clock, same reasoning as the command before. The trigger will set the player's own score equal to the number of "affected items" whenever the player runs a command that targets items (such as /clear).
/stats entity @a set AffectedItems @a[c=1] ITEMS
Triggering:
Place the following into a command block that will be detecting items in the inventory. It forces players to clear from their own inventories. It will not remove any items from their inventory, but we will get the necessary data: the number of items that *could* have been cleared.
Every time the /execute command is activated, players run the /clear command, triggering their stored CommandStat. That CommandStat will check the number of items the command the player ran (/clear) affected, and set the nearest player (which will be the executing player, so themselves) to have their "ITEMS" score set equal to that value.
So if a player has 30 cobblestone, their "ITEMS" score is set to 30. You can then target players with that score:
/say @a[score_ITEMS_min=30]
This will consider items regardless of where they are in their inventory.
Can we use AffectedItems stats with multiple scores ? If not is there an alternative wayto detect if the player have at least [amount] of items in inventory ?
You can use CommandStats to accomplish this, which also supports multiplayer tracking.
Prerequisites:
Objective for each player to hold their own score:
/scoreboard objectives add ITEMS dummy
In order for CommandStats to modify a score, the target must be tracked prior to triggering. You may need to run the following on a clock if new players are able to enter the game at any time. Adding 0 will force players to be tracked with a default score of 0, while not affecting previously-tracked scores:
/scoreboard players add @a ITEMS 0
And finally, the players will need a necessary CommandStat trigger, in this case "AffectedItems". This may also need to be on a clock, same reasoning as the command before. The trigger will set the player's own score equal to the number of "affected items" whenever the player runs a command that targets items (such as /clear).
/stats entity @a set AffectedItems @a[c=1] ITEMS
Triggering:
Place the following into a command block that will be detecting items in the inventory. It forces players to clear from their own inventories. It will not remove any items from their inventory, but we will get the necessary data: the number of items that *could* have been cleared.
Every time the /execute command is activated, players run the /clear command, triggering their stored CommandStat. That CommandStat will check the number of items the command the player ran (/clear) affected, and set the nearest player (which will be the executing player, so themselves) to have their "ITEMS" score set equal to that value.
So if a player has 30 cobblestone, their "ITEMS" score is set to 30. You can then target players with that score:
/say @a[score_ITEMS_min=30]
This will consider items regardless of where they are in their inventory.
Ive used your technique and it works well, but Ive noticed that the
command block keeps a redstone signal if you have more than the amount
(2) so it can only run once, now with the moneywars idea I had in mind
would work well, but I want it reset able, or to make some form of shop
with it
Will it work correctly if I simply replace "cobblestone" with my own custom item of "gold_ingot,tag:{display: {Name:"Stamped Gold",},ench:[{id:35,lvl:10}]"
I already have a working 'ATM' with a /clear, comparator and /scoreboard players add etc., but I can only do it one item at a time. I want one that I am able to do is just check for a minimum quantity first, the have that 'comparatored' to preface the other two in order to not be able to cheat. Currently the one I tried with just the two, for larger quantities, allows you to only have one of that item and still get the 'add [playerName] Money 16'.
You can use CommandStats to accomplish this, which also supports multiplayer tracking.
Prerequisites:
Objective for each player to hold their own score:
/scoreboard objectives add ITEMS dummy
In order for CommandStats to modify a score, the target must be tracked prior to triggering. You may need to run the following on a clock if new players are able to enter the game at any time. Adding 0 will force players to be tracked with a default score of 0, while not affecting previously-tracked scores:
/scoreboard players add @a ITEMS 0
And finally, the players will need a necessary CommandStat trigger, in this case "AffectedItems". This may also need to be on a clock, same reasoning as the command before. The trigger will set the player's own score equal to the number of "affected items" whenever the player runs a command that targets items (such as /clear).
/stats entity @a set AffectedItems @a[c=1] ITEMS
Triggering:
Place the following into a command block that will be detecting items in the inventory. It forces players to clear from their own inventories. It will not remove any items from their inventory, but we will get the necessary data: the number of items that *could* have been cleared.
Every time the /execute command is activated, players run the /clear command, triggering their stored CommandStat. That CommandStat will check the number of items the command the player ran (/clear) affected, and set the nearest player (which will be the executing player, so themselves) to have their "ITEMS" score set equal to that value.
So if a player has 30 cobblestone, their "ITEMS" score is set to 30. You can then target players with that score:
/say @a[score_ITEMS_min=30]
This will consider items regardless of where they are in their inventory.
Yes, though quite a bit differently. CommandStats as a whole has been overhauled and no longer directly stores data on the entity/block. Instead, /execute stores the result of a command directly to a target's score. That way the only prerequisite is the objective itself, no /stats or other /scoreboard commands.
Prerequisites:
The objective to track the number of items in:
/scoreboard objectives add ITEMS dummy
Triggering:
The following command will set each player's own score based on the number of the specified items that they have in their inventory:
/execute as @a store result score @s ITEMS run clear @s minecraft:cobblestone 0
And to target players afterwards:
/say Players with 30+ cobblestone: @a[scores={ITEMS=30..}]
The subargument that replaces CommandStats is "store". All of the old varied CommandStats types (AffectedItems, AffectedEntities, AffectedBlocks, QueryResult) have been merged into one "result" type (which is what's used in the command above). The original "SuccessCount" type is now just "success" (in place of "result" int he command). From there, you can either choose to store the resulting value from the nested command into a "score", or you could store it directly into NBT data for a "block" or "entity".
For example, the following sets a creeper's health based on the number of cobblestone in the player's inventory (provided the amount does not exceed the creeper's max health):
/execute as @p store result entity @e[type=minecraft:creeper,limit=1,sort=nearest] Health float 1.0 run clear @s minecraft:cobblestone 0
I already suceeded in making this. Thanks to the guys who helped!
Hey, I am making a map and I am working on quests right now. I want to detect if the player have at least [amount] of items in inventory.
I know this command:
but it detects if the player have ONLY 2. I want to detect if the player have at least 2.
Thank you
You could always have multiple command blocks with a slight variation in the code.
Such as this
/testfor @a {Inventory:[{id:"minecraft:log",Count:1b}]}
/testfor @a {Inventory:[{id:"minecraft:log",Count:2b}]}
/testfor @a {Inventory:[{id:"minecraft:log",Count:3b}]}
And so on. It has problems of course, since it would also create a maximum, and is time-consuming, but if you use lots you could make that quite high.
I have no doubt there's a better way to do it, in fact I feel a tickle at the back of my mind right now on something that would work better, but it's being elusive.
AKA: OwenConner
Don't be surprised if one day I take over the front page of the Forum Games, and then disappear for months at a time. It happens.
------------------------------------------------------------------------------
------------------------------------------------------------------------------
I was going to put a list of words of wisdom here, but I think I'll put this here instead
You can use CommandStats to accomplish this, which also supports multiplayer tracking.
Prerequisites:
Objective for each player to hold their own score:
In order for CommandStats to modify a score, the target must be tracked prior to triggering. You may need to run the following on a clock if new players are able to enter the game at any time. Adding 0 will force players to be tracked with a default score of 0, while not affecting previously-tracked scores:
And finally, the players will need a necessary CommandStat trigger, in this case "AffectedItems". This may also need to be on a clock, same reasoning as the command before. The trigger will set the player's own score equal to the number of "affected items" whenever the player runs a command that targets items (such as /clear).
Triggering:
Place the following into a command block that will be detecting items in the inventory. It forces players to clear from their own inventories. It will not remove any items from their inventory, but we will get the necessary data: the number of items that *could* have been cleared.
Summary:
Every time the /execute command is activated, players run the /clear command, triggering their stored CommandStat. That CommandStat will check the number of items the command the player ran (/clear) affected, and set the nearest player (which will be the executing player, so themselves) to have their "ITEMS" score set equal to that value.
So if a player has 30 cobblestone, their "ITEMS" score is set to 30. You can then target players with that score:
This will consider items regardless of where they are in their inventory.
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/
That's exactly what I have done already (I now came to edit the post to say that I already figured it out)!
Thank you very much for your help!
Can we use AffectedItems stats with multiple scores ? If not is there an alternative wayto detect if the player have at least [amount] of items in inventory ?
Remove this please
Ive used your technique and it works well, but Ive noticed that the
command block keeps a redstone signal if you have more than the amount
(2) so it can only run once, now with the moneywars idea I had in mind
would work well, but I want it reset able, or to make some form of shop
with it
Will it work correctly if I simply replace "cobblestone" with my own custom item of "gold_ingot,tag:{display: {Name:"Stamped Gold",},ench:[{id:35,lvl:10}]"
I already have a working 'ATM' with a /clear, comparator and /scoreboard players add etc., but I can only do it one item at a time. I want one that I am able to do is just check for a minimum quantity first, the have that 'comparatored' to preface the other two in order to not be able to cheat. Currently the one I tried with just the two, for larger quantities, allows you to only have one of that item and still get the 'add [playerName] Money 16'.
Is it possible to set a scoreboard to a certain number, then later add a certain number to that number on the scoreboard. For example:
you have 100 cobblestone
you "sell" the cobblestone, 100 is added to your "Money" scoreboard
your "Money" scoreboard is set at 100
then later you have another 100 cobblestone
you "sell the cobble stone, 100 is added to you "Money" scoreboard
your "Money" scoreboard is now set at 200 because it added the two 100 cobblestone together
is that possible?
Is there a way to do this in 1.13 (snapshot)?
Yes, though quite a bit differently. CommandStats as a whole has been overhauled and no longer directly stores data on the entity/block. Instead, /execute stores the result of a command directly to a target's score. That way the only prerequisite is the objective itself, no /stats or other /scoreboard commands.
Prerequisites:
The objective to track the number of items in:
Triggering:
The following command will set each player's own score based on the number of the specified items that they have in their inventory:
And to target players afterwards:
The subargument that replaces CommandStats is "store". All of the old varied CommandStats types (AffectedItems, AffectedEntities, AffectedBlocks, QueryResult) have been merged into one "result" type (which is what's used in the command above). The original "SuccessCount" type is now just "success" (in place of "result" int he command). From there, you can either choose to store the resulting value from the nested command into a "score", or you could store it directly into NBT data for a "block" or "entity".
For example, the following sets a creeper's health based on the number of cobblestone in the player's inventory (provided the amount does not exceed the creeper's max health):
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/
Thank you very much for such a swift reply, Skylinerw!
This method works perfectly, just like the one you described previously, worked in the pre-1.13 versions. And it requires fewer command blocks.
I've always found the scoreboard branch of commands quite confusing, and I'm still learning.
I wanted to use this method to make a simple item-for-item shop, which I've just tried to make and it's perfect ^^
So thank you, you saved me.
Is there a way to do it using the /execute command in 1.13?