From 51f73be6e5ffede635fcda1c19c5d553276f491e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Dobi=C3=A1=C5=A1?= Date: Sat, 26 Feb 2022 12:58:09 +0100 Subject: [PATCH] Timer now resets correctly when player dies. --- scripts/main.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/main.js b/scripts/main.js index 5e1bfe3..2c79c7d 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -14,18 +14,25 @@ function tickEvent (eventData) { for (const player of world.getPlayers()) { if (Object.keys(playerMovement).includes(player.name)) { const velocity = player.velocity.x + player.velocity.z; + //Not moving: if ((-0.001 < velocity) && (velocity < 0.001) || playerMovement[player.name] < 0) { if (playerMovement[player.name] === timer && eventData.currentTick % 20 === 0) { try { player.runCommand('damage @s 2'); } catch { - + } } playerMovement[player.name] = Math.min(timer, playerMovement[player.name] + randInt(2,10)); + //Moving: } else if (playerMovement[player.name] >= 0) { playerMovement[player.name] = Math.max(0, playerMovement[player.name] - randInt(1,5)); } + //Check if dead: + if (player.getComponent('minecraft:health').current === 0) { + playerMovement[player.name] = 0; + } + //Check if player just loaded: } else { playerMovement[player.name] = -275; }