find the damage source when player is attack in minecraftusing datapck
In Minecraft, the damage source when a player is attacked can be found using datapacks. Here's an example of how you can achieve this:
-
Create a new datapack by creating a new folder in the "datapacks" directory of your Minecraft world. Let's call it "DamageSourceDatapack".
-
Inside the "DamageSourceDatapack" folder, create the following directories: "DamageSourceDatapack/data/damage_source/functions".
-
In the "functions" directory, create a new text file called "attack.mcfunction".
-
Open the "attack.mcfunction" file and enter the following command to detect the damage source:
execute as @a at @s run say You were attacked by:
execute as @e[type=minecraft:player] at @s unless entity @a[distance=0..1] run say @s
This command will display the message "You were attacked by:" and then the name of the attacking player.
-
Save the file and exit.
-
Compress the "DamageSourceDatapack" folder into a .zip file.
-
Place the .zip file into the "datapacks" directory of your Minecraft world.
-
Load the world in Minecraft.
Now, whenever a player is attacked by another player, the message "You were attacked by: [Player Name]" will be displayed
原文地址: https://www.cveoy.top/t/topic/h6ka 著作权归作者所有。请勿转载和采集!