@p
targets the closest player so will only find 1 player each time, even if more are within the radius you have given.
@a
targets all players with the arguments given, so should work for either of the methods you are trying.
You have to use a command to apply a label to the player based on their data rather than using /testfor
. For example, /scoreboard
can assign a label:
/scoreboard players tag @a[tag=HasItem] remove HasItem
/scoreboard players tag @a[tag=!HasItem] add HasItem {SelectedItemSlot:0,Inventory:[{Slot:0b,tag:{display:{Name:"Fire Wand"}}}]}
And you'd then target players based on their label. The correct tag for fireball damage is ExplosionPower
:
/execute @a[tag=HasItem] ~ ~ ~ /summon Fireball ~2 ~1 ~ {ExplosionPower:10,direction:[0.0,0.0,0.0]}
If using 1.8, you will have to use a score instead. Objective to create:
/scoreboard objectives add HasItem dummy
Commands to run for labeling:
/scoreboard players set @a HasItem 0
/scoreboard players set @a HasItem 1 {SelectedItem:{tag:{display:{Name:"Fire Wand"}}}}
And for targeting, you'd use the score
parameter:
/execute @a[score_HasItem_min=1] ~ ~ ~ /summon Fireball ~2 ~1 ~ {ExplosionPower:10,direction:[0.0,0.0,0.0]}
You may be interested in the SelectedItem
compound, which holds a copy of the player's currently-held item. This way you do not need to specifically test each individual hotbar slot:
/scoreboard players tag @a[tag=!HasItem] add HasItem {SelectedItem:{tag:{display:{Name:"Fire Wand"}}}}
Best Answer
Thanks to bco2135 in comments for starting to steer me in the right direction. Thanks to their suggestion to leverage
scoreboard
and customized objective tracking that way, this has allowed me to get limited execution on items in a single command block properly. There's follow-up for me to do here in additional questions, but at least the first part is handled here.Effectively, I have to do the following (assumes: cheats and op mode):
Add a dummy objective I want to track
Use an always active command block to add 0 to all players (effective on join) for this objective
Use an
execute if entity
conditional in the command block able to be triggered by a button:... specifying of course the command to execute when this is true.