Files
netease-modsdk-wiki/docs/mcdocs/1-ModAPI/接口/玩家/属性.md
boybook 760c2dd9ad 2.6
2025-12-01 20:59:16 +08:00

1309 lines
33 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
---
# 属性
## AddPlayerExperience
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.expCompServer.ExpComponentServer
- 描述
增加玩家经验值
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| exp | int | 玩家经验值,可设置负数 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 备注
- 如果设置的exp值为负数且超过当前等级已有的经验值调用接口后该玩家等级不会下降但是经验值会置为最小值
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateExp(entityId)
comp.AddPlayerExperience(25)
```
## AddPlayerLevel
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.levelCompServer.LevelComponentServer
- 描述
修改玩家等级
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| level | int | 玩家等级,可设置负数 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateLv(playerId)
comp.AddPlayerLevel(2)
```
## CollectOnlineClientData
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
收集在线玩家客户端数据,用于判断玩家是否作弊
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| collectTypes | list(str) | 数据类型,不同类型收集到不同数据,具体说明参见备注。 |
| callback | function | 回调函数用于分析数据并判断玩家是否作弊包含两个参数第一个参数是playerId类型str第二个参数表示收集到的数据dict类型内容由collectTypes决定的具体参见备注若数据收集失败则为None比如玩家不在线 |
| extraArgs | dict | 默认为None根据collectTypes传入不同参数具体说明参见备注。 |
- 返回值
- 备注
- collectTypes中类型解释如下
game类型收集到的数据字典解释如下
| 关键字 | 数据类型 | 说明 |
| ----------| --------------------- | ---------|
| gameType | int | 游戏模式,含义:-1获取失败0生存模式1创造模式2冒险模式3旁观者模式|
| levelGravity | float | 世界的重力因子|
player类型收集到的数据字典解释如下
| 关键字 | 数据类型 | 说明 |
| ----------| --------------------- | ---------|
| playerHealth | int | 玩家生命值|
world类型收集到的数据字典解释如下
| 关键字 | 数据类型 | 说明 |
| ----------| --------------------- | ---------|
| blockName | str | 某一位置方块的名称要求extraArgs参数包含pos参数|
| blockAuxValue | int | 某一位置方块的附加值AuxValue要求extraArgs参数字典中包含"pos",若缺少则没有数据|
entity类型收集到的数据字典解释如下
| 关键字 | 数据类型 | 说明 |
| ----------| --------------------- | ---------|
| entityPos | tuple(float,float,float) | 实体位置具体参见客户端GetPos接口说明要求extraArgs参数字典中包含"entityId",若缺少则没有数据|
| entityGravity | float | 获取实体的重力因子当生物重力因子为0时则应用世界的重力因子要求extraArgs参数字典中包含"entityId",若缺少则没有数据|
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
def ProcessData(playerId, data):
#正常返回实例ProcessData 123 {'blockAuxValue': 0, 'blockName': 'minecraft:air', 'blockBoxSize': (-1.0, -1.0), 'gameType': 1, 'entityPos': (123,456,789), 'levelGravity': -0.08, 'playerHealth': 20, 'entityGravity': 0.0}
#失败返回实例ProcessData 123 None
print 'ProcessData', playerId, data
comp.CollectOnlineClientData(['player', 'world', 'entity', 'game'], ProcessData, {'entityId' :'123', 'pos' : (123,456,789))})
```
## GetArmorValue
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.gameCompClient.GameComponentClient
- 描述
获取玩家护甲值
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| playerId | str | 玩家id |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| int | 获取玩家护甲值 |
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateGame(levelId)
print(comp.GetArmorValue(playerId))
```
## GetEnchantmentSeed
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
获取玩家的附魔种子,该种子会决定附魔台上准备附魔的装备的附魔项
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| int | 附魔种子 |
- 备注
- 该属性会自动存档
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
comp.GetEnchantmentSeed()
```
## GetPlayerCurLevelExp
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.gameCompClient.GameComponentClient
- 描述
获取玩家当前等级需要的经验值
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| playerId | str | 玩家id |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| int | 玩家当前等级需要的经验值 |
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateGame(levelId)
print(comp.GetPlayerCurLevelExp(playerId))
```
## GetPlayerCurrentExhaustionValue
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
获取玩家foodExhaustionLevel的当前消耗度。详见<a href="https://zh.minecraft.wiki/w/%E9%A5%A5%E9%A5%BF#%E6%9C%BA%E5%88%B6">消耗度介绍</a>
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| float | 玩家foodExhaustionLevel的当前消耗度, |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
value = comp.GetPlayerCurrentExhaustionValue()
```
## GetPlayerExp
<span style="display:inline;color:#ff5555">服务端</span><span style="display:inline;color:#7575f9">客户端</span>
### 服务端接口
<span id="s0"></span>
method in mod.server.component.expCompServer.ExpComponentServer
- 描述
获取玩家当前等级下的经验值
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| isPercent | bool | 是否为百分比 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| float | 玩家经验值 |
- 备注
- 如果设置返回百分比为False则返回玩家当前等级下经验的绝对值非当前玩家总经验值
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateExp(entityId)
print(comp.GetPlayerExp(False))
```
### 客户端接口
<span id="c0"></span>
method in mod.client.component.gameCompClient.GameComponentClient
- 描述
获取玩家当前等级下的经验值
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| playerId | str | 玩家id |
| isPercent | bool | 是否为百分比, 如果设置返回百分比为False则返回玩家当前等级下经验的绝对值非当前玩家总经验值。 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| float | 玩家经验值 |
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateGame(levelId)
print(comp.GetPlayerExp(playerId, False))
```
## GetPlayerHealthLevel
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
获取玩家健康临界值当饥饿值大于等于健康临界值时会自动恢复血量开启饥饿值且开启自然恢复时有效。原版默认值为18
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| int | 健康临界值,-1表示获取失败 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(entityId)
print(comp.GetPlayerHealthLevel())
```
## GetPlayerHealthTick
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
获取玩家自然恢复速度当饥饿值大于等于健康临界值时会自动恢复血量开启饥饿值且开启自然恢复时有效。原版默认值为80刻即每4秒恢复1点血量
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| int | 自然恢复速度,-1表示获取失败 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(entityId)
print(comp.GetPlayerHealthTick())
```
## GetPlayerHunger
<span style="display:inline;color:#ff5555">服务端</span><span style="display:inline;color:#7575f9">客户端</span>
### 服务端接口
<span id="s0"></span>
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
获取玩家饥饿度展示在UI饥饿度进度条上初始值为20即每一个鸡腿代表2个饥饿度。 **饱和度(saturation)** 玩家当前饱和度初始值为5最大值始终为玩家当前饥饿度(hunger),该值直接影响玩家**饥饿度(hunger)**。<br>1增加方法吃食物。<br>2减少方法每触发一次**消耗事件**该值减少1如果该值不大于0直接把玩家 **饥饿度(hunger)** 减少1。
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| float | 玩家饥饿度 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
comp.GetPlayerHunger()
```
### 客户端接口
<span id="c0"></span>
method in mod.client.component.playerCompClient.PlayerCompClient
- 描述
获取玩家饥饿度展示在UI饥饿度进度条上初始值为20即每一个鸡腿代表2个饥饿度。 **饱和度(saturation)** 玩家当前饱和度初始值为5最大值始终为玩家当前饥饿度(hunger),该值直接影响玩家**饥饿度(hunger)**。<br>1增加方法吃食物。<br>2减少方法每触发一次**消耗事件**该值减少1如果该值不大于0直接把玩家 **饥饿度(hunger)** 减少1。
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| float | 玩家饥饿度 |
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreatePlayer(playerId)
comp.GetPlayerHunger()
```
## GetPlayerLevel
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.levelCompServer.LevelComponentServer
- 描述
获取玩家等级
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| int | 玩家等级 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateLv(playerId)
comp.GetPlayerLevel()
```
## GetPlayerMaxExhaustionValue
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
获取玩家foodExhaustionLevel的归零值常量值默认为4。**消耗度exhaustion**是指玩家当前消耗度水平初始值为0该值会随着玩家一系列动作如跳跃的影响而增加当该值大于最大消耗度maxExhaustion后归零并且把饱和度saturation减少1为了说明饥饿度机制我们将此定义为**消耗事件**
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| float | 玩家foodExhaustionLevel的归零值 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
comp.GetPlayerMaxExhaustionValue()
```
## GetPlayerStarveLevel
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
获取玩家饥饿临界值当饥饿值小于饥饿临界值时会自动扣除血量开启饥饿值且开启饥饿掉血时有效。原版默认值为1
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| int | 饥饿临界值 -1表示获取失败 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(entityId)
print(comp.GetPlayerStarveLevel())
```
## GetPlayerStarveTick
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
获取玩家饥饿掉血速度当饥饿值小于饥饿临界值时会自动扣除血量开启饥饿值且开启饥饿掉血时有效。原版默认值为80刻即每4秒扣除1点血量
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| int | 饥饿掉血速度,-1表示获取失败 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(entityId)
print(comp.GetPlayerStarveTick())
```
## GetPlayerTotalExp
<span style="display:inline;color:#ff5555">服务端</span><span style="display:inline;color:#7575f9">客户端</span>
### 服务端接口
<span id="s0"></span>
method in mod.server.component.expCompServer.ExpComponentServer
- 描述
获取玩家的总经验值
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| int | 总经验值,正整数。获取失败的情况下返回-1。 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateExp(entityId)
print(comp.GetPlayerTotalExp())
```
### 客户端接口
<span id="c0"></span>
method in mod.client.component.gameCompClient.GameComponentClient
- 描述
获取玩家的总经验值
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| playerId | str | 玩家id |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| int | 总经验值,正整数。获取失败的情况下返回-1。 |
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateGame(levelId)
print(comp.GetPlayerTotalExp(playerId))
```
## IsHighLevelMultiJointOfficialSkin
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.gameCompClient.GameComponentClient
- 描述
获取玩家穿戴的皮肤是否为史诗及以上的多关节官方4d皮肤 在接收到 UpdatePlayerSkinClientEvent 事件后调用 此事件在客户端接收到玩家皮肤信息同步后触发 参数仅playerId
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| playerId | str | 玩家ID |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 史诗及以上的多关节官方4d皮肤返回True |
- 示例
```python
self.ListenForEvent('Minecraft', "Engine", 'UpdatePlayerSkinClientEvent', self, self.onUpdatePlayerSkinClientEvent)
def onUpdatePlayerSkinClientEvent(self,args):
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateGame(levelId)
comp.IsHighLevelMultiJointOfficialSkin(args['playerId'])
```
## IsHighLevelOfficialSkin
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.gameCompClient.GameComponentClient
- 描述
获取玩家穿戴的皮肤是否为史诗及以上的官方4d皮肤 在接收到 UpdatePlayerSkinClientEvent 事件后调用 此事件在客户端接收到玩家皮肤信息同步后触发 参数仅playerId
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| playerId | str | 玩家ID |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 史诗及以上的官方4d皮肤返回True |
- 示例
```python
self.ListenForEvent('Minecraft', "Engine", 'UpdatePlayerSkinClientEvent', self, self.onUpdatePlayerSkinClientEvent)
def onUpdatePlayerSkinClientEvent(self,args):
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateGame(levelId)
comp.IsHighLevelOfficialSkin(args['playerId'])
```
## IsMultiJointOfficialSkin
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.gameCompClient.GameComponentClient
- 描述
获取玩家穿戴的皮肤是否为多关节官方4d皮肤 在接收到 UpdatePlayerSkinClientEvent 事件后调用 此事件在客户端接收到玩家皮肤信息同步后触发 参数仅playerId
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| playerId | str | 玩家ID |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 多关节官方4d皮肤返回True |
- 示例
```python
self.ListenForEvent('Minecraft', "Engine", 'UpdatePlayerSkinClientEvent', self, self.onUpdatePlayerSkinClientEvent)
def onUpdatePlayerSkinClientEvent(self,args):
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateGame(levelId)
comp.IsMultiJointOfficialSkin(args['playerId'])
```
## IsOfficialSkin
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.gameCompClient.GameComponentClient
- 描述
获取玩家穿戴的皮肤是否为官方4d皮肤 在接收到 UpdatePlayerSkinClientEvent 事件后调用 此事件在客户端接收到玩家皮肤信息同步后触发 参数仅playerId
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| playerId | str | 玩家ID |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 官方4d皮肤返回True |
- 示例
```python
self.ListenForEvent('Minecraft', "Engine", 'UpdatePlayerSkinClientEvent', self, self.onUpdatePlayerSkinClientEvent)
def onUpdatePlayerSkinClientEvent(self,args):
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateGame(levelId)
comp.IsOfficialSkin(args['playerId'])
```
## IsPlayerNaturalRegen
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
是否开启玩家自然恢复,当饥饿值大于等于健康临界值时会自动恢复血量,开启饥饿值且开启自然恢复时有效。原版默认开启
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | True表示开启False表示关闭None表示获取失败 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(entityId)
print(comp.IsPlayerNaturalRegen())
```
## IsPlayerNaturalStarve
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
是否开启玩家饥饿掉血,当饥饿值小于饥饿临界值时会自动恢复血量,开启饥饿值且开启饥饿掉血时有效。原版默认开启
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | True表示开启False表示关闭None表示获取失败 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(entityId)
print(comp.IsPlayerNaturalStarve())
```
## SetEnchantmentSeed
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
设置玩家的附魔种子,该种子会决定附魔台上准备附魔的装备的附魔项
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| enchantmentSeed | int | 种子,随机数量多,开发者可使用[GetEnchantmentSeed](#getenchantmentseed)获取当前的随机种子,自行记录 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 备注
- 该属性会自动存档
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
comp.SetEnchantmentSeed(32)
```
## SetPlayerCurrentExhaustionValue
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
设置玩家foodExhaustionLevel的当前消耗度。详见<a href="https://zh.minecraft.wiki/w/%E9%A5%A5%E9%A5%BF#%E6%9C%BA%E5%88%B6">消耗度介绍</a>
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| value | float | 当前消耗度 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
result = comp.SetPlayerCurrentExhaustionValue(2.0)
```
## SetPlayerHealthLevel
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
设置玩家健康临界值,当饥饿值大于等于健康临界值时会自动恢复血量,开启饥饿值且开启自然恢复时有效.原版默认值为18
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| healthLevel | int | 健康临界值 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 备注
- 注:健康临界值始终大于等于饥饿临界值。如果设置的健康临界值小于饥饿临界值,饥饿临界值将被设置为当前的健康临界值
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.SetPlayerHealthLevel(16) # 饥饿值大于等于16就会进入自然恢复状态默认每隔4秒恢复1点血量
```
## SetPlayerHealthTick
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
设置玩家自然恢复速度,当饥饿值大于等于健康临界值时会自动恢复血量,开启饥饿值且开启自然恢复时有效.原版默认值为80刻即每4秒恢复1点血量
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| healthTick | int | 自然恢复速度 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 备注
-最小值为1即每秒恢复20点血量
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.SetPlayerHealthTick(40) # 自然恢复状态下每隔240/20秒恢复1点血量
```
## SetPlayerHunger
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
设置玩家饥饿度。
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| value | float | 饥饿度 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 备注
- 该接口修改的饥饿度不能触发PlayerHungerChangeServerEvent事件
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
comp.SetPlayerHunger(10)
```
## SetPlayerMaxExhaustionValue
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
设置玩家**最大消耗度(maxExhaustion)**,通过调整 **最大消耗度(maxExhaustion)** 的大小,就可以调整 **饥饿度(hunger)** 的消耗速度,当 **最大消耗度(maxExhaustion)** 很大时,饥饿度可以看似一直不下降
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| value | float | **最大消耗度(maxExhaustion)** |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 备注
- 例如:当 **最大消耗度(maxExhaustion)** 为4时玩家的饥饿消耗速度是 **最大消耗度(maxExhaustion)** 为8时的两倍
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
comp.SetPlayerMaxExhaustionValue(10.0)
```
## SetPlayerNaturalRegen
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
设置是否开启玩家自然恢复,当饥饿值大于等于健康临界值时会自动恢复血量,开启饥饿值且开启自然恢复时有效.原版默认开启
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| value | bool | True开启False关闭 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.SetPlayerNaturalRegen(False) # 关闭自然恢复,即使饥饿值大于健康临界值时也不会恢复血量
```
## SetPlayerNaturalStarve
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
设置是否开启玩家饥饿掉血,当饥饿值小于饥饿临界值时会自动扣除血量,开启饥饿值且开启饥饿掉血时有效.原版默认开启
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| value | bool | True开启False关闭 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.SetPlayerNaturalStarve(False) # 关闭饥饿掉血,即使饥饿值小于饥饿临界值时也不会扣除血量
```
## SetPlayerPrefixAndSuffixName
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.nameCompServer.NameComponentServer
- 描述
设置玩家前缀和后缀名字
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| prefix | str | 前缀内容 |
| prefixColor | str | 前缀内容颜色描述可以使用GenerateColor接口传入参数 |
| suffix | str | 后缀内容 |
| suffixColor | str | 后缀内容颜色描述可以使用GenerateColor接口传入参数 |
| nameColor | str | 名字颜色描述可以使用GenerateColor接口传入参数,默认为空 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateName(playerId)
comp.SetPlayerPrefixAndSuffixName("红队",serverApi.GenerateColor('RED'),'肉盾',serverApi.GenerateColor('RED'), serverApi.GenerateColor('BLUE'))
```
## SetPlayerStarveLevel
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
设置玩家饥饿临界值当饥饿值小于饥饿临界值时会自动扣除血量开启饥饿值且开启饥饿掉血时有效。原版默认值为1
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| starveLevel | int | 饥饿临界值 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 备注
- 注:健康临界值始终大于等于饥饿临界值。如果设置的饥饿临界值大于健康临界值,将被设置为当前的健康临界值
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.SetPlayerStarveLevel(2) # 饥饿值小于等于2就会进入饥饿掉血状态默认每隔4秒掉1点血量
```
## SetPlayerStarveTick
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
设置玩家饥饿掉血速度,当饥饿值小于饥饿临界值时会自动扣除血量,开启饥饿值且开启饥饿掉血时有效.原版默认值为80刻即每4秒扣除1点血量
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| starveTick | int | 饥饿掉血速度 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 备注
-最小值为1即每秒扣20点血量
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.SetPlayerStarveTick(40) # 饥饿掉血状态下每隔240/20秒扣除1点血量
```
## SetPlayerTotalExp
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.expCompServer.ExpComponentServer
- 描述
设置玩家的总经验值
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| exp | int | 总经验值,正整数 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 备注
- 根据总经验值会重新计算等级,该接口可引起等级的变化
- 内部运算采用浮点数,数值较大时会出现误差
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateExp(entityId)
comp.SetPlayerTotalExp(25)
```
## Swing
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.playerCompClient.PlayerCompClient
- 描述
本地玩家播放原版攻击动作
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否成功 |
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreatePlayer(clientApi.GetLevelId())
comp.Swing()
```
## getUid
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.playerCompClient.PlayerCompClient
- 描述
获取本地玩家的uid
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| long或None | 玩家uid |
- 备注
- 不是客户端线程或者没有经过登录认证获取的uid为None。在当前机器上调用该接口获取的值为固定值不依赖创建的player
- getUid接口不能在加载mod过程中使用推荐开发者在OnLocalPlayerStopLoading事件触发之后再使用
- 示例
```python
comp = clientApi.GetEngineCompFactory().CreatePlayer(entityId)
uid = comp.getUid()
```