Skip to content

Commit

Permalink
world-border (#302)
Browse files Browse the repository at this point in the history
* Create index.js

* Update index.js

* Create README.md

* Update README.md

* world-border
  • Loading branch information
defowler2005 authored Aug 2, 2023
1 parent c32f00c commit 8d958a4
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
25 changes: 25 additions & 0 deletions scripts/world-border/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# world-border

## Description

Rn code when the player is outside the set coordinates.

**Parameters:**

- `player` (type: Player or entity): The player or entity for which the function will be executed on.

- `border` (type: object): An object representing the border with the following properties:

- `minX` (type: number): The minimum X-coordinate value of the border.

- `minZ` (type: number): The minimum Z-coordinate value of the border.

- `maxX` (type: number): The maximum X-coordinate value of the border.

- `maxZ` (type: number): The maximum Z-coordinate value of the border.

The border is defined by the range between (`minX`, `minZ`) and (`maxX`, `maxZ`) coordinates.

## Credits

These scripts were written by [defowler2005](https://github.com/defowler2005).
39 changes: 39 additions & 0 deletions scripts/world-border/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Script example for ScriptAPI
// Author: defowler2005 <https://github.com/defowler2005>
// Project: https://github.com/JaylyDev/ScriptAPI

/**
* world border
* @license Do whatever you want
* @author defowler2005
* @version 1.0.0
* @project https://github.com/JaylyDev/ScriptAPI
* --------------------------------------------------------------------------
* A code that creates a border for the world, Simple.
* --------------------------------------------------------------------------
*/
import { world, system } from '@minecraft/server';

/**
* @property {number} minX - The minimum X-coordinate value of the border.
* @property {number} minZ - The minimum Z-coordinate value of the border.
* @property {number} maxX - The maximum X-coordinate value of the border.
* @property {number} maxZ - The maximum Z-coordinate value of the border.
*/

const minX = -10;
const minZ = -10;
const maxX = 10;
const maxZ = 10;

system.runInterval(() => {
world.getPlayers().forEach(player => {
const x = Math.floor(player.location.x);
const z = Math.floor(player.location.z);
if (Math.abs(x - (minX + maxX) / 2) > Math.abs(minX - maxX) / 2 || Math.abs(z - (minZ + maxZ) / 2) > Math.abs(minZ - maxZ) / 2) {
player.sendMessage('You are outside the border!');
} else {
player.sendMessage('You are in the border!');
}
})
}, 20);

0 comments on commit 8d958a4

Please sign in to comment.