#Having Trouble Detecting Damage
1 messages · Page 1 of 1 (latest)
Get the time in-between hits with a map
ok i will try that, thanks
i used a map to store their health and check if it changed so that works, but i also want to beable to get the damage source, like if a player uses fire aspect, i will get the owner of the damage source, is that possible?
thank you
Man
mc.world.afterEvents.entityHitEntity.subscribe(async (entityHit) => {
const
player = entityHit.damagingEntity,
target = entityHit.hitEntity;
} )
sorry im new to addon scripting, but yes thats the one i was having issues with, entityHurt is what i was looking for
This is already a ready system
As you can see, there is the player and the target
Target is the entity that receives the damage
yes but it detects when the player hits the entity and i only want to detect damaging or hurting the entity
And the player is the entity that deals the damage
What are you trying to do?
make a hit detection for zombies so i can add points
i got it now, thanks
Do you want me to detect zombie attacks on the player?
Or do you want me to detect the player's attacks on a zombie?
im trying to have it so when the player damages or kills the zombie it will add points
i think i got it working now tho
@cosmic socket
mc.world.afterEvents.entityHurt.subscribe(event => {
const hurtEntity = event.hurtEntity, hitEntity = event.damageSource, damage = event.damage
if (hurtEntity.typeId == "minecraft:zombie" || hurtEntity.typeId == "minecraft:piglin" || hurtEntity.typeId == "minecraft:husk" || hurtEntity.typeId == "minecraft:drowned") {
player.runCommandAsync('scoreboard players add @s ssak_score 1')
}
} )
Generally, people asking for help want to see what the code should look like, especially if that person is a beginner.
im not new to scripting, just minecrafts api
Just sending a link to what the person wants doesn't help much...
Even if you already have a sense of scripting, the Minecraft API works in specific ways
Just the math is very similar
ive been messing with it all day, i think i got the gist of interacting with entities
and world events
Use this, it will solve your problem, if you want to add points when the player reaches the entities inside the if
I never had the patience to read the documentation present at Microsoft 😄
thats pretty much what i was doing in the hitEntity event
i couldnt find any vids on the scripting api so i decided to try to learn from the docs
this is what i was doing before
world.afterEvents.entityHitEntity.subscribe(async event => {
const player = event.damagingEntity;
const target = event.hitEntity;
const targId = target.id;
const playerName = player.name;
const targName = format(target.typeId);
const targHealth = target.getComponent(EntityComponentTypes.Health).currentValue;
world.sendMessage(playerName + ' hit ' + targName);
if (player.typeId === item('player') && targName === "Zombie"){
if (targHealth === 0) {
if (zedHealthMap.has(targId)) {
if (zedHealthMap.get(targId)) {
player.runCommandAsync('scoreboard players add @s points 200');
zedHealthMap.delete(targId);
}
}
}else{
if (zedHealthMap.get(targId) !== targHealth){
player.runCommandAsync('scoreboard players add @s points 10');
}
zedHealthMap.set(targId, targHealth);
}
}
});
world.afterEvents.entityDie.subscribe(event => {
const entity = event.deadEntity.id;
if (zedHealthMap.has(entity)){
if (zedHealthMap.get(entity)){
zedHealthMap.delete(entity);
}
}
});```
If you need more help with this, you can call me