#1.6.0-beta (1.20.30) Entity runCommand on player target.
1 messages · Page 1 of 1 (latest)
import { world, system } from "@minecraft/server";
world.before.events.entityHit.subscribe(data => {
const npc = data.hitEntity;
const player = data.entity;
if (data.hitBlock) {
return;
}
if (npc.hasTag('tag')) {
player.runCommand('say test');
}
});```
I think its like this, I need to test
well that didn't seem to work.
import { world, system } from "@minecraft/server";
world.afterEvents.entityHitEntity.subscribe(data => {
const npc = data.hitEntity;
const player = data.damagingEntity;
if (npc.hasTag('tag')) {
player.runCommand('say test');
}
});```
import { world, system } from "@minecraft/server"
world.afterEvents.entityHitEntity.subscribe(ev => {
const { damagingEntity, hitEntity } = ev;
damagingEntity.runCommand('I ran something!');
});```
I figured out how to do it I think
I have to setup VSCode though
Installing the types would help a ton
import { world, system } from "@minecraft/server"
world.afterEvents.entityHitEntity.subscribe(ev => {
const { damagingEntity, hitEntity } = ev;
if (hitEntity.name === 'minecraft:pig') {
console.log(`Entity ${damagingEntity.name} hit a pig`);
damagingEntity.runCommand('say I hit a pig!');
}
});
for some reason this isn't working
When I hit a pig entity it should run the command as me, saying "I hit a pig"
1.6.0-beta (1.20.30) Entity runCommand on player target.
.typeId, not .name