const database = new Map();
world.afterEvents.entityHitEntity.subscribe(({ hitEntity, damagingEntity: entity }) => {
const health = hitEntity.getComponent("minecraft:health");
const mobs = ['minecraft:cow'];
if (health.currentValue > 0 || !mobs.includes(hitEntity.typeId)) return;
const entityData = (database.get(entity.name) ?? []);
if (!entityData.includes(hitEntity.typeId)) {
entityData.push(hitEntity.typeId);
database.set(entity.name, entityData);
}
});
function PlayersMenu(player) {
const data = database.get(player.name) ?? [];
const form = new ActionFormData();
form.title('Something');
form.body('Select an entity:');
form.button('Back');
for (const entityId of data) {
form.button(entityId.replace('minecraft:', ''));
}
form.show(player).then((r) => {
if (r.canceled) return;
const response = r.selection;
switch (response) {
case 0:
StatisticsMenu(player);
break;
default:
}
})
}
I want to make the buttons created using "for" into a "dynamic property" so that the buttons are not deleted after exiting the world.