1

I'm trying to direct /execute to the location of a player who is holding a specific item. In this case, an item with the name "Gun". This is the script I'm trying to use:

/execute @e {SelectedItem:{tag:{display:{Name:"Firestarter"}}}} ~ ~ ~ 
/summon Fireball ~ ~ ~ {ExplosionPower:0,direction:[0.0,0.0,0.0]}

Unfortunately, this doesn't work. I've compiled the script from two working scripts:

/execute @p ~ ~ ~ 
/summon Fireball ~ ~ ~ {ExplosionPower:0,direction:[0.0,0.0,0.0]}

and

/testfor @e {SelectedItem:{tag:{display:{Name:"Gun"}}}}

Does anyone know how to put these together? The output of the command block is "that entity cannot be found"

1
  • In the first command, the name of the item is Firestarter. Therein may lie the problem, because you said you wanted an item named Gun. Mar 16, 2016 at 16:41

5 Answers 5

4

Contrary to other commands, like testfor, the execute command does not support data tag matching. The syntax is:

execute <entity> <x> <y> <z> <command …> 

Luckily, you can turn data tag matching into a scoreboard objective, as detailed in this answer. Set up a scoreboard objective using

scoreboard objectives add hasGun dummy

Create a fast clock (setblock/fill clock recommended), and run the following two commands (at the same time, but in this order!):

scoreboard players set @a hasGun 0
scoreboard players set @a hasGun 1 {SelectedItem:{tag:{display:{Name:"Firestarter"}}}}

You can now use this this objective in a target selector, such as

execute @a[score_hasGun_min=1] ~ ~ ~ summon Fireball ~ ~ ~ {ExplosionPower:0,direction:[0.0,0.0,0.0]}
0

I know I'm a little late to the party, but I would use snowballs as a gun, retexture them to look like a weapon, then instantly summon a snowball at that snowball's location- the snowball will give the fireball it's exact momentum before being deleted. First off, put into the chat this command:

/scoreboard objectives add holding.gun dummy

Then, attach these commands to a repeating/chain command block string (in order)

/scoreboard players set @a holding.gun 2 {SelectedItem:{id:snowball,tag:{put any other NBT tags in here}}}

/scoreboard player remove @a[score_holding.gun_min=1] holding.gun 1

/execute @a[score_holding.gun_min=1] ~ ~ ~ execute @e[type=Snowball,tag=!snowball,r=2] ~ ~ ~ summon Fireball ~ ~ ~ {ExplosionPower:0,direction:[0.0,0.0,0.0]}

/scoreboard players tag @e[type=Snowball] add snowball

0

Actually, to testfor yourself holding a certain item, all you need is one command block with the following command (for example, we can test for ourself holding an arrow)

/testfor @e[type=Player] {SelectedItem:{id:"minecraft:arrow"}}
-1

The execute command sadly does not support data tags, but can be matched up with a test for command block on a repeater clock with a secondary command of /summon, or so put as

/testfor @a {SelectedItem:{tag:{display:{Name:"Firestarter"}}}}

, then do

/summon Fireball ~ ~ ~ {ExplosionPower:0,direction:[0.0,0.0,0.0]}

You can also add particles to make it more detailed, or setblock to fire like this:

/setblock ~1 ~ ~ fire 

with the /testfor command, and do this:

/execute @e[type=Fireball] ~ ~ ~ /particle <Particle Name> ~ ~ ~ 0.25 0.25 0.25 <Speed> <Count> 

,although 0.25 can be replaced with how many blocks away from the fireball the particles can reach. You can also do:

/execute @e[type=Fireball] ~ ~ ~ /setblock ~ ~-1 ~ fire

to set the block below the fire charge on fire.

2
  • Putting commands in Pre-Formatted Text, the {} button, makes the commands more readable.
    – Moddl
    Mar 30, 2016 at 5:46
  • This solution will check, if any player holding the gun exists, and if, it will summon fireball on commandblock location. Not really working as expected, I would say. Mar 30, 2016 at 10:40
-2

This is what you need to do...

/testfor @e {SelectedItem:{tag:{Display{Name: "Firestarter"}}}}
/execute @e {SelectedItem:{tag:{Display{Name: "Firestarter"}}}} ~ ~ ~
/summon Fireball ~ ~ ~ {ExplosionPower0,direction:[0.0,0.0,0.0]}

That should work :)

2
  • 1
    The first command works, but does absolutely nothing on its own. The second command is absolutely wrong. execute does not support a data tag, and it's missing a command to execute in the first place.
    – MrLemon
    Aug 18, 2015 at 12:41
  • Oh okay, thank you for telling me that. I will keep this in mind when I am trying to make a One Command thingy :) Aug 24, 2015 at 2:44

Not the answer you're looking for? Browse other questions tagged .