forked from JaylyDev/ScriptAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (33 loc) · 1.47 KB
/
index.js
File metadata and controls
36 lines (33 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Script example for ScriptAPI
// Author: defowler2005 <https://github.com/defowler2005>
// Project: https://github.com/JaylyDev/ScriptAPI
/**
* Minecraft Bedrock ScriptAPI Example
* @license Do what ever you want
* @author defowler2005#4812
* @version 1.0.0
* ---------------------------------------------------------------------------
* This is a waitMove function, It logged the players x, y, z coordinates-
* with the player's current coordinates in aystem.runInterval(() => {});
* This is ideal for ui forms in chat commands!
* ---------------------------------------------------------------------------
*/
import { system } from '@minecraft/server';
/**
* Waits for the player to move and then executes a callback function.
* @param {Object} target - The target player to monitor for movement.
* @param {number} x - The initial X-coordinate of the target player.
* @param {number} y - The initial Y-coordinate of the target player.
* @param {number} z - The initial Z-coordinate of the target player.
* @param {Function} callback - The callback function to execute after the player moves.
*/
export function waitMove(target, x, y, z, callback) {
const t = new Map();
t.set(target, [x, y, z]);
system.runInterval(() => {
for (const [target, [xOld, yOld, zOld]] of t) {
const { x: xc, y: yc, z: zc } = target.location;
if (xOld !== xc || yOld !== yc || zOld !== zc) system.run(() => t.delete(target) || callback());
}
})
};