How do I use ! on teams and items
I am working on a Minecraft bed-wars map and I want to make 2 things; an alarm and something that destroys items on the ground except iron ingots, gold ingots, emeralds, and diamonds. I can already destroy individual items, but id rather not make a command block for around 20 different items. My current code for each is this:
/kill @e[type=item,nbt={Item:{id:"minecraft:the item I want"}}]
Is there a way to put ! into it so it destroys everything but the iron ingots, gold ingots, emeralds, and diamonds? For the alarm I need to either get a way to add the 3 other teams (I only can put one in at the moment). Or could I use !blue somehow to detect teams other than blue within a radius of 50. Some kind of code like this, this one doesn't work
/execute at @a[team=!blue,distance=..50] run say blue alarm triggered
Solution 1:
To target all except some items, you can tag the items you don't want to kill.
Put the following in a repeating command blocks for each item you want to keep.
tag @e[type=item,nbt={Item:{id:"minecraft:some_item"}}] add dontDestroy
Then you can target items without the dontDestroy
tag:
/kill @e[type=item,tag=!dontDestroy]
For the teams command, create a dummy scoreboard objective to track if the alarms have been triggered:
/scoreboard objectives add alarmTriggered dummy
Fake players will be used to keep track if each team's alarm is triggered.
Put the following in a repeating command block:
execute if entity @a[team!=blue,distance=..50] if score blueTeam alarmTriggered matches 0 run say blue alarm triggered
Then put the following in a conditional chain command block next to it to update the scoreboard:
scoreboard players set blueTeam alarmTriggered 1
Do this for every team. To reset the game, run /scoreboard players set @a alarmTriggered 0
.
Without the scoreboard, the message "blue alarm triggered" would be shown constantly because of the repeating command block.