When you place a named block, it loses its name tag, making it impossible to detect if it was ever named. What you can do, however, is set a custom data value:
/setblock ~ ~ ~ diamond_block 1
Then, replace detect ~ ~-1 ~ diamond_block 0
with diamond_block 1
. You can use values 1 through 15, but values above 15 are not supported.
Note: In some versions of the game (and possibly the latest updates), blocks with custom data may have a missing texture, and the custom data may not be saved properly. You'll have to look into this yourself as I can't test it at the moment.
You'll need to "translate" the glass bottle data tag into something that works with target selectors (@a and so on). This can be achieved most easily using dummy scoreboard values or, in 1.9, scoreboard tags.
In 1.8, create an objective using
scoreboard objectives add bottleInOne dummy
Create a fill clock and run the following two commands
scoreboard players set @a[score_bottleInOne_min=1] bottleInOne 0
scoreboard players set @a[score_bottleInOne=0] bottleInOne 1 {SelectedItemSlot:0,SelectedItem:{id:minecraft:glass_bottle}}
If the team part is necessary, you can now add @a[score_bottleInOne_min=1]
to the team, and remove @a[score_bottleInOne=0]
from it, using the same fill clock. You could also use these target selectors directly for the /effect
and /replaceitem
commands, if the team part was just your idea of selecting that player for the effect.
In 1.9, you can omit the scoreboard objective in favor of tags. Using a Repeat/Chain command block chain, run
scoreboard players tag @a[tag=bottleInOne] remove bottleInOne
scoreboard players tag @a[tag=!bottleInOne] add bottleInOne {SelectedItemSlot:0,SelectedItem:{id:minecraft:glass_bottle}}
In the following commands, you can then use @a[tag=bottleInOne]
or @a[tag=!bottleInOne]
to target players with and without the bottle selected in slot 0, respectively.
Best Answer
You should use a dummy variable and target selector arguments.
Run once
Have a dummy score, call it
healthDif
.Run every tick, in order
Set each players
healthDif
score to their own health score:Subtract the other player's
healthDif
score from your own:Now players with a positive
healthDif
score will have more health than the other player. Target with @a[score_healthDif=1]Note this will only work for two players. In order for it to work with more, you have to take a few extra steps.
Run once
First you'll need a dummy variable to store miscellaneous variables. Call it
vars
. Note: If you already have a variable for this (you likely do), you can skip this step.Run every tick, in order
Put these between the two commands from before.
First, set the
#nplayers
to 0:Now, have each player increment
#nplayers
:Finally, multiply each players
healthDif
score by this numberThis way, you can have any amount of players, and the system automatically adapts!