#How to stop someone from dying when they would have been killed (with a certain weapon/tag)

1 messages · Page 1 of 1 (latest)

sly seal
#

i have a weapon that should run commands on someone when they are kill. However, given that they die, I can't do anything. How do i stop them from dying, or at least appear to do so? I can give more info if necessary.

fluid basin
#

Does the weapon actually need them to not die, or do you just need to run commands as them when they die?

#

Cause you can do the latter

stone raft
#

You could make the weapon have the totem of undying component and then just give the item back.

sly seal
#

I have misworded this, sorry! 😅 I meant to say that i need the person killed by the item not to die. There will be some special effects, then they will be put in spectator. Does anyone know if this is possible? I was thinking about setting immediate respawn to true really quickly then teleporting them to their death location.

fluid basin
#

In that case then yes as HeDeAn said, you can give the item a death_protection component so that it behaves like a totem of undying, and just detect when that gets used via an advancement to run a function that does whatever you need

sly seal
#

i

#

am the smartest man alive

#

i meant to say the person killed by the item

#

sorry again man

stone raft
#

You can do that with a custom enchantment. more specifically with the post_attack effect.
make the item deal 0 damage, and in the effect, target the hit player and run a function. That function compares the players health and how much damage it would deal. If the if the the damage would kill the player run a different function instead if it doesn't, just run a damage command.

#

This method has some slight drawbacks, like it can't easily increase the damage with sharpness or other enchantments unless you specifically program that in or the damage/health comparison can't easily calculate the targets armor protection and overall damage reduction.

frank onyx
#

Can't you detect the origin of death through advancement and target @s in the reward function ?

fluid basin
#

Yes, but they don't want or need to have the player die

sly seal
#

well doesn't that select the attacker and not the victim

#

because if not i may use that

sly seal
#

yeah no that is how it is

#

wait

#

how do you select the attacker in entity_killed_player?

frank onyx
#
{
    "criteria": {
        "a": {
            "trigger": "minecraft:entity_killed_player",
            "conditions": {
                "player": {},
                "entity": {},
                "killing_blow": {}
            }
        }
    }
}```
#

Attacker is under entity

sly seal
#

ah thank you!

#

i assume killing_blow is the weapon used?