#how to detect entity family?
1 messages · Page 1 of 1 (latest)
const ritualProjectiles = world.getDimension("overworld").getEntities({ families: ['ritual'] });
did not work
const ritualProjectiles = data.dimension.getEntities({ families: ['ritual'] });
check this.
it didn't work either
try to display values, quantities or names in the console.
what do you mean?
console.warn(hitEntity.entity.nameTag);
console.warn(ritualProjectiles.length);
gave me an error
[Scripting][error]-Plugin [project - 1.0.0] - [main.js] ran with error: [ReferenceError: 'hitEntity' is not defined at <anonymous> (amaldicoar.js:2)]
By the way, you need to put / in runCommand
and
change const to let.
(method) ProjectileHitEntityAfterEvent.getEntityHit(): mc.EntityHitInformation
@remarks — Contains additional information about an entity that was hit.
This function can't be called in read-only mode.
wich cosnt?
let hitEntity
what version of the api?
try removing const world = server.world;
and change world to server.world
Exactly the same error?
I removed
console.warn(hitEntity.entity.nameTag);
console.warn(ritualProjectiles.length);
And It didnt showed any errors
==================================
server.world.afterEvents.projectileHitEntity.subscribe(event => {
const hitEntity = event.getEntityHit().entity;
const projectile = event.projectile;
const ritualProjectiles = event.dimension.getEntities({
families: ['ritual']
});
if (ritualProjectiles.includes(projectile)) {
hitEntity.runCommand('/execute as @s run function amaldicoar');
}
});
no error, but it didn't work
I don't think it should be the command, I was changing this script to detect the entity's family and before it was working. But i Will try
Nope, didnt work
if console.warn(hitEntity.nameTag)
will give an error, then I don’t know what to do
i mean
==================================
server.world.afterEvents.projectileHitEntity.subscribe(event => {
const hitEntity = event.getEntityHit().entity;
const projectile = event.projectile;
console.warn(hitEntity.nameTag);
const ritualProjectiles = event.dimension.getEntities({
families: ['ritual']
});
if (ritualProjectiles.includes(projectile)) {
hitEntity.runCommand('/execute at @s as @s run function amaldicoar');
}
});
there was no error
if (ritualProjectiles.includes(projectile)) {
let test = hitEntity.runCommand('/execute at @s as @s run function amaldicoar');
console.warn(test.successCount);
}
try it
or runCommandAsync
Didnt work but there was no errors or warns
console.warn("amaldicoar.js 1 loaded");
import * as server from "@minecraft/server";
import * as ui from "@minecraft/server-ui";
const world = server.world;
world.afterEvents.projectileHitEntity.subscribe((data) => {
const hitEntity = data.getEntityHit();
const projectile = data.projectile;
if (projectile.matches({ families: ['ritual']})) {
hitEntity.entity.runCommand('execute as @s run function amaldicoar');
}
});```
Use .matches({ families: ['ritual']}) on the projectile entity
It returns ture or false if the entity matches the given EntityQueryOptions
@serene sun
will try
[Scripting][error]-Error: Failed to call function 'matches' at <anonymous> (amaldicoar.js:12)
Your projectile thing isn't an entity then
Isn't a projectile an entity?
It is
I don't know why the .matches doesn't work on that projectile entity
I am reading documentation rn
Ok
I don't think it must be something in the projectile, when I use other projectiles the script also gives the same error
And if the script was working well, it wouldn't give an error even if there was something wrong in the entity, right?
I don't see any reason it shouldn't work. If you add console.warn(projectile.typeId) what do you get in the console log?
Add it before the if statement
like this?
[Scripting][error]-Plugin [project - 1.0.0] - [main.js] ran with error: [ReferenceError: 'projectile' is not defined at <anonymous> (amaldicoar.js:11)]
Yeah something is wrong with the projectile object
It's not defined
Imma re write the file how I would write it and you try it then
It's the whole file right? You don't have any other code after that running and using the imports?
K
console.warn("amaldicoar.js 2 loaded");
import { world } from "@minecraft/server";
world.afterEvents.projectileHitEntity.subscribe(({ getEntityHit, projectile }) => {
const hitEntity = getEntityHit().entity;
if (projectile.matches({ families: ['ritual'] })) {
hitEntity.runCommandAsync('execute as @s run function amaldicoar');
}
});```
[Scripting][error]-ReferenceError: Native object bound to prototype does not exist. at <anonymous> (amaldicoar.js:7)
i remove the () from getEntityHit().entity and fixed it,
but now it give this error
[Scripting][error]-Error: Failed to call function 'matches' at <anonymous> (amaldicoar.js:9)
Add console.warn(projectile)
@serene sun
[Scripting][error]-Plugin [project - 1.0.0] - [main.js] ran with error: [ReferenceError: 'projectile' is not defined at <anonymous> (amaldicoar.js:2)]
oh wait, i put it behind if and it worked, but now it has this error:
[Scripting][error]-Error: Failed to call function 'matches' at <anonymous> (amaldicoar.js:9)
Yeah. Seems the projectile object simply doesn't exist in the projectileHitEntityEvent
i also got this [Scripting][warning]-[object Object]
Huh
Nvm
I genuenly don't know why it doesn't work for you.
It should.
But it doesn't
is there something im not doing? like the entity has the family right is there anything more i need to do?
You need the before event as when it is the after the projectile entity has already hit the block and despawned