#how to detect entity family?

1 messages · Page 1 of 1 (latest)

serene sun
#

I'm trying to do when a projectile from the "ritual" family hits an entity, it executes a command but the script doesn't work, what am I doing wrong?

sonic sierra
#

const ritualProjectiles = world.getDimension("overworld").getEntities({ families: ['ritual'] });

sonic sierra
#

const ritualProjectiles = data.dimension.getEntities({ families: ['ritual'] });
check this.

serene sun
#

it didn't work either

sonic sierra
#

try to display values, quantities or names in the console.

serene sun
#

what do you mean?

sonic sierra
#

console.warn(hitEntity.entity.nameTag);
console.warn(ritualProjectiles.length);

serene sun
#

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)]

sonic sierra
#

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.

serene sun
#

wich cosnt?

sonic sierra
#

let hitEntity

#

what version of the api?

#

try removing const world = server.world;
and change world to server.world

serene sun
#

the server is 1.8.0

sonic sierra
#

Exactly the same error?

serene sun
#

I removed
console.warn(hitEntity.entity.nameTag);
console.warn(ritualProjectiles.length);

And It didnt showed any errors

sonic sierra
#

==================================
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');
}

});

serene sun
#

no error, but it didn't work

sonic sierra
#

@magic spindle You can help?

#

/execute at @s as @s run function amaldicoar

#

try it

serene sun
#

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

sonic sierra
#

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');
}

});

serene sun
#

there was no error

sonic sierra
#

if (ritualProjectiles.includes(projectile)) {
let test = hitEntity.runCommand('/execute at @s as @s run function amaldicoar');
console.warn(test.successCount);
}

#

try it

#

or runCommandAsync

serene sun
#

Didnt work but there was no errors or warns

sonic sierra
#

I don't know what to do

#

okay, bye

serene sun
#

Bye

#

thank you for trying to help :D

stiff pilot
#
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

stiff pilot
#

@serene sun

serene sun
#

will try

serene sun
stiff pilot
#

Your projectile thing isn't an entity then

serene sun
#

Isn't a projectile an entity?

stiff pilot
#

It is

#

I don't know why the .matches doesn't work on that projectile entity

#

I am reading documentation rn

serene sun
#

Ok

serene sun
#

And if the script was working well, it wouldn't give an error even if there was something wrong in the entity, right?

stiff pilot
#

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

serene sun
#

[Scripting][error]-Plugin [project - 1.0.0] - [main.js] ran with error: [ReferenceError: 'projectile' is not defined at <anonymous> (amaldicoar.js:11)]

stiff pilot
#

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?

serene sun
#

No

#

Just that script

stiff pilot
#

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');
    }
});```
serene sun
#

[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)

stiff pilot
#

Add console.warn(projectile)

stiff pilot
#

@serene sun

serene sun
#

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)

stiff pilot
#

Yeah. Seems the projectile object simply doesn't exist in the projectileHitEntityEvent

serene sun
#

i also got this [Scripting][warning]-[object Object]

stiff pilot
#

Huh

#

Nvm

#

I genuenly don't know why it doesn't work for you.

#

It should.

#

But it doesn't

serene sun
#

is there something im not doing? like the entity has the family right is there anything more i need to do?

high wadi