Skip to content

Commit

Permalink
Timer now resets correctly when player dies.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Dobiáš authored Feb 26, 2022
1 parent 4ce73b0 commit 51f73be
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 51f73be

Please sign in to comment.