docs(areacontrol): update

This commit is contained in:
2025-11-12 21:02:51 +08:00
parent 17987c0cec
commit 125dbfc592
4 changed files with 20 additions and 14 deletions

View File

@@ -48,12 +48,15 @@ You can manage the script in-game using the `/areacontrol` command series. All c
- `/areacontrol toggleCooldown`
- **Function**: Enable or disable the item cooldown feature.
- `/areacontrol setcenter`
- **Function**: Set your current position as the center of the zone.
- `/areacontrol setCircularArea <radius>`
- **Function**: Set your current position as the center of the zone and define its radius.
- **Example**: `/areacontrol setCircularArea 100`
- `/areacontrol setradius <radius>`
- **Function**: Set the radius of the zone.
- **Example**: `/areacontrol setradius 100`
- `/areacontrol setAreaPos1`
- **Function**: Set the first corner of the area to your current position.
- `/areacontrol setAreaPos2`
- **Function**: Set the second corner of the area to your current position, defining a rectangular zone.
- `/areacontrol setmode <adventure|spectator>`
- **Function**: Set the game mode players will be switched to upon entering the zone.
@@ -112,7 +115,7 @@ PlayerEvents.tick((event) => {
#### State Caching and Boundary Detection
To avoid unnecessary operations, the script uses state caching and fast boundary detection.
1. **Boundary Pre-calculation**: When `center` or `radius` changes, the script pre-calculates the area's `minX`, `maxX`, `minZ`, `maxZ` boundaries.
1. **Boundary Pre-calculation**: When the area is defined (either as a circular zone with `setCircularArea` or a rectangular zone with `setAreaPos1`/`setAreaPos2`), the script pre-calculates the area's `minX`, `maxX`, `minZ`, `maxZ` boundaries.
2. **Fast Detection**: When checking a player's position, it only needs to compare the player's X and Z coordinates with the pre-calculated boundaries, which is an efficient O(1) operation.
3. **State Caching**: A global object named `playerStates` caches whether each player is inside the area (as a boolean). The core logic, like switching game modes, is executed only when the player's current state differs from the cached state (i.e., the player has crossed the area boundary). The cache is then updated.

View File

@@ -48,12 +48,15 @@
- `/areacontrol toggleCooldown`
- **功能**:启用或禁用物品冷却功能。
- `/areacontrol setcenter`
- **功能**:将您当前的位置设置为区域的中心点。
- `/areacontrol setCircularArea <半径>`
- **功能**:将您当前的位置设置为区域的中心点,并定义其半径
- **示例**`/areacontrol setCircularArea 100`
- `/areacontrol setradius <半径>`
- **功能**:设置区域的半径
- **示例**`/areacontrol setradius 100`
- `/areacontrol setAreaPos1`
- **功能**将您当前的位置设置区域的第一个角点
- `/areacontrol setAreaPos2`
- **功能**:将您当前的位置设置为区域的第二个角点,从而定义一个矩形区域。
- `/areacontrol setmode <adventure|spectator>`
- **功能**:设置玩家进入区域后切换到的游戏模式。
@@ -112,7 +115,7 @@ PlayerEvents.tick((event) => {
#### 状态缓存与边界检测
为避免不必要的操作,脚本采用状态缓存和快速边界检测。
1. **边界预计算**:当 `center``radius` 改变时,脚本会预先计算出区域的 `minX`, `maxX`, `minZ`, `maxZ` 边界。
1. **边界预计算**:当区域被定义时(无论是通过 `setCircularArea` 定义的圆形区域,还是通过 `setAreaPos1`/`setAreaPos2` 定义的矩形区域),脚本会预先计算出区域的 `minX`, `maxX`, `minZ`, `maxZ` 边界。
2. **快速检测**:在检查玩家位置时,只需将玩家的 X 和 Z 坐标与预计算的边界进行比较,这是一个 O(1) 的高效操作。
3. **状态缓存**:一个名为 `playerStates` 的全局对象缓存着每个玩家是否在区域内的布尔值。只有当玩家的当前状态与缓存状态不一致时(即玩家穿越了区域边界),脚本才会执行游戏模式切换等核心逻辑,并更新缓存。