#Random Outcomes

1 messages · Page 1 of 1 (latest)

outer gulch
#

hi! How can I set a possible outcomes from a pool of different options? like if randomly I want to set One tree or Another, how do I need to do it? I know that Math.random() can help me, but I don't know how to do the list...

#

please. bao_bee_happy

#

or i need to get the structures with StructureManager, set a pool in 'const' then call the structures with math.fandom? 🤔

hollow olive
#

Not verified by myself

#

Oops

#

One sec

#
import { EquipmentSlot, GameMode, world, Block, Structure, StructureManager } from "@minecraft/server";

const before = world.beforeEvents;
const beforeInitialize = before.worldInitialize;

beforeInitialize.subscribe(({ blockComponentRegistry }) =>
    blockComponentRegistry.registerCustomComponent(
        "aliien:tree_event", TreeComponent
    )
);

const TreeComponent = {
    onPlayerInteract({ block, player }) {
        const setStructure = world.structureManager;
        const dimension = player.dimension;
        const { location: { x, y, z } } = block;

        // List of possible tree structures
        const treeOptions = ['tree_1', 'tree_2', 'tree_3'];

        // Randomly select one tree from the list
        const randomTree = treeOptions[Math.floor(Math.random() * treeOptions.length)];

        // Place the selected tree
        setStructure.place(randomTree, dimension, { x: x - 1, y: y, z: z - 1 });
    }
};```
#

Notice using the length, and that's how you basically choose from the list, 0,1,2 etx

outer gulch
#

let me test it when ill back from the market

outer gulch
#

thanks it works bro UuuU

outer gulch
#

?but if I want an empty space for random fail?