#Help on detecting effects, how to use.

1 messages · Page 1 of 1 (latest)

amber anchor
#

I have the image which works like this
take the dimension
take the entities in that dimension
get the effects of all entity

if all entity has invisibility effect it will trigger "something"

ancient hearth
#

not valid

#
if (entity.getEffect('invisibility')) {
    console.warn('Entity: ' + entity.typeId + ' is invisible');
};
#
import { system, world } from "@minecraft/server";

function onTick() {
    const allDimensions = [ 'overworld', 'nether', 'the_end' ];
    for (const dimension of allDimensions) {
        const entities = world.getDimension(dimension).getEntities();
        for (const entity of entities) {
            if (entity.getEffect('invisibility')) {
                console.warn('Entity: ' + entity.typeId + ' is invisible');
            };
        };
    };
};

system.runInterval(onTick);
amber anchor
#

wait

#

ima try what you sent me

#

what does this line means?

for (const dimension of allDimensions)```
ancient hearth
#

Unless ur trying to get entities in a single dimension (overworld), you need that

amber anchor
#

@ancient hearth thanks A lot man

#

it works now

#

I am still bad at assigning things in JS cause im new

#

I now understand why they say Lua is a easy language

#

I have question though why

const allDimensions = [ 'overworld', 'nether', 'the_end' ];
    for (const dimension of allDimensions) 

do this?
assigning a constant to a constant? im a bit confused and it's using a for loop, why?

#

can you enlighten me about it?

ancient hearth
ancient hearth
#

you can skip this if you don't want ur script to function in nether or the end, in that u can simply just do this:

const entities = world.getDimension('overworld').getEntities();
for (const entity of entities) {
    if (entity.getEffect('invisibility')) {
        console.warn('Entity: ' + entity.typeId + ' is invisible');
    };
};
amber anchor
ancient hearth
amber anchor
#

so the reason you've got to put the array in a variable because you can't assign that array to the getDimenstion() function?

amber anchor
#

I kind of get how it works now