I'm not the most experienced person when it comes to commands. I worked out how to do stuff like when holding x you have y effect. I wanted to think of something that gave other people an effect when hit. Here is what I came up with but I got stuck when it said it couldn't execute the command.

/scoreboard objective add nokill dummy

/scoreboard objective add poi dummy

/scoreboard players set [player] nokill 1

/scoreboard players add @a poi 1 {SelectedItem:{id:minecraft:diamond_sword,display:{Name:{Poison sword}}}}

/execute @a[score_poi_min=1] ~ ~ ~ /effect @p[score_nokill_max=1,r=5] {HurtTime:1} minecraft:poison 10 1
  • 1
    Hmm... I don't actually think this is possible in Vanilla, but I'll investigate – Unionhawk Mar 8 '16 at 17:16
  • It looks like your third command is wrong. There's some other things that will also be needed. – MBraedley Mar 8 '16 at 17:23
  • I ment to say /scoreboard players set nokill [player] 1 – Karuki307 Mar 8 '16 at 17:39
  • Dragnoz has a video on this: m.youtube.com/watch?v=OC-fbKL7G2E – Roke Mar 8 '16 at 19:27
  • Nice use of the HurtTime tag. though! – rustphoenix Mar 10 '16 at 17:12

You can use the stat.damageDealt and stat.damageTaken objective-types to target players who have dealt and taken damage for multiplayer support.

The following assumes you're using the latest version, being 1.9.


Objective to track damage dealt.

/scoreboard objectives add Dealt stat.damageDealt

Objective to track damage taken.

/scoreboard objectives add Taken stat.damageTaken

Item to provide the player.

/give @p minecraft:diamond_sword 1 0 {display:{Name:"Poison sword"}}

Clock commands:

The following must be run in numerical order on a clock.

  1. Remove the label from players who were wielding the particular item in the event they are no longer holding it.

    /scoreboard players tag @a[tag=HoldingItem] remove HoldingItem
  2. Mark players who are wielding the desired item. Any tags that are not the root id, Damage, Count, and Slot will be placed within a single tag compound.

    /scoreboard players tag @a[tag=!HoldingItem] add HoldingItem {SelectedItem:{id:"minecraft:diamond_sword",tag:{display:{Name:"Poison sword"}}}}
  3. Cause players to are holding the sword and have dealt damage to inflict poison on the closest living player to them who has taken damage. Note, however, that targeting the actual player that was struck is impossible. There is nothing to state which player struck which player, short of guesswork via the auto-incrementing objectives. You may want to fiddle with the nested selector to fit your needs better.

    /execute @a[tag=HoldingItem,score_Dealt_min=1] ~ ~ ~ /effect @p[score_Taken_min=1,rm=0,r=6] minecraft:poison 10 1
  4. Reset player's "Dealt" and "Taken" scores for future detection.

    /scoreboard players reset @a[score_Dealt_min=1] Dealt
    /scoreboard players reset @a[score_Taken_min=1] Taken
| improve this answer | |
  • Thanks, very extremely helpful. But could you do this by replacing a few "@a" with "@e" for it to be able to poison all entity types, not just players? – Karuki307 Mar 9 '16 at 16:14
  • @Karuki307: Yeah, that shouldn't be a problem. The only thing that you really need to look out for is the execute command. In that, you'll want /effect @e[c=1,... to ensure that you get every relevant entity, but only execute the effect on the current entity. – MBraedley Mar 19 '16 at 2:34

Update: @Skylinerw has commented that this will bug on multiplayer. To fix this, just ad the team selector for each command and as long everyone has there own team, everything should be fine. You can always ally teams. For this example I am using team a called team. Also, instead of teams, you can use the tag [name=%%] where %% is the name.

Update: for a better reset machine, remove the torch and place a block in its spot than a repeater touching the comparator. Make sure to set the clock at its slowest speed (press 3 times) and is connected to the string of Redstone that connects to the final command block.

I have a different method to this. (This is an edit of Dragnoz's video's method)/

The first command block tests for an item. In this case, I used dragnoz's command:

/testfor @p[team=team] {SelectedItemSlot:0,Inventory:[{Slot:0b,tag:{display:{Name:"Poisoned Blade"}}}]}
/testfor @p[score_damage_min=1]  
/execute @p[score_damage_min=1,team=team] ~ ~ ~ effect @e[r=16,type=!Player,team=team] 2 13 2    

This is the effect command. You can customize it, but here I gave made it so that when I use the Poisoned Blade, all entities in a range of 16 except for players get effect 2 (slowness) for 13 seconds which is level 2.

enter image description here

The first three blocks to the left reset the comparators to off.
Then we have a clock running these commands 24/7
Then we have 1CB, followed by a comparator, 2CB followed by a comparator, 3CB, followed by a comparator.
Then at the end of the comparator we have a redstone string that inputs a signal to a redstone torch.
The redstone torch is connected to a wire of redstone which goes to a command block that resets the scoreboard (/scoreboard players set @p[score_damage_min=1] damage 0) so the command can operator more than one time.

You can do all sorts of stuff with the execute command, one of my favorite being that you when you replace the effect slowness with heal.

In a nutshell it tests if you are holding (in slot 0) A sword named Poisoned blade > then it tests if you have done damage > finally it executes a command (effect) and then resets the score for further use.

  • It should be noted that this does not support multiplayer due to the reliance on physical logic. – Skylinerw Mar 9 '16 at 3:05
  • Why are you using testfor? What purpose does it serve? This solution is just as multiplayer unfriendly as it was before, and half of the reason is the testfors, the other half is the comparators. There are much better ways! There are very few good reasons to use testfor, and this problem certainly isn't one. That's especially the case in multiplayer. – MBraedley Mar 18 '16 at 21:46
  • 1.8... I can't do 1.9 – Roke Mar 18 '16 at 23:15
  • @RookieTEC9: That still doesn't excuse the use of testfor. Even in 1.8, use of testfor should be considered deprecated, and it's use reserved for when it's truly the best option. That is not the case here. Don't use testfor! – MBraedley Mar 19 '16 at 2:23
  • 1
    I am criticizing your answer so that you can become a better command blocker. I am trying to help you. Really, I am. I want others to learn to use the best approaches and avoid the worst ones. You've done the opposite of that with this answer. Skylinerw's answer will work just as well in 1.8 as it does in 1.9; you just need to use a 20Hz clock. That is the better way. Given enough time, that's probably pretty close to the solution that I would come up with. I'm not going to write an answer to this question (and especially not for 1.8) because I can't write a better one than Skylinerw. – MBraedley Mar 19 '16 at 20:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.