#Detector [RESOLVED]
1 messages · Page 1 of 1 (latest)
import {
Player,
world
} from '@minecraft/server';
world.afterEvents.entitySpawn.subscribe(({
entity
}) => {
if (entity.typeId !== 'minecraft:arrow' || entity.typeId !== 'minecraft:trident') return;
const callback = world.afterEvents.projectileHitEntity.subscribe((arg) => {
const {
source,
projectile
} = arg;
const hitInfo = arg.getEntityHit();
if (hitInfo?.entity instanceof Player && source instanceof Player && projectile === entity) {
const soundOption = {
volume: 0.4,
pitch: 0.5,
}
source.playSound('random.orb', soundOption);
world.afterEvents.projectileHitEntity.unsubscribe(callback);
};
});
});
@proud gust
I was supposed to script it but thanks!
It was "projectileHitEntity"
U are welcome
Oh, where can I find that?
U can change hitInfo?.entity instanceof Player
To hitInfo?.entity.typeId == 'custom: entity'
Wait
Alright, thanks.
Suggestion for @proud gust
Debug result for [code](#1329063822958264363 message)
Compiler Result
Compiler found 1 errors:
[36m<REPL0>.js[0m:[33m9[0m:[33m48[0m - [31merror[0m[30m TS2367: [0mThis comparison appears to be unintentional because the types '"minecraft:arrow"' and '"minecraft:trident"' have no overlap.
[7m9[0m if (entity.typeId !== 'minecraft:arrow' || entity.typeId !== 'minecraft:trident') return;
[7m [0m [31m ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[0m
Lint Result
There are no errors from ESLint.
Ignore it
import { Player, world } from "@minecraft/server";
world.afterEvents.entitySpawn.subscribe(({ entity }) => {
if (entity.typeId !== 'minecraft:arrow' && entity.typeId !== 'minecraft:trident') return;
const callback = world.afterEvents.projectileHitEntity.subscribe((arg) => {
const { source, projectile } = arg;
const hitInfo = arg.getEntityHit();
if (hitInfo?.entity && source instanceof Player && projectile === entity) {
const soundOption = {
volume: 0.4,
pitch: 1.0,
};
source.playSound("random.orb", soundOption);
world.afterEvents.projectileHitEntity.unsubscribe(callback);
}
});
});```