#How can I detect when you use totem?

1 messages · Page 1 of 1 (latest)

formal jolt
#

How can I make that when a player uses totem (postmortal) a message appears with the person and the entity or thing that caused the damage?

pure gazelle
#

You can do this with only command, at least detect totem use but okay. You can use some things into the game. You detect when the player has the tótem in their inventory and store in a tag or scoreboard that it will works like a switch/powerON/OFF. Then when the totem isn't in player inventory you can deactivate or activate the tag/scoreboard player, testing if the totem isn't through or around the player or their inventory. All this can be inside a entityHurt or entityDie event.

edit: Excuse my bad english

formal jolt
pure gazelle
pure gazelle
drowsy scarab
#

there's about 5 consecutive events triggered in 2ms

#
  1. entityHurt: cause 'none'
    2,3,4. effectAdd: regen, absorption, fire res
  2. entityHurt: cause <anything that caused it>
#

gl arranging those XD

formal jolt
#

And how is that? Xd

drowsy scarab
# formal jolt And how is that? Xd

try this one

import { world,  Player } from "@minecraft/server";


world.events.entityHurt.subscribe(hurt => {
    const {
        damage,
        hurtEntity,
        damageSource: {
            cause, damagingEntity
        }
    } = hurt;
    if (damage > 0 || cause !== 'none' || !((damagingEntity ?? '') instanceof Player)) return;
    world.sendMessage(`${damagingEntity.name} popped ${hurtEntity}'s totem!`);
    //code

}, { entityTypes: ['minecraft:player'] })
drowsy scarab
formal jolt
#

No

drowsy scarab
#

do /damage

formal jolt
#

Does it only work if I die to some entity?

drowsy scarab
#

uhm it only works when the killer is player

#

but it can be changed to what u want

formal jolt
#

I put /damage @s 90 entity_attack entity @s but nothing appeared either xd

formal jolt
#

I'm using a translator and sometimes it doesn't translate well, sorry

drowsy scarab
# formal jolt Well, I just want it to detect who killed the player using totem
const { entityHurt } = world.events;

entityHurt.subscribe(hurt => {
    const {
        damage,
        hurtEntity,
        damageSource: {
            cause, damagingEntity
        }
    } = hurt;
    if (damage > 0 || cause !== 'none') return
    const evId = entityHurt.subscribe(hurt2 => {
        if (hurtEntity !== hurt2.hurtEntity) return
        const { cause, damagingEntity } = hurt2.damageSource;
        if (cause == 'none') return
        console.warn(`${damagingEntity?.name} popped ${hurtEntity.name}'s totem!`);
        entityHurt.unsubscribe(evId)
        //code
    }, { entityTypes: ['minecraft:player'] })
}, { entityTypes: ['minecraft:player'] })
sacred grail
royal echo
royal echo
#

@drowsy scarab sorry

drowsy scarab
maiden maple
#

I just implemented this in an addon to detect popped totems:

    //e.entity, e.oldValue, e.newValue    

    const inventory = e.entity.getComponent("minecraft:inventory").container;
    if (e.oldValue <= 0 && e.newValue > 0 && inventory.contains(new ItemStack("totem_of_undying", 1))) {
        //do the thing
    }
}, { entityTypes: ["minecraft:player"] });```
drowsy scarab
opal wolf
#

Well imma ask one thing, is it possible to detect death by commands
Using /kill, /damage, or any damaging/killing commands 🤔

#

Is the value "none" or smth else or is it just not possible

drowsy scarab
#

hmmm, good catch

#

dying in void also doesnt detect on my setup.
It's only designed for combat

#

hmm, the totem doesnt pop with those, i just tested

#

i did /kill detecting selfDestruct, but it just dropped my totem.
/damage @s void 40 also dropped the totem.
they didn't pop

opal wolf