#Random Outcomes
1 messages · Page 1 of 1 (latest)
please. 
or i need to get the structures with StructureManager, set a pool in 'const' then call the structures with math.fandom? 🤔
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
let me test it when ill back from the market
thanks it works bro UuuU
?but if I want an empty space for random fail?