Minecraft Datapack: Find Attacker's Name | Damage Source Detection
In Minecraft, you can use datapacks to determine the source of damage when a player is attacked. Here's a step-by-step guide: \n\n1. Create a new datapack folder named "DamageSourceDatapack" in your Minecraft world's "datapacks" directory.\n\n2. Inside the "DamageSourceDatapack" folder, create these directories: "DamageSourceDatapack/data/damage_source/functions".\n\n3. In the "functions" directory, create a text file named "attack.mcfunction".\n\n4. Open "attack.mcfunction" and add this command to detect the damage source: \n\nmcfunction\nexecute as @a at @s run say You were attacked by: \nexecute as @e[type=minecraft:player] at @s unless entity @a[distance=0..1] run say @s\n\n\nThis command will display "You were attacked by:" followed by the attacker's name.\n\n5. Save the file and exit.\n\n6. Zip the "DamageSourceDatapack" folder.\n\n7. Place the .zip file in your Minecraft world's "datapacks" directory.\n\n8. Load your world in Minecraft.\n\nNow, whenever a player is attacked by another player, you'll see the message "You were attacked by: [Player Name]".\n
原文地址: https://www.cveoy.top/t/topic/pPcm 著作权归作者所有。请勿转载和采集!