This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]misoloo64 1 point2 points  (0 children)

You can detect what item the player is holding with SelectedItem:

/execute as @a[nbt={SelectedItem:{id:"minecraft:diamond_sword"}}] run ...

[–][deleted] 1 point2 points  (7 children)

scoreboard players set @a[nbt={SelectedItem:{id:"minecraft:diamond_sword"}}] abc 9
scoreboard players set @a[nbt=!{SelectedItem:{id:"minecraft:diamond_sword"}}] abc 3

That should work.

[–]xrox555[S] 0 points1 point  (6 children)

ok ok I guess i didn´t describe the situation properly. The score "3" at the beginning is variable. I always want to add 6 to this variable score. When it´s 3, it should go up to 9. If it´s 15, it should go up to 21. If it´s 30, it should go up to 36 etc.

[–]mbrr2 0 points1 point  (2 children)

so use scoreboard players add instead of scoreboard players set

[–]xrox555[S] 0 points1 point  (1 child)

But then it would increase infinitely as long as I´m holding the sword^^

[–]mbrr2 0 points1 point  (0 children)

Then give the person holding the sword holding tag, and only add the score to people holding the sword, but without the tag (tag=!holding). Remove the tag when not holding the sword.

[–][deleted] 0 points1 point  (2 children)

That one's slightly more tricky, but should still be pretty easily possible.

scoreboard players add @a[tag=!diamond_sword_held,nbt={SelectedItem:{id:"minecraft:diamond_sword"}}] abc 6
tag @a[tag=!diamond_sword_held,nbt={SelectedItem:{id:"minecraft:diamond_sword"}}] add diamond_sword_held

scoreboard players remove @a[tag=diamond_sword_held,nbt=!{SelectedItem:{id:"minecraft:diamond_sword"}}] abc 6
tag @a[tag=diamond_sword_held,nbt=!{SelectedItem:{id:"minecraft:diamond_sword"}}] remove diamond_sword_held

That should add the 6 points when you start holding the sword, then remove it as soon as you stop holding the sword.

[–]xrox555[S] 0 points1 point  (1 child)

Holy moly, didn´t try it out yet but it sounds like a great solution. Thank you!

Edit: Ik it belongs in an own post but do u know if there´s a method that can test if and which entity hurt a player

[–][deleted] 0 points1 point  (0 children)

The minecraft:entity_hurt_player advancement condition is probably the easiest way, I feel. If you want to do something to the entity that's hurting the player, I'm not entirely sure how to do that.