> For the complete documentation index, see [llms.txt](https://docs.decentraland.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.decentraland.org/contributor/contributor-zh/chang-jing-yun-xing-shi/yun-xing-shi-mo-kuai/restricted-actions.md).

# 受限操作

该 `RestrictedActions` 该模块允许场景访问敏感（因此受限）的功能。它与 [`权限`](https://github.com/decentraland/docs/tree/main/contributor/content/entity-types/scenes/README.md#permissions) 系统相关联，场景使用它来请求使用各个方法。

```ts
const RestrictedActions = require("~system/RestrictedActions");
```

{% hint style="info" %}
作为 World Explorer 的实现者，你的运行时可能不会强制执行权限。我们 **强烈** 不建议这样做，因为这会使玩家处于危险之中。
{% endhint %}

大部分受限功能都由此模块提供，但也有受限的 [全局函数](https://github.com/decentraland/docs/tree/main/contributor/globals/README.md).

该模块包含以下方法和类型：

* [`function movePlayerTo`](#movePlayerTo)
* [`function teleportTo`](#teleportTo)
* [`function triggerEmote`](#triggerEmote)
* [`function changeRealm`](#changeRealm)
* [`function openExternalUrl`](#openExternalUrl)
* [`function openNftDialog`](#openNftDialog)
* [`function setCommunicationsAdapter`](#setCommunicationsAdapter)
* [`interface Vector3`](#Vector3)

### 方法

下面每个方法都与一个特定的 [权限](https://github.com/decentraland/docs/tree/main/contributor/content/entity-types/scenes/README.md#permissions) 权限相关联，该权限可在场景清单中请求。

**`movePlayerTo`**

将玩家移动到相对于当前位置的新位置，并可选地使用 [向量](#Vector3).

需要 [`ALLOW_TO_MOVE_PLAYER_INSIDE_SCENE`](https://github.com/decentraland/docs/tree/main/contributor/content/entity-types/scenes/README.md#permissions) 权限。

```ts
interface Request {
  newRelativePosition: Vector3;
  cameraTarget?: Vector3;
}

interface Response {
    // 一旦玩家移动到新位置，并且如果玩家没有中断移动，这将为 true。
  success: boolean;
}

function movePlayerTo(Request): Promise<Response>;
```

**`teleportTo`**

将玩家重新定位到一个地块，可选地位于另一个 realm 中。

不要求预先批准的权限，而是对 `teleportTo` 的每次调用都必须由玩家批准。

```ts
interface Request {
  // 要落脚的地块。省略：该 realm 的默认出生点
  // （仅在与 `realm` 一起使用时才有意义）。
  worldCoordinates?: Vector2;

  // 该地块所属的 realm：世界名称（`foo.dcl.eth`）或 realm URL。
  // 设置后，客户端会切换 realm（完全重新连接，甚至连到该
  // 玩家已经所在的 realm），然后在那里落脚到该地块。
  // 省略：该地块位于玩家当前的 realm 中。
  realm?: string;
}

interface Response {}

function teleportTo(Request): Promise<Response>;
```

**`triggerEmote`**

使用预定义名称之一，让玩家的头像播放一个表情动画。

需要 [`ALLOW_TO_TRIGGER_AVATAR_EMOTE`](https://github.com/decentraland/docs/tree/main/contributor/content/entity-types/scenes/README.md#permissions) 权限。

```ts
interface Request {
  predefinedEmote: string;
}

interface Response {}

function triggerEmote(Request): Promise<Response>;
```

**`openExternalUrl`**

使用适当的 UI 向玩家显示一个网站。

需要 [`OPEN_EXTERNAL_LINK`](https://github.com/decentraland/docs/tree/main/contributor/content/entity-types/scenes/README.md#permissions) 权限。

```ts
interface Request {
  url: string;
}

interface Response {
  // 玩家是否授权打开该链接。
  success: boolean;
}

function openExternalUrl(Request): Promise<Response>;
```

**`openNftDialog`**

使用适当的 UI 向玩家显示关于 NFT 的信息。

```ts
interface Request {
  // NFT 的 URN。
  urn: string;
}

interface Response {
  // NFT 是否已成功定位并关联到一张图片或视频。
  success: boolean;
}

function openNftDialog(Request): Promise<Response>;
```

**`changeRealm`** （已弃用）

使用其基础 URL 将 World Explorer 切换到另一个内容服务器。

已弃用，改用 [`teleportTo`](#teleportTo) 配合一个 `realm` （并且没有 `worldCoordinates` 用于该 realm 的默认出生点）。 `changeRealm` 在更改被接受时即解析，而不是在新 realm 上线时，因此 `teleportTo` 在它运行后立即发出的请求会针对之前的 realm。

```ts
interface Request {
  // 新 realm 的 URL。
  realm: string;

  // 当用户需要批准更改时向其显示的可选消息。
  message?: string;
}

interface Response {
  // realm 更改是否已获授权并成功。
  success: boolean;
}

function changeRealm(Request): Promise<Response>;
```

### 类型

此模块中的方法所使用的唯一额外类型是 `Vector3`.

**`Vector3`**

保存相对或绝对的 3D 位置。

```ts
interface Vector3 {
  x: number;
  y: number;
  z: number;
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.decentraland.org/contributor/contributor-zh/chang-jing-yun-xing-shi/yun-xing-shi-mo-kuai/restricted-actions.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
