From 505d3af95eef3e31fc4e011aacc3ba81b56973ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Dobi=C3=A1=C5=A1?= Date: Wed, 8 Feb 2023 10:51:19 +0100 Subject: [PATCH] Version 1.5 - 1.19.60 Patch --- manifest.json | 12 +++-------- scripts/main.js | 56 +++++++++++++++++++++++++------------------------ 2 files changed, 32 insertions(+), 36 deletions(-) diff --git a/manifest.json b/manifest.json index 547611d..eecf316 100644 --- a/manifest.json +++ b/manifest.json @@ -9,22 +9,16 @@ "description": "Make sure to move or else... you'll die! ยง9Made by PavelDobCZ23", "name": "Don't Stop Moving", "uuid": "e8720e7a-a0ba-4f1f-a085-1e3f1bef6ec4", - "version": [ 1, 4, 0 ], - "min_engine_version": [ 1, 19, 50 ] + "version": [ 1, 5, 0 ], + "min_engine_version": [ 1, 19, 60 ] }, "modules": [ - { - "description": "Don't Stop Moving [BP] - data module", - "type": "data", - "uuid": "7023c32d-c8e3-47d4-b14e-15dc01bf155e", - "version": [1, 4, 0] - }, { "description": "Don't Stop Moving [BP] - script module", "type": "script", "language": "javascript", "uuid": "039ce6f0-df97-488d-8633-f231b5ea234a", - "version": [1, 4, 0], + "version": [1, 5, 0], "entry": "scripts/main.js" } ], diff --git a/scripts/main.js b/scripts/main.js index 78b61b7..16b2c59 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -1,36 +1,38 @@ import {world,system} from "@minecraft/server"; import {timer} from "./modules/addon_options.js"; -var playerMovement = {}; +const playerMovement = {}; function randInt(min, max) { - max++; - return Math.floor(Math.random() * (max - min)) + min; + return Math.floor(Math.random() * (max - min + 1)) + min; } -async function tickEvent(eventData) { - system.run(tickEvent); - if (eventData.currentTick % 5 === 0) { - for (const player of world.getPlayers()) { - if (player.id in playerMovement) { - const velocity = player.velocity.x + player.velocity.z; - if ((-0.001 < velocity) && (velocity < 0.001) || playerMovement[player.id] < 0) { - if (playerMovement[player.id] === timer && eventData.currentTick % 20 === 0) { - try { - await player.runCommandAsync('damage @s 2'); - } catch {} - } - playerMovement[player.id] = Math.min(timer, playerMovement[player.id] + randInt(2,10)); - } else if (playerMovement[player.id] >= 0) { - playerMovement[player.id] = Math.max(0, playerMovement[player.id] - randInt(1,5)); - } - if (player.getComponent('minecraft:health').current === 0) { - playerMovement[player.id] = -20; - } - } else { - playerMovement[player.id] = -275; - } - } +//Calculate movement: +system.runSchedule(playerMovementTick,5); + +//Deal Damage: +system.runSchedule(playerDamageTick,20); + +function playerDamageTick() { + for (const player of world.getPlayers()) { + console.warn(`${player.name} [${playerMovement[player.id]}] - Damage`); + if (playerMovement[player.id] === timer) player.applyDamage(2); } } -system.run(tickEvent); \ No newline at end of file +function playerMovementTick() { + for (const player of world.getPlayers()) { + if (player.id in playerMovement) { + const velocity = player.velocity.x + player.velocity.z; + if ((-0.001 < velocity) && (velocity < 0.001) || playerMovement[player.id] < 0) { + playerMovement[player.id] = Math.min(timer, playerMovement[player.id] + randInt(2,10)); + } else if (playerMovement[player.id] >= 0) { + playerMovement[player.id] = Math.max(0, playerMovement[player.id] - randInt(1,5)); + } + if (player.getComponent('minecraft:health').current === 0) { + playerMovement[player.id] = -45; + } + } else { + playerMovement[player.id] = -275; + } + } +} \ No newline at end of file