完整版BedrockWiki镜像!

This commit is contained in:
boybook
2025-03-20 11:52:46 +08:00
parent 1994c41f01
commit bf9aa4b056
214 changed files with 9042 additions and 8867 deletions

View File

@@ -1,6 +1,6 @@
---
title: On Player Respawn
category: On Event Systems
title: 玩家重生事件
category: 事件系统
mentions:
- BedrockCommands
- zheaEvyline
@@ -9,66 +9,71 @@ tags:
- system
---
## Introduction
# 玩家重生事件
[Sourced By Bedrock Commands Community Discord](https://discord.gg/SYstTYx5G5)
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
This system will run your desired commands on the event that a player respawns from death state.
## 前言
## Setup
[由Bedrock Commands社区Discord提供](https://discord.gg/SYstTYx5G5)
*To be typed in Chat:*
当玩家从死亡状态重生时,该系统将执行您指定的命令。
## 初始化设置
*在聊天栏输入以下指令:*
`/scoreboard objectives add respawn dummy`
If you prefer to have the objective added automatically on world initialisation, follow the process outlined in [On First World Load.](/commands/on-first-world-load)
若希望在世界初始化时自动添加计分板,请参照[首次世界加载](/wiki/commands/on-first-world-load)指南操作。
## System
## 系统实现
<CodeHeader>on_player_respawn.mcfunction</CodeHeader>
```yaml
#Your Commands Here (example)
execute as @e [scores={respawn=1}] run say I died and respawned.
::: code-group
```yaml [on_player_respawn.mcfunction]
# 在此处添加你的命令(示例)
execute as @e [scores={respawn=1}] run say 我已死亡并重生。
scoreboard players set @a respawn 1
scoreboard players set @e [type=player] respawn 0
```
![commandBlockChain3](/assets/images/commands/commandBlockChain/3.png)
:::
![命令方块链3](/assets/images/commands/commandBlockChain/3.png)
Here we have used an `/execute - say` command as an example but you can use any command you prefer and as many as you require.
本例中使用`/execute - say`指令作为示例,您可以根据需求替换为任意指令,数量不限。
Just make sure to follow the given order and properly use the selector argument ` @e [scores={respawn=1}] ` as shown for your desired commands.
请严格遵循指令顺序,并正确使用选择器参数` @e [scores={respawn=1}] `来定位目标玩家。
## Explanation
## 运行原理
- **` respawn=0 `** this means the player is alive or had already respawned.
- **` respawn=1 `** this means the player died and is now respawning, ie. respawned *just now*, in the current gametick.
- **` @a `** selector will target all players alive/dead so we use it to mark everyone as 1 'respawning'
- **` @e `** selector on the other hand will only target players who are alive, so we can use this to mark all alive players 0 'respawned'
- **` respawn=0 `** 表示玩家存活或已完成重生
- **` respawn=1 `** 表示玩家死亡且正在重生(即当前游戏刻内刚触发重生)
- **` @a `** 选择器将定位所有玩家(包括存活/死亡用于标记全体玩家为1正在重生状态
- **` @e `** 选择器仅定位存活玩家用于重置存活玩家为0已完成重生状态
Now that *respawning* players are 1 and *respawned* players are 0 we can use this knowledge to run our desired commands on the players respawning.
通过此机制我们可以精准捕捉到刚刚重生的玩家分数为1的玩家来执行指定命令。
In the system, your desired commands must come before the other 2 commands because players change from death state to alive state along the start of the gametick before commands are run.
在系统文件中,自定义命令必须放置在最后两条计分板操作指令之前,因为玩家状态会在游戏刻开始时立即从死亡转为存活。
Hence; if we were to put them at the end then the other 2 commands would set respawning players score to 0 first and then the commands you want to run won't be able to select those players as our selector argument is ` @e [scores={respawn=1}] ` not 0. Using 0 would not work as then it would repeat endlessly even on players who have already respawned.
若将自定义命令置于末尾计分板操作会先将重生玩家的分数重置为0此时通过` @e [scores={respawn=1}] `选择器将无法定位到目标玩家。若使用分数0作为条件则会导致指令在已重生玩家身上重复触发。
## Tick JSON
## 游戏刻函数配置
If you are using functions instead of command blocks, the ` on_player_respawn ` function must be added to the ` tick.json ` in order to loop and run it continuously. Multiple files can be added to the ` tick.json ` by placing a comma after each string. Refer to [Functions](/commands/mcfunctions#tick-json) documentation for further info.
若使用函数而非命令方块,需将` on_player_respawn `函数添加至` tick.json `以实现循环检测。多个函数可通过逗号分隔添加,详见[函数文档](/wiki/commands/mcfunctions#tick-json)。
<CodeHeader>BP/functions/tick.json</CodeHeader>
```json
::: code-group
```json [BP/functions/tick.json]
{
"values": [
"on_player_respawn"
]
}
```
:::
If using functions, your pack folder structure will be be as follows:
函数包的文件结构如下所示:
<FolderView
:paths="[
@@ -81,6 +86,6 @@ If using functions, your pack folder structure will be be as follows:
]"
></FolderView>
> **Note:** the scoreboard names (in this case: 'respawn') may end up being used by other people. Appending ` _ ` and a set of randomly generated characters after would be a choice that reduces the probability of collisions. Similar technique can be employed for the ` .mcfunction ` filenames. Ex:
> **注意:** 计分板名称(本例中的'respawn')可能与其他开发者冲突。建议在名称后追加` _ `和随机字符组合来降低重复概率,函数文件名也可采用相同策略。例如:
> - ` respawn_0fe678 `
> - ` on_player_respawn_0fe678.mcfunction `
> - ` on_player_respawn_0fe678.mcfunction `