Files
netease-modsdk-wiki/docs/mcdocs/1-ModAPI/接口/玩家/行为.md
2025-03-17 13:24:39 +08:00

1492 lines
34 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
---
# 行为
## AddPlayerAroundEntityMotion
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer
- 描述
给玩家添加对实体环绕运动器
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| eID | str | 要环绕的某个实体的ID |
| angularVelocity | float | 圆周运动的角速度(弧度/秒) |
| axis | tuple(float,float,float) | 圆周运动的轴,决定了在哪个平面上做圆周运动,默认为(0, 1, 0) |
| lockDir | bool | 是否在运动器生效时锁定实体的朝向不锁定则实体的朝向会随着运动而改变默认为False。 |
| stopRad | float | 停止该运动器所需要的弧度当stopRad为0时该运动器会一直运行默认为0 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| int | 运动器ID添加失败时返回-1 |
- 备注
- 该接口不屏蔽玩家控制的移动以及重力作用,当有玩家控制发生时,最终的表现结果可能与预期有差异。由于玩家的头部与相机控制相关,若需要使运动器控制玩家的头部,请使用[DepartCamera](./摄像机.md#DepartCamera)分离玩家与摄像机。
- 环绕运动器可叠加多个,且可与速度运动器互相叠加。
- 由于引擎中有加载的区块限制建议将玩家的运动范围控制在当前位置±100内。
- 示例
```python
import mod.server.extraServerApi as serverApi
motionComp = serverApi.GetEngineCompFactory().CreateActorMotion(playerId)
axis=(-1, 1, 1)
mID = motionComp.AddPlayerAroundEntityMotion(eID, 1.0, axis, lockDir=False, stopRad=0)
```
## AddPlayerAroundPointMotion
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer
- 描述
给玩家添加对点环绕运动器
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| center | tuple(float,float,float) | 要环绕的圆心点坐标 |
| angularVelocity | float | 圆周运动的角速度(弧度/秒) |
| axis | tuple(float,float,float) | 圆周运动的轴,决定了在哪个平面上做圆周运动,默认为(0, 1, 0) |
| lockDir | bool | 是否在运动器生效时锁定实体的朝向不锁定则玩家的朝向会随着运动而改变默认为False。 |
| stopRad | float | 停止该运动器所需要的弧度当stopRad为0时该运动器会一直运行默认为0 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| int | 运动器ID添加失败时返回-1 |
- 备注
- 该接口不屏蔽玩家控制的移动以及重力作用,当有玩家控制发生时,最终的表现结果可能与预期有差异。由于玩家的头部与相机控制相关,若需要使运动器控制玩家的头部,请使用[DepartCamera](./摄像机.md#DepartCamera)分离玩家与摄像机。
- 环绕运动器可叠加多个,且可与速度运动器互相叠加。
- 由于引擎中有加载的区块限制建议将玩家的运动范围控制在当前位置±100内。
- 示例
```python
import mod.server.extraServerApi as serverApi
motionComp = serverApi.GetEngineCompFactory().CreateActorMotion(playerId)
center = (0, 8, 0)
axis=(-1, 1, 1)
mID = motionComp.AddPlayerAroundPointMotion(center, 1.0, axis, lockDir=False, stopRad=0)
```
## AddPlayerTrackMotion
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer
- 描述
给玩家添加轨迹运动器
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| targetPos | tuple(float,float,float) | 轨迹终点 |
| duraTime | float | 到达终点所需要的时间 |
| startPos | tuple(float,float,float) | 轨迹起点默认为None表示以调用[StartPlayerMotion](#StartPlayerMotion)的位置作为起点。 |
| relativeCoord | bool | 是否使用相对坐标设置起点和终点默认为False。 |
| isLoop | bool | 是否循环若设为True则玩家会在起点和终点之间往复运动。 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| int | 运动器ID添加失败时返回-1 |
- 备注
- 该接口不屏蔽玩家控制的移动,当有玩家控制发生时,最终的表现结果可能与预期有差异。
- 轨迹运动器不可叠加,仅能添加一个。
- 示例
```python
import mod.server.extraServerApi as serverApi
motionComp = serverApi.GetEngineCompFactory().CreateActorMotion(playerId)
target = (5, 0, 0)
mID = motionComp.AddPlayerTrackMotion(target, 3.0, startPos=None, relativeCoord=True, isLoop=False)
```
## AddPlayerVelocityMotion
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer
- 描述
给玩家添加速度运动器
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| velocity | tuple(float,float,float) | 速度,包含大小、方向 |
| accelerate | tuple(float,float,float) | 加速度包含大小、方向默认为None表示没有加速度 |
| useVelocityDir | bool | 是否使用当前速度的方向作为此刻实体的朝向默认为True |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| int | 运动器ID添加失败时返回-1 |
- 备注
- 该接口不屏蔽玩家控制的移动以及重力作用,当有玩家控制发生时,最终的表现结果可能与预期有差异。由于玩家的头部与相机控制相关,若需要使运动器控制玩家的头部,请使用[DepartCamera](./摄像机.md#DepartCamera)分离玩家与摄像机。
- 速度运动器可叠加多个,且可与环绕运动器互相叠加。
- 由于引擎中有加载的区块限制建议将玩家的运动范围控制在当前位置±100内。
- 示例
```python
import mod.server.extraServerApi as serverApi
motionComp = serverApi.GetEngineCompFactory().CreateActorMotion(playerId)
velocity = (0, 0, 1)
accelerate = (0, 0, -1)
mID = motionComp.AddPlayerVelocityMotion(velocity, accelerate, useVelocityDir=True)
```
## BeginSprinting
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.actorMotionCompClient.ActorMotionComponentClient
- 描述
使本地玩家进入并保持向前冲刺状态
- 参数
- 返回值
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateActorMotion(localPlayerId)
comp.BeginSprinting()
```
## ChangePlayerDimension
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.dimensionCompServer.DimensionCompServer
- 描述
传送玩家
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| dimensionId | int | 维度0-overWorld; 1-nether; 2-theEnd |
| pos | tuple(int,int,int) | 传送的坐标 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 备注
- 该接口在成功切换维度时pos位置为玩家头的位置即比设定位置低1.62
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateDimension(playerId)
comp.ChangePlayerDimension(0, (0,4,0))
```
## ChangePlayerFlyState
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.flyCompServer.FlyComponentServer
- 描述
给予/取消飞行能力,并且进入飞行/非飞行状态
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| isFly | bool | 飞行状态True飞行模式False正常行走模式 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | True:是 False:否 |
- 备注
- 不建议在OnGroundClientEvent事件回调中NotifyToServer然后服务端收到数据后调用ChangePlayerFlyState接口。
如果仍然需要这样调用则建议在服务端收到数据后用AddTimer延迟一帧后再调用ChangePlayerFlyState接口
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateFly(playerId)
comp.ChangePlayerFlyState(True)
```
## EnableKeepInventory
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
设置玩家死亡不掉落物品
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| enable | bool | 是否开启“保留物品栏” |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
succ = comp.EnableKeepInventory(True)
```
## EndSprinting
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.actorMotionCompClient.ActorMotionComponentClient
- 描述
使本地玩家结束向前冲刺状态
- 参数
- 返回值
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateActorMotion(localPlayerId)
comp.EndSprinting()
```
## GetEntityRider
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.rideCompServer.RideCompServer
- 描述
获取玩家正在骑乘的实体的id。
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| str | 玩家直接骑乘对象的实体id假如玩家没有骑乘则返回“-1” |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateRide(entityId)
riderId = comp.GetEntityRider()
```
## GetIsBlocking
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
获取玩家激活盾牌状态
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 玩家盾牌状态是否激活 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
comp.GetIsBlocking()
```
## GetPlayerExhaustionRatioByType
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
获取玩家某行为饥饿度消耗倍率
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| type | int | 行为枚举[PlayerExhauseRatioType枚举](../../枚举值/PlayerExhauseRatioType.md) |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| float | 饥饿度消耗倍率值, -1为获取失败 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
jumpType = serverApi.GetMinecraftEnum().PlayerExhauseRatioType.JUMP
ratio = comp.GetPlayerExhaustionRatioByType(jumpType)
```
## GetPlayerMotions
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer
- 描述
获取玩家身上的所有运动器
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| dict | 运动器集合key值代表运动器mIDvalue值代表运动器类型0轨迹运动器、1速度运动器、2环绕运动器 |
- 备注
- 运动器非人为停止后会被移除。
- 示例
```python
import mod.server.extraServerApi as serverApi
motionComp = serverApi.GetEngineCompFactory().CreateActorMotion(playerId)
motions = motionComp.GetPlayerMotions()
# motions = {
# 0:1,
# 1:2
# }
```
## GetPlayerRespawnPos
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
获取玩家复活点
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| dict | 复活点信息,包括维度和坐标 |
- 备注
- 使用spawnpoint指令设置玩家的出生点后该接口可以获取到设置后的出生点
- 未使用setworldspawn指令设置过出生点位置时返回坐标的y轴是32767
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
print comp.GetPlayerRespawnPos()
#结果示例 {'dimensionId': 0, 'pos': (44, 32767, 4)}
```
## GetRelevantPlayer
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
获取附近玩家id列表
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| list(str) | exceptList | 排除的玩家id列表,默认值为None,不排除其他玩家及自身 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| list(str) | 附近玩家id列表 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
comp.GetRelevantPlayer(exceptId)
```
## IsEntityRiding
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.rideCompServer.RideCompServer
- 描述
检查玩家是否骑乘。
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否骑乘 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateRide(entityId)
isRiding = comp.IsEntityRiding()
```
## IsPlayerFlying
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.flyCompServer.FlyComponentServer
- 描述
获取玩家是否在飞行
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | True:是 False:否 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateFly(playerId)
comp.IsPlayerFlying()
```
## PickUpItemEntity
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
某个Player拾取物品ItemEntity
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| playerEntityId | str | 拾取者的playerEntityId |
| itemEntityId | str | 要拾取的物品itemEntityId |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否拾取成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
comp.PickUpItemEntity(playerEntityId, itemEntityId)
```
## PlayerDestoryBlock
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer
- 描述
使用手上工具破坏方块
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| pos | tuple(int,int,int) | 方块位置 |
| particle | int | 是否开启破坏粒子效果,默认为开 |
| sendInv | bool | 是否同步服务端背包信息默认为不同步。因为破坏方块可能会造成手持物品耐久度降低等信息改变不同步信息可能会造成后续一些逻辑异常若大批量破坏方块每次同步会有性能问题建议前面的调用可令sendInv为False在最后一次调用此函数时传入sendInv为True。 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置结果 |
- 备注
- 手上工具的附魔效果会生效,同时扣除耐久度
- 会触发ServerPlayerTryDestroyBlockEvent事件并且可以被这个事件cancel
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateBlockInfo(playerId) # 此处playerId为block的破坏者
comp.PlayerDestoryBlock((0, 5, 0), 1, False)
comp.PlayerDestoryBlock((0, 6, 0), 1, True)
# 关闭破坏粒子效果
comp.PlayerDestoryBlock((0, 6, 0),0)
```
## PlayerUseItemToEntity
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer
- 描述
玩家使用手上物品对某个生物使用
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| entityId | str | 生物entityId |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置结果 |
- 备注
- 1.会触发PlayerInteractServerEvent事件并且可以被这个事件cancel2.此接口无视距离,但无法跨维度使用,同时需要目标区域已加载
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateBlockInfo(playerId) # 此处playerId为使用物品的玩家
suc = comp.PlayerUseItemToEntity("-123456")
```
## PlayerUseItemToPos
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer
- 描述
玩家对某个坐标使用物品
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| pos | tuple(int,int,int) | 坐标 |
| posType | int | 物品所在的地方[ItemPosType枚举](../../枚举值/ItemPosType.md) |
| slotPos | int | 槽位获取INVENTORY及ARMOR时需要设置其他情况写0即可 |
| facing | int | 朝向,详见[Facing枚举](../../枚举值/Facing.md) |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置结果 |
- 备注
- 当使用抛射物时只有在非创造模式下才会返回True;如果要对"盔甲架"等实体使用物品请使用PlayerUseItemToEntity接口;只能对玩家周边200格以内的坐标使用
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateBlockInfo(playerId) # 此处playerId为使用物品的玩家
comp.PlayerUseItemToPos((0, 5, 0), serverApi.GetMinecraftEnum().ItemPosType.INVENTORY, 0, 1)
```
## RemovePlayerMotion
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer
- 描述
移除玩家身上的运动器
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| motionId | int | 要移除的某个运动器的ID |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否成功移除 |
- 示例
```python
import mod.server.extraServerApi as serverApi
motionComp = serverApi.GetEngineCompFactory().CreateActorMotion(playerId)
motionComp.RemovePlayerMotion(mID)
```
## SetPickUpArea
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
设置玩家的拾取物品范围,设置后该玩家的拾取物品范围会在原版拾取范围的基础上进行改变。
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| area | tuple(float,float,float) | 拾取物品范围,传入(0, 0, 0)时视作取消设置 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
# 玩家拾取物品范围在X轴正负方向各增加5格在Z轴正负方向各增加3格在Y轴保持不变
succ = comp.SetPickUpArea((5, 0, 3))
```
## SetPlayerAttackSpeedAmplifier
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
设置玩家攻击速度倍数1.0表示正常水平1.2表示速度减益20%0.8表示速度增益20%
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| amplifier | float | 攻击速度倍数,范围[0.5,2.0] |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 备注
- 该接口影响接口[SetHurtCD](../世界/游戏规则.md#sethurtcd)设置的全局攻击cd
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
comp.SetPlayerAttackSpeedAmplifier(1.1)
```
## SetPlayerExhaustionRatioByType
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
设置玩家某行为饥饿度消耗倍率
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| type | int | 行为枚举[PlayerExhauseRatioType枚举](../../枚举值/PlayerExhauseRatioType.md) |
| ratio | float | 倍率 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
jumpType = serverApi.GetMinecraftEnum().PlayerExhauseRatioType.JUMP
ratio = comp.SetPlayerExhaustionRatioByType(jumpType, 20)
```
## SetPlayerJumpable
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
设置玩家是否可跳跃
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| isJumpable | bool | 是否可跳跃,True允许跳跃False禁止跳跃 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
comp.SetPlayerJumpable(False)
```
## SetPlayerMovable
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
设置玩家是否可移动
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| isMovable | bool | 是否可移动,True允许移动False禁止移动 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
comp.SetPlayerMovable(False)
```
## SetPlayerRespawnPos
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
设置玩家复活的位置与维度
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| pos | tuple(int,int,int) | 复活点的位置坐标 |
| dimensionId | int | 复活点的维度默认值为0主世界注意1维度21是不可用的注意2不能在玩家死亡PlayerDieEvent之后设置复活点 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
suc = comp.SetPlayerRespawnPos((0, 4, 0), 0)
```
## SetPlayerRideEntity
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.rideCompServer.RideCompServer
- 描述
设置玩家骑乘生物(或者船与矿车)
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| playerId | str | 玩家id |
| rideEntityId | str | 被骑乘生物id |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置结果 |
- 备注
- 通常需要配合SetEntityRide、SetControl一起使用
当被控制的entity有多个位置时且开发者想要添加多个玩家时第一个被添加的玩家会被引擎默认设置为控制者
- 示例
```python
# 骑上坐骑
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateRide(entityId)
comp.SetPlayerRideEntity(playerId,rideEntityId)
```
## StartPlayerMotion
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer
- 描述
启动玩家身上的某个运动器
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| motionId | int | 要启动的某个运动器的ID |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否成功启动 |
- 备注
- 由于玩家的运动器需要在客户端与服务端之间同步,所以请以[EntityMotionStartServerEvent](../../事件/实体.md#EntityMotionStartServerEvent)事件的触发作为真正的开始时机。
- 示例
```python
import mod.server.extraServerApi as serverApi
motionComp = serverApi.GetEngineCompFactory().CreateActorMotion(playerId)
motionComp.StartPlayerMotion(mID)
```
## StopEntityRiding
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.rideCompServer.RideCompServer
- 描述
强制玩家下坐骑。
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 当玩家当前正在骑乘并成功下坐骑返回True否则返回False |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateRide(entityId)
success = comp.StopEntityRiding()
```
## StopPlayerMotion
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer
- 描述
停止玩家身上的某个运动器
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| motionId | int | 要停止的某个运动器的ID |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否成功停止 |
- 备注
- 调用该接口不会触发事件[EntityMotionStopServerEvent](../../事件/实体.md#EntityMotionStopServerEvent)。
- 示例
```python
import mod.server.extraServerApi as serverApi
motionComp = serverApi.GetEngineCompFactory().CreateActorMotion(playerId)
motionComp.StopPlayerMotion(mID)
```
## isGliding
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.playerCompClient.PlayerCompClient
- 描述
是否鞘翅飞行
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否鞘翅飞行 |
- 示例
```python
comp = clientApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.isGliding()
```
## isInWater
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.playerCompClient.PlayerCompClient
- 描述
是否在水中
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否在水中 |
- 示例
```python
comp = clientApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.isInWater()
```
## isMoving
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.playerCompClient.PlayerCompClient
- 描述
是否在行走
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否在行走 |
- 示例
```python
comp = clientApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.isMoving()
```
## isRiding
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.playerCompClient.PlayerCompClient
- 描述
是否骑乘
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否骑乘 |
- 示例
```python
comp = clientApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.isRiding()
```
## isSneaking
<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
- 描述
获取玩家是否处于潜行状态
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 当前玩家是否处于潜行状态 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
is_sneaking = comp.isSneaking()
```
### 客户端接口
<span id="c0"></span>
method in mod.client.component.playerCompClient.PlayerCompClient
- 描述
是否潜行
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否潜行 |
- 示例
```python
comp = clientApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.isSneaking()
```
## isSprinting
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.playerCompClient.PlayerCompClient
- 描述
是否在疾跑
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否在疾跑 |
- 示例
```python
comp = clientApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.isSprinting()
```
## isSwimming
<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
- 描述
获取玩家是否处于游泳状态。
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 当前玩家是否处于游泳状态 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
is_swiming = comp.isSwimming()
```
### 客户端接口
<span id="c0"></span>
method in mod.client.component.playerCompClient.PlayerCompClient
- 描述
是否游泳
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否游泳 |
- 示例
```python
comp = clientApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.isSwimming()
```
## setMoving
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.playerCompClient.PlayerCompClient
- 描述
设置是否行走,只能设置本地玩家(只适用于移动端)
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 示例
```python
comp = clientApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.setMoving()
```
## setSneaking
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.playerCompClient.PlayerCompClient
- 描述
设置是否潜行,只能设置本地玩家(只适用于移动端)
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 示例
```python
comp = clientApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.setSneaking()
```
## setSprinting
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.playerCompClient.PlayerCompClient
- 描述
设置是否疾跑,只能设置本地玩家(只适用于移动端)
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 示例
```python
comp = clientApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.setSprinting()
```
## setUsingShield
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.playerCompClient.PlayerCompClient
- 描述
激活盾牌状态
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| flag | bool | True使用盾牌False取消使用盾牌 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| int | 1设置成功0设置失败-1玩家未持盾 |
- 示例
```python
comp = clientApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.setUsingShield(True)
```