Issue with CTF commands
I'm trying to set up a series of working commands that test when the player breaks the wool block (i.e. the flag), they get tagged as the FlagCarrier
. They will also have other effects applied, specifically the glowing effect and a banner placed on their head. I know how to do the glowing and banner, but for some reason I can't seem to get the 'FlagCarrier' commands to work.
I was originally trying to testfor
when a player breaks a certain block (at exact coordinates) I tried testing for air (which worked) - but how does the command know who broke it? So now instead I'm trying to tag whoever picks it up and has the wool block in their inventory. But I can't seem to:
/execute @a {Inventory:[{id:"minecraft:wool",Damage:11s}]} /scoreboard players set @a FlagCarrier 1.
For some reason execute doesn't work with scoreboard?
My original set-up commands are:
/execute @a[r=100] ~ ~ ~ /scoreboard objectives add FlagCarrier dummy
This has a comparator leading into a block with a redstone torch, so it activates when the player is NOT within 100 blocks: /execute @a ~ ~ ~ /scoreboard objectives remove FlagCarrier
/execute @a[r=100] ~ ~ ~ /scoreboard objectives setdisplay sidebar FlagCarrier
(also, this isn't showing unless I manually set it to either 1 or 0)
Also, how can I replace the block if there is no player tagged FlagCarrier
, and no flag item on the ground? I would like to have it so a player on the blue team cannot pick up the blue flag, and it is instead returned to their base. whereas a red player could pick up the dropped flag and gain the tags.
I'm playing version 1.12, so any of the new or changed commands from 1.13+ won't help.
Depends what version you're using but if you're using 1.13 or over, do this:
First make a new objective where the objective is to pick up wool
/scoreboard objectives add (Name) minecraft.picked_up:minecraft.(color)_wool
Next set up a repeat command block that is always on that will detect who has the wool and give them glowing
/execute as @a[scores={(Name)=1}] run effect give @s minecraft:glowing 1 10 true
Next, make another objective that will see when a player drops the wool
/scoreboard objectives add (Name2) minecraft.dropped:minecraft.(same color as last time)_wool
Then make two other repeat command blocks that are always on and put this in the first
/execute as @a[scores={(Name2)=1}] run scoreboard players remove @s (Name) 1
and this in the second
/execute as @a[scores={Name1=1}] run scoreboard players remove @s (Name2) 1
Lastly, add the players to both of the scoreboards and you should be good. Hope this helps!
What you have is close, the main problem is in your execute:
/execute @a {Inventory:[{id:"minecraft:wool",Damage:11s}]} /scoreboard players set @a FlagCarrier 1
What this execute is doing is running scoreboard players set @a FlagCarrier 1
at the position of all players for which {Inventory:[{id:"minecraft:wool",Damage:11s}]}
matches. In other words, if one or more players have wool with damage value 11, the command block sets the FlagCarrier score for @a (every player in the server) to 1.
This can be simplified using just a /scoreboard
command that utilizes the appropriate NBT data:
/scoreboard players set @a FlagCarrier 1 {Inventory:[{id:"minecraft:wool",Damage:11s}]}
This sets the FlagCarrier score to 1 for all players that match that NBT (aka, all players that have that particular color of wool in their inventory).