import { world, system, Player } from "@minecraft/server";
const previousHearts = new Map();
function her() {
const players = world.getPlayers();
for (const player of players) {
const health = player.getComponent('health').currentValue;
const currentHearts = health / 2;
const playerId = player.id;
const prevHearts = previousHearts.get(playerId) || currentHearts;
player.runCommandAsync(`title @s actionbar ❤ ${currentHearts.toFixed(1)}`);
if (prevHearts > 6.0 && currentHearts <= 6.0) {
player.runCommandAsync(`tellraw @s {"rawtext":[{"text":"§cВнимание! Жизней становится меньше (6.0 сердец)"}]}`);
}
else if (prevHearts > 3.0 && currentHearts <= 3.0) {
player.runCommandAsync(`tellraw @s {"rawtext":[{"text":"§4Тревога! Сердец осталось мало (3.0 сердца)"}]}`);
}
else if (prevHearts > 1.0 && currentHearts <= 1.0) {
player.runCommandAsync(`tellraw @s {"rawtext":[{"text":"§4§lКРИТИЧЕСКИ! Осталось всего 1.0 сердце!"}]}`);
}
previousHearts.set(playerId, currentHearts);
}
}
system.runInterval(her); Post #51
121
Показатель сердец