Skip to content

Commit e42e514

Browse files
Added New wait-move Script (JaylyDev#259)
* Create index.js Added New wait-move Script * Create README.md * Merge branch 'main' into pr/259 * Update jsconfig.json * Update index.js
1 parent 05eb60e commit e42e514

2 files changed

Lines changed: 92 additions & 0 deletions

File tree

scripts/wait-move/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# wait-move
2+
3+
## Description
4+
5+
When a wait-move is set, it will run code once the player has moved.
6+
7+
**Parameters:**
8+
9+
- `player` (type: Player or entity): The player or entity for which the function will be executed on.
10+
11+
- `x` (type: number): The X-coordinate of the destination of the player's current location.
12+
13+
- `y` (type: number): The Y-coordinate of the destination of the player's current location.
14+
15+
- `z` (type: number): The Z-coordinate of the destination of the player's current location.
16+
17+
- `callback` (type: function): The callback function to be executed once the player has moved.
18+
19+
**Example:**
20+
21+
```js
22+
23+
waitMove(player, x, y, z, (target) => {
24+
25+
target.sendMessage('You have moved!');
26+
27+
});
28+
29+
```
30+
31+
## Credits
32+
33+
These scripts were written by [defowler2005](https://github.com/defowler2005).

scripts/wait-move/index.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Script example for ScriptAPI
2+
// Author: defowler2005 <https://github.com/defowler2005>
3+
// Project: https://github.com/JaylyDev/ScriptAPI
4+
/**
5+
6+
* Minecraft Bedrock ScriptAPI Example
7+
8+
* @license Do what ever you want
9+
10+
* @author defowler2005#4812
11+
12+
* @version 1.0.0
13+
14+
* ---------------------------------------------------------------------------
15+
16+
* This is a waitMove function, It logged the players x, y, z coordinates-
17+
18+
* with the player's current coordinates in aystem.runInterval(() => {});
19+
20+
* This is ideal for ui forms in chat commands!
21+
22+
* ---------------------------------------------------------------------------
23+
24+
*/
25+
26+
import { world, system, Entity } from '@minecraft/server';
27+
28+
/**
29+
* @param {Entity} target
30+
* @param {number} x
31+
* @param {number} y
32+
* @param {number} z
33+
* @param {(arg0: Entity) => void} callback
34+
*/
35+
export function waitMove(target, x, y, z, callback) {
36+
37+
const t = new Map();
38+
39+
t.set(target, [x, y, z]);
40+
41+
system.runInterval(() => {
42+
43+
for (const [target, [xOld, yOld, zOld]] of t) {
44+
45+
const { x: xc, y: yc, z: zc } = target.location;
46+
47+
if (xOld !== xc || yOld !== yc || zOld !== zc) {
48+
49+
t.delete(target);
50+
51+
callback(target);
52+
53+
}
54+
55+
}
56+
57+
})
58+
59+
};

0 commit comments

Comments
 (0)