#How can I detect when you use totem?
1 messages · Page 1 of 1 (latest)
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
Are you Spanish?
The language
But isn't there a way to detect what was the cause?
Yes, but I am from LATAM
Not at all, but you can an aproximate
cause is "none"
there's about 5 consecutive events triggered in 2ms
- entityHurt: cause 'none'
2,3,4. effectAdd: regen, absorption, fire res- entityHurt: cause <anything that caused it>
gl arranging those XD
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'] })
nothing appeared
did a player killed aplayer?
No
do /damage
Does it only work if I die to some entity?
I put /damage @s 90 entity_attack entity @s but nothing appeared either xd
Well, I just want it to detect who killed the player using totem
I'm using a translator and sometimes it doesn't translate well, sorry
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'] })
is there any documentation for such niche information? or do you only know these through testing
Testing
how to make it detect your Name when you lost your totem or using it a message appear for all players in main hand and off hand ?
@drowsy scarab sorry
ima just leave this here https://discord.com/channels/523663022053392405/1403780060623802478
someone must help
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"] });```
where to get who popped the totem
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
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
Maybe the game just refuses