2

[1.13] How to detect if a player doesn't have an item in their inventory

Dudamesh's Avatar Dudamesh11/14/18 6:13 pm
2 emeralds 13k 7
12/1/2018 6:50 am
Dudamesh's Avatar Dudamesh


Title sums it up


basically I need to test if a player (with a certain tag) doesn't have that item in their inventory


I'm using it as a detector for shooting arrows instead of tagging the arrow as it spawns from the player, I'm using it to detect if a player has shot an arrow.


Basically what I've already done is run this command in a loop:


```execute if entity @a[tag=hasGun,nbt={Inventory:{id:"minecraft:arrow"}]}] run scoreboard players set @a[tag=hasGun,nbt={Inventory:{id:"minecraft:arrow"}]}] hasArrow 1```




which sets all players' score tagged "hasGun" with an arrow in their inventory to 1 meaning they have an arrow




then I need to detect when that player has shot their bow (and used up the arrow in their inventory) and then set their score to 0




how exactly does one do that
Posted by Dudamesh's Avatar
Dudamesh
Level 62 : High Grandmaster Senpai
72

Create an account or sign in to comment.

7

1
11/19/2018 11:37 am
Level 57 : Grandmaster Engineer
ShelLuser
ShelLuser's Avatar
Normally you'd also use a Count property when checking for an inventory item. So if you set Count to 0 you'd check if no items are present in the players inventory.
1
11/15/2018 2:06 pm
Level 14 : Journeyman Modder
brobie1kanobi
brobie1kanobi's Avatar
I do that all the time man! Sometimes it just takes a "stepping back" second and you usually realize you are over-complicating stuff. lol
1
11/14/2018 8:21 pm
Level 2 : Apprentice Architect
Frozy--
Frozy--'s Avatar
i do remember im most languages including command blocks the "!" indicates a negative


so maybe try putting a ! infront of one of those things


it might just work you never know
2
11/14/2018 8:51 pmhistory
Level 62 : High Grandmaster Senpai
Dudamesh
Dudamesh's Avatar
it does work for [tag=!abc] but not for NBT tags




Also I found out a way to fix my problem as I only need to set all players score to 0 on a repeat command block

and set all with arrows to 1, it's a really simple fix I'm quite disappointed in myself for not thinking of it much more earlier
1
11/30/2018 5:31 pm
Level 29 : Expert Engineer
SUPERIONtheKnight
SUPERIONtheKnight's Avatar
It does work for NBT tags, have you tried the following?
/say @s[nbt=!{Inventory:[{id:"minecraft:arrow"}]}]
Also, that is a good solution you found. I use it a lot. :)

~SUPERIONtheKnight
1
12/01/2018 6:50 am
Level 62 : High Grandmaster Senpai
Dudamesh
Dudamesh's Avatar
I've already quite gotten over this but it's nice to see people eager to help, even though they are 16 days late xP
1
11/15/2018 4:18 am
Level 2 : Apprentice Architect
Frozy--
Frozy--'s Avatar
hehe the best can make the dumbest mistakes XD
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome