Is there a way to make a sword strike an enemy with lightning when hit?
Is there like a command that can strike a mob or player or both with lightning when hit with a sword? If so super cool, if not :( too bad either way thanks! Unfortunately I have no idea what you guys are talking about I'm not able to speak the language you have answered my question in sorry when your able to speak in English please let me know thanks again :)
Best Answer
The "stat.useItem" objective-type can track when a player deals damage with a sword. Unfortunately there are some complications with targeting the struck mob. There isn't really any data to use, apart from guesswork with "HurtTime" tag that will change once the mob is struck, but that doesn't necessarily mean the mob was struck by that player in that instance. The fire damage from lightning itself may cause issues.
As such, the following set of commands (for 1.8.8.) will try to spawn lightning as accurately as possible, but just be aware that it's not possible to be perfectly accurate.
Prerequisites
Objective that automatically increases when a player hits an enemy with a diamond sword.
/scoreboard objectives add UseSword stat.useItem.minecraft.diamond_sword
Objective to track when a mob was struck via "HurtTime".
/scoreboard objectives add MobStruck dummy
Clock Commands
The following must be run in numerical order on a 20-tick-per-second clock.
First, reset the "MobStruck" score for relevant mobs. Using a straight @e will cause the /scoreboard command to be processed equal to the number of all entities, so it's not recommended to do that. This example will affect creepers and zombies only, so you may add more. This sets their score to 0 just before "HurtTime" hits 0, just to reduce command output.
/scoreboard players set @e[type=Creeper] MobStruck 0 {HurtTime:1s} /scoreboard players set @e[type=Zombie] MobStruck 0 {HurtTime:1s}Label mobs who were recently struck. "HurtTime" will be set to 10 when the mob is struck, and then decrease by 1 per tick until it reaches 0 again. This is why a 20t/s clock is required.
/scoreboard players set @e[type=Creeper] MobStruck 1 {HurtTime:10s} /scoreboard players set @e[type=Zombie] MobStruck 1 {HurtTime:10s}Cause players who have used their diamond sword to strike the relevant mobs within a 10-block radius (which you may change).
/execute @a[score_UseSword_min=1] ~ ~ ~ execute @e[score_MobStruck_min=1,r=10] ~ ~ ~ summon LightningBoltAnd finally, reset the "UseSword" score for players that have used their sword.
/scoreboard players set @a[score_UseSword_min=1] UseSword 0
Pictures about "Is there a way to make a sword strike an enemy with lightning when hit?"



How do you make lightning strike when you hit something in Minecraft?
You can summon a lightning bolt whenever you want using a cheat (game command) in Minecraft. This is done using the /summon command. Lightning bolts can be used to turn mobs into witches, zombie pigmen, or charged creepers.Dragon Lightning is OVERPOWERED - How to One Shot Bosses - Best Elden Ring Incantation Faith Build!
More answers regarding is there a way to make a sword strike an enemy with lightning when hit?
Answer 2
nah that a more great way to do that first do /scoreboard objectives add hold dummy /scoreboard players set @a hold 1 {SelectedItem:{tag}} /scoreboard players set @a hold 0 /scoreboard objectives add strike stat.damageDealt /scoreboard players set @a strike 0 /execute @a[score_hold_min=1,score_strike_min=1] ~ ~ ~ execute @e[rm=1,r=10] ~ ~ ~ summon LightningBolt use all of this with clock and this is lemon teach me XD
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Hector Perez, Heorhii Heorhiichuk, Philippe Donn, Andre Furtado
