Files
netease-modsdk-wiki/docs/mcdocs/1-ModAPI/接口/世界/指令.md
2025-03-17 13:24:39 +08:00

176 lines
4.7 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
---
# 指令
## GetCommandPermissionLevel
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.commandCompServer.CommandCompServer
- 描述
返回设定使用/op命令时OP的权限等级对应server.properties中的op-permission-level配置
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| int | 权限等级1-OP可以绕过重生点保护2-OP可以使用所有单人游戏作弊命令3-OP可以使用大多数多人游戏中独有的命令4-OP可以使用所有命令 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateCommand(levelId)
opLevel = comp.GetCommandPermissionLevel()
print "GetCommandPermissionLevel oplevel={}".format(opLevel)
```
## GetDefaultPlayerPermissionLevel
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.commandCompServer.CommandCompServer
- 描述
返回新玩家加入时的权限身份对应server.properties中的default-player-permission-level配置
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| int | 权限身份0-Visitor1-Member2-Operator3-自定义 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateCommand(levelId)
opLevel = comp.GetDefaultPlayerPermissionLevel()
print "GetDefaultPlayerPermissionLevel oplevel={}".format(opLevel)
```
## SetCommand
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.commandCompServer.CommandCompServer
- 描述
使用游戏内指令
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| cmdStr | str | 指令 |
| playerId | str | 玩家id:可选如果playerId不设置则随机选择玩家 |
| showOutput | bool | 是否输出到聊天窗口可选默认False如果为True的话指令正确时才会和聊天框输入原生指令一样输出返回信息。只有当该参数为True的时候会触发OnCommandOutputServerEvent与OnCommandOutputClientEvent |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 命令是否执行成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateCommand(levelId)
comp.SetCommand("/tp @p 100 5 100")#传送指令
```
## SetCommandPermissionLevel
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.commandCompServer.CommandCompServer
- 描述
设置当玩家使用/op命令时OP的权限等级对应server.properties中的op-permission-level配置
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| opLevel | int | 权限等级1-OP可以绕过重生点保护2-OP可以使用所有单人游戏作弊命令3-OP可以使用大多数多人游戏中独有的命令4-OP可以使用所有命令 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 命令是否执行成功 |
- 备注
- 此API不会修改已经获取了op的玩家的权限等级仅影响调用API之后才获取op的玩家建议在游戏初始化时调用此API
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateCommand(levelId)
opLevel = 4
suc = comp.SetCommandPermissionLevel(opLevel)
print "SetCommandPermissionLevel to {} suc={}".format(opLevel, suc)
```
## SetDefaultPlayerPermissionLevel
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.commandCompServer.CommandCompServer
- 描述
设置新玩家加入时的权限身份对应server.properties中的default-player-permission-level配置
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| opLevel | int | 权限身份0-Visitor1-Member2-Operator3-自定义 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 命令是否执行成功 |
- 备注
- 此API不会修改已经加入过游戏的玩家的权限身份仅影响调用API之后才新加入的玩家建议在游戏初始化时调用此API
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateCommand(levelId)
opLevel = 1
suc = comp.SetDefaultPlayerPermissionLevel(opLevel)
print "SetDefaultPlayerPermissionLevel to {} suc={}".format(opLevel, suc)
```