1
(Solved) Detect Attack Damage of Held Item?
In my Data Pack, I want to make it so if the Player holds an item with an Attack Damage 8 or greater, (like a Netherite Sword), then they will be given an advancement.
But I can't seem to figure it out, here's my command below in case I am doing something wrong:
/execute as @a[nbt={SelectedItem:{tag:{AttributeModifiers:[{AttributeName:"generic.attack_damage",Amount:7s,Operation:0,UUID:[I;0,0,0,0]}]}}}] run execute as @s[nbt={SelectedItem:{tag:{AttributeModifiers:[{AttributeName:"generic.attack_damage",Amount:8s..}]}}}] run advancement grant @s only minecraft:story/mine_stone
P.S, I am just using Stone Age as a placeholder to see if this even works.
If someone could make a single function/command that would accomplish this, that would be great!
Any help would be greatly appreciated!
EDIT: This problem has already been solved! If you want the solution for yourself, you can go down in the comments to the one before my latest one, and that comment by mega7 will contain the answer.
But I can't seem to figure it out, here's my command below in case I am doing something wrong:
/execute as @a[nbt={SelectedItem:{tag:{AttributeModifiers:[{AttributeName:"generic.attack_damage",Amount:7s,Operation:0,UUID:[I;0,0,0,0]}]}}}] run execute as @s[nbt={SelectedItem:{tag:{AttributeModifiers:[{AttributeName:"generic.attack_damage",Amount:8s..}]}}}] run advancement grant @s only minecraft:story/mine_stone
P.S, I am just using Stone Age as a placeholder to see if this even works.
If someone could make a single function/command that would accomplish this, that would be great!
Any help would be greatly appreciated!
EDIT: This problem has already been solved! If you want the solution for yourself, you can go down in the comments to the one before my latest one, and that comment by mega7 will contain the answer.
Create an account or sign in to comment.
5
1
Perhaps you could run an execute result to a command that gets the value of the attack damage attribute of held item. and store it into a scoreboard. Then execute if it is above 8 it gives you the advancement.
I think you could even achieve that with one advancement if i'm correct.
If i have time today i'll send you the commands.
I think you could even achieve that with one advancement if i'm correct.
If i have time today i'll send you the commands.
1
Yeah you can't do it with advancement alone. Use the way i provided first.
3
Make a function and name it for example. "attack_damage_detector.mcfunction" or whatever you want.
Create a scoreboard objective and make it a dummy in load.mcfunction,
Put those three in the attack_damage_detector function:
execute store result score @s dummy_score_you_made run attribute @s generic.attack_damage get
execute if score @s dummy_score_you_made matches 8.. run advancement grant @s only (your advancement)
scoreboard players reset @s dummy_score_you_made
And make a command in tick.mcfunction that runs this function repeatedly for any person without your advancement.
Would look something like this:
execute as @a[advancements={namespace:advancement_location=false}] run function namespace:attack_damage_detector
Note that you can put the location of the files whereever you want just don't forget to put its right directory
Create a scoreboard objective and make it a dummy in load.mcfunction,
Put those three in the attack_damage_detector function:
execute store result score @s dummy_score_you_made run attribute @s generic.attack_damage get
execute if score @s dummy_score_you_made matches 8.. run advancement grant @s only (your advancement)
scoreboard players reset @s dummy_score_you_made
And make a command in tick.mcfunction that runs this function repeatedly for any person without your advancement.
Would look something like this:
execute as @a[advancements={namespace:advancement_location=false}] run function namespace:attack_damage_detector
Note that you can put the location of the files whereever you want just don't forget to put its right directory
2
Thank you so much! This worked so well!
1
Glad it worked thumb_up_alt