I would like to accomplish this using a single command in a command block that is set to repeat, and I'd like to avoid using the scoreboard. I'm looking to check whether or not the player's level is above Lv.15, and if so, give them a tripwire hook named "15EXP Key". I'd also like to make sure they only have one of these keys at a time, so as to encourage using them before acquiring any more experience. I had tried this, but it didn't work how I had expected it to:
/execute unless entity @a[nbt={Inventory:[{id:"minecraft:tripwire_hook"}]}] run give @a[level=15..] minecraft:tripwire_hook{Name:"15EXP Key"} 1
Moreover, this command will be used in an area with multiple nearby players, and I'd like it to only apply to players in a certain specified area, but I have no idea how to do that. Also, it should apply to those players individually so that if one player has the required levels and the other does not, the player with the right level should receive the item but the other should not.
@a[level=15..]
, thenunless @s[nbt={…}]
. Also, you said that it doesn't work like expected, how does it behave instead? Does the check for tripwire in the inventory work? I think it should, but I'm not 100% sure.