Files
netease-modsdk-wiki/docs/mcdocs/1-ModAPI/接口/世界/消息.md
2025-03-18 14:46:12 +08:00

408 lines
10 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
sidebarDepth: 1
---
# 消息
## NotifyOneMessage
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.msgCompServer.MsgComponentServer
- 描述
给指定玩家发送聊天框消息
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| playerId | str | 指定玩家id |
| msg | str | 消息内容 |
| color | str | 颜色样式代码字符串可参考wiki[样式代码](https://minecraft-zh.gamepedia.com/%E6%A0%B7%E5%BC%8F%E4%BB%A3%E7%A0%81),默认为白色 |
- 返回值
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateMsg(playerId)
comp.NotifyOneMessage(playerId, "test", "§c")
```
## SendMsg
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.msgCompServer.MsgComponentServer
- 描述
模拟玩家给所有人发送聊天栏消息
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| name | str | 发送者玩家的名字 |
| msg | str | 消息内容 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置结果 |
- 备注
- name参数需要设置玩家的名字(可通过name组件的GetName接口获取),如果设置的玩家名字不存在,则随机找一个玩家发出该消息
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateMsg(levelId)
comp.SendMsg("playerName","test")
```
## SendMsgToPlayer
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.msgCompServer.MsgComponentServer
- 描述
模拟玩家给另一个玩家发送聊天栏消息
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| fromEntityId | str | 发送者玩家ID |
| toEntityId | str | 接受者玩家ID |
| msg | str | 消息内容 |
- 返回值
- 示例
```python
comp = serverApi.GetEngineCompFactory().CreateMsg(levelId)
comp.SendMsgToPlayer(fromPlayerId, toPlayerId, "test")
```
## SetLeftCornerNotify
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.textNotifyCompClient.TextNotifyComponet
- 描述
客户端设置左上角通知信息
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| textMsg | str | 通知内容 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateTextNotifyClient(levelId)
comp.SetLeftCornerNotify("做好准备")
```
## SetNotifyMsg
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
设置消息通知
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| msg | str | 消息内容 |
| color | str | 使用GenerateColor接口获取的颜色默认为白色 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
comp.SetNotifyMsg("消息通知", serverApi.GenerateColor('BLUE'))
```
## SetOnePopupNotice
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
在具体某个玩家的物品栏上方弹出popup类型通知位置位于tip类型消息下方此功能更建议客户端使用game组件的对应接口SetPopupNotice
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| playerId | str | 具体玩家Id |
| message | str | 消息内容,可以在消息前增加extraServerApi.GenerateColor("RED")字符来设置颜色,具体参考样例 |
| subtitle | str | 消息子标题内容,效果同message也可设置颜色位置位于message上方 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(playerId)
# playerId 变量改为具体的玩家Id
comp.SetOnePopupNotice(playerId, serverApi.GenerateColor("RED") + "消息通知", "消息子标题")
```
## SetOneTipMessage
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
在具体某个玩家的物品栏上方弹出tip类型通知位置位于popup类型通知上方此功能更建议在客户端使用game组件的对应接口SetTipMessage
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| playerId | str | 具体玩家Id |
| message | str | 消息内容,可以在消息前增加extraServerApi.GenerateColor("RED")字符来设置颜色,具体参考样例 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(playerId)
# playerId 变量改为具体的玩家Id
comp.SetOneTipMessage(playerId, serverApi.GenerateColor("RED") + "tip提示")
```
## SetPopupNotice
<span style="display:inline;color:#ff5555">服务端</span><span style="display:inline;color:#7575f9">客户端</span>
### 服务端接口
<span id="s0"></span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
在所有玩家物品栏上方弹出popup类型通知位置位于tip类型消息下方
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| message | str | 消息内容,可以在消息前增加extraServerApi.GenerateColor("RED")字符来设置颜色,具体参考样例 |
| subtitle | str | 消息子标题内容,效果同message也可设置颜色位置位于message上方 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
comp.SetPopupNotice(serverApi.GenerateColor("RED") + "消息通知", "消息子标题")
```
### 客户端接口
<span id="c0"></span>
method in mod.client.component.gameCompClient.GameComponentClient
- 描述
在本地玩家的物品栏上方弹出popup类型通知位置位于tip类型消息下方
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| message | str | 消息内容,可以在消息前增加extraClientApi.GenerateColor("RED")字符来设置颜色,具体参考样例 |
| subtitle | str | 消息子标题内容,效果同message也可设置颜色位置位于message上方 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateGame(entityId)
comp.SetPopupNotice(clientApi.GenerateColor("RED") + "消息通知", "消息子标题")
```
## SetPopupState
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.gameCompClient.GameComponentClient
- 描述
设置Popup消息栏状态
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| state | int | 状态值0为原版开启状态1为关闭2为使用接口设置的物品dict中customTips的第一行作为弹出信息 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否成功 |
- 备注
- 注意该设置不会存档如果是配在json里面的custom_tips组件中的内容使用2模式是无法显示的只有使用物品dict相关的接口设置的customTips才能生效、
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateGame(entityId)
comp.SetPopupState(2)
```
## SetTipMessage
<span style="display:inline;color:#ff5555">服务端</span><span style="display:inline;color:#7575f9">客户端</span>
### 服务端接口
<span id="s0"></span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
在所有玩家物品栏上方弹出tip类型通知位置位于popup类型通知上方
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| message | str | 消息内容,可以在消息前增加extraServerApi.GenerateColor("RED")字符来设置颜色,具体参考样例 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
comp.SetTipMessage(serverApi.GenerateColor("RED") + "tip提示")
```
### 客户端接口
<span id="c0"></span>
method in mod.client.component.gameCompClient.GameComponentClient
- 描述
在本地玩家的物品栏上方弹出tip类型通知位置位于popup类型通知上方
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| message | str | 消息内容,可以在消息前增加extraClientApi.GenerateColor("RED")字符来设置颜色,具体参考样例 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateGame(entityId)
comp.SetTipMessage(clientApi.GenerateColor("RED") + "tip提示")
```