完整版BedrockWiki镜像!
This commit is contained in:
@@ -1,75 +1,77 @@
|
||||
---
|
||||
title: On Player Death
|
||||
category: On Event Systems
|
||||
title: 玩家死亡事件
|
||||
category: 事件系统
|
||||
mentions:
|
||||
- BedrockCommands
|
||||
- zheaEvyline
|
||||
nav_order: 4
|
||||
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 dies.
|
||||
## 系统介绍
|
||||
|
||||
## Setup
|
||||
[由Bedrock Commands社区Discord提供](https://discord.gg/SYstTYx5G5)
|
||||
|
||||
*To be typed in Chat:*
|
||||
本系统将在玩家死亡时执行你预设的命令。
|
||||
|
||||
## 系统配置
|
||||
|
||||
*在聊天栏输入以下指令:*
|
||||
|
||||
`/scoreboard objectives add alive 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>BP/functions/on_player_death.mcfunction</CodeHeader>
|
||||
|
||||
```yaml
|
||||
::: code-group
|
||||
```yaml [BP/functions/on_player_death.mcfunction]
|
||||
scoreboard players set @a [scores={alive=!2}] alive 0
|
||||
scoreboard players set @e [type=player] alive 1
|
||||
|
||||
|
||||
#Your Commands Here (example)
|
||||
execute as @a [scores={alive=0}] run say I died
|
||||
#在此处添加你的命令(示例)
|
||||
execute as @a [scores={alive=0}] run say 我死了
|
||||
|
||||
|
||||
scoreboard players set @a [scores={alive=0}] alive 2
|
||||
```
|
||||
|
||||

|
||||

|
||||
|
||||
我们以`/execute - say`指令为例,你可以根据需求替换为任意指令并自由扩展数量。
|
||||
|
||||
请严格遵循给定顺序,并确保在目标指令中正确添加选择器参数`scores={alive=0}`。
|
||||
|
||||
## 系统原理
|
||||
|
||||
- **`alive=0`** 表示玩家处于死亡状态
|
||||
- **`alive=1`** 表示玩家处于存活状态
|
||||
- **`alive=2`** 表示已对死亡玩家执行过预设命令
|
||||
|
||||
|
||||
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.
|
||||
|
||||
Just make sure to follow the given order and properly add the selector argument ` scores={alive=0} ` as shown for your desired commands.
|
||||
|
||||
## Explanation
|
||||
|
||||
- **` alive=0 `** this means player is dead.
|
||||
- **` alive=1 `** this means player is alive.
|
||||
- **` alive=2 `** this means player is dead and we have run our desired commands on/from them.
|
||||
- **`@a`** 选择器会选中所有玩家(无论生死),因此我们用它将所有玩家标记为0(死亡)
|
||||
- 注意:需要排除已标记为2的玩家,否则会导致命令在死亡玩家身上重复执行
|
||||
|
||||
|
||||
- **` @a `** selector will target all players alive/dead so we use it to mark everyone as 0 'dead.'
|
||||
- Note: we will ignore 2 or it will end up making the commands execute on dead players again. We only want our commands to execute once.
|
||||
- **`@e`** 选择器仅会选中存活玩家,因此我们用它将所有存活玩家标记为1(存活)
|
||||
|
||||
|
||||
- **` @e `** selector on the other hand will only target players who are alive, so we can use this to mark all alive players 1 'alive.'
|
||||
- 通过上述标记,我们可以在死亡玩家(标记0)身上执行预设命令
|
||||
- 执行后需将其分数设为2,否则命令会在玩家复活前持续执行
|
||||
|
||||
|
||||
- Now that dead players are 0 and alive players are 1 we can use this knowledge to run our desired commands on the dead players.
|
||||
- Keep in mind we need to set their score to 2 after or otherwise the commands will keep executing till they respawn.
|
||||
## 循环执行配置
|
||||
|
||||
若使用函数实现,需将`on_player_death`函数添加至`tick.json`以实现循环执行。多个函数可通过逗号分隔添加,详见[函数文档](/wiki/commands/mcfunctions#tick-json)。
|
||||
|
||||
## Tick JSON
|
||||
|
||||
If you are using functions instead of command blocks, the ` on_player_death ` 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.
|
||||
|
||||
<CodeHeader>BP/functions/tick.json</CodeHeader>
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/functions/tick.json]
|
||||
{
|
||||
"values": [
|
||||
"on_player_death"
|
||||
@@ -77,7 +79,7 @@ If you are using functions instead of command blocks, the ` on_player_death ` fu
|
||||
}
|
||||
```
|
||||
|
||||
If using functions, your pack folder structure will be be as follows:
|
||||
使用函数时,资源包文件夹结构如下:
|
||||
|
||||
<FolderView
|
||||
:paths="[
|
||||
@@ -90,6 +92,6 @@ If using functions, your pack folder structure will be be as follows:
|
||||
]"
|
||||
></FolderView>
|
||||
|
||||
> **Note:** the scoreboard names (in this case: 'alive') 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:
|
||||
> - ` alive_0fe678 `
|
||||
> - ` on_player_death_0fe678.mcfunction `
|
||||
> **注意:** 计分板名称(如本例中的'alive')可能被他人重复使用。建议在名称后追加`_`和随机字符来降低冲突概率,函数文件名也可采用相同策略。例如:
|
||||
> - `alive_0fe678`
|
||||
> - `on_player_death_0fe678.mcfunction`
|
||||
Reference in New Issue
Block a user