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
30 lines (27 loc) · 1.1 KB
/
index.js
File metadata and controls
30 lines (27 loc) · 1.1 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
// Script example for ScriptAPI
// Author: THE BOSS9345#0193 <Bedrock Add-Ons>
// Project: https://github.com/JaylyDev/ScriptAPI
import { Player } from "@minecraft/server";
/**
* Checks if the player is located within a specific radius of a block
* @param {Player} player The player to check
* @param {number} x The X coordinate of the block to check
* @param {number} y The Y coordinate of the block to check
* @param {number} z The Z coordinate of the block to check
* @param {number} radius The radius to check
* @returns {boolean} True if the player is located within the specified radius of the block, false otherwise
* @example radiusCheck(player, 0, 0, 0, 10)
*/
function radiusCheck(player, x, y, z, radius) {
const playerLocation = player.location;
const playerX = playerLocation.x;
const playerY = playerLocation.y;
const playerZ = playerLocation.z;
const distanceSquared = (playerX - x) ** 2 + (playerY - y) ** 2 + (playerZ - z) ** 2;
const radiusSquared = radius ** 2;
if (distanceSquared <= radiusSquared) {
return true;
} else {
return false;
}
}