#I need this to be executed in all entities...

1 messages · Page 1 of 1 (latest)

simple flax
#

[Scripting][error]-TypeError: not a function at <anonymous> (Main.js:11)

#

The getAllEntities that is throwing the error

#

I've tried before but I'll look again

#

It says that the entity is undefined

#

Expects 1 argument and receives 0

devout socket
simple flax
#

Do I have to do it with all dimensions?

devout socket
simple flax
#

Yep

#

I need all dimensions

#
system.runInterval(() => {
    for (let entity of world.getDimension('overworld').getEntities()) {
        const cd = world.scoreboard.getObjective('ptw_atk_cd');

        if (cd.getScore(entity) > 0) {
            cd.addScore(entity, -1);
            entity.addEffect("weakness", 3, { amplifier: 3, showParticles: false });
            entity.addEffect("mining_fatigue", 3, { amplifier: 4, showParticles: false });
        }
    };
});
#

Is correct?

#

Did not work

#

[Scripting][error]-Error: Failed to resolve identity for '' at <anonymous> (Main.js:14)

devout socket
# simple flax I need all dimensions
import {world,World,system} from '@minecraft/server';

World.prototype.getAllEntities = function (){
const dimensionAll = ["overworld","nether","the end"].map(dimension=>world.getDimension(dimension))
return [...dimensionAll[0].getEntities(),...dimensionAll[1].getEntities(),...dimensionAll[2].getEntities()]
}
console.warn("Running");

system.run(() => {
    world.scoreboard.getObjective("ptw_atk_cd") ?? world.scoreboard.addObjective("ptw_atk_cd", "attack_cooldown");
});

system.runInterval(() => {
    for (let entity of world.getAllEntities()) {
        const cd = world.scoreboard.getObjective('ptw_atk_cd');

        if (cd.getScore(entity) > 0) {
            console.log("Applying effects to entity");
            cd.addScore(entity, -1);
            entity.addEffect("weakness", 3, { amplifier: 3, showParticles: false });
            entity.addEffect("mining_fatigue", 3, { amplifier: 4, showParticles: false });
        }
    }
});
simple flax
#

[Scripting][error]-Error: Failed to resolve identity for '' at <anonymous> (Main.js:17)

#
 if (cd.getScore(entity) > 0)```
#

Line 17

analog pebble
#

if you explain what this "code" should do i could maybe help

simple flax
#

...

#

It creates a scoreboard if it doesn't exist. Then, if the player's score is greater than 0, it reduces it by 1 and applies the weakness and fatigue effect.

#

This code works for players, but I want it to work for other entities too.

devout socket