> 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/players.md).

# 玩家

该 `玩家` 模块允许 [场景](https://github.com/decentraland/docs/blob/main/contributor/content/entity-types/scenes/README.md) 用于在其环境中查找玩家并获取有关其身份和 [资料](https://github.com/decentraland/docs/blob/main/contributor/content/entity-types/profiles/README.md).

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

它包含以下方法和类型：

* [`函数 getPlayersInScene`](#getPlayersInScene)
* [`函数 getConnectedPlayers`](#getPlayersInScene)
* [`函数 getPlayerData`](#getPlayerData)
* [`接口 Player`](#Player)
* [`interface UserData`](#UserData)

### 方法

此模块中有两个方法用于发现场景中的玩家，另有一个方法用于获取他们的资料。

**`getPlayersInScene`**

返回一个 [`Player`](#Player) 数组，每个都带有一个 `userId` 可用于 [getPlayerData](#getPlayerData).

```ts
interface Request {}

interface Response {
  players: Player[];
}

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

**`getConnectedPlayers`**

```ts
interface Request {}

interface Response {
  players: Player[];
}

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

**`getPlayerData`**

返回 [`UserData`](#UserData) 用于某个用户，如果已知该给定 `userId`.

```ts
接口 Request {
  // 用户标识符（对于非访客，即其 Ethereum 地址）。
  userId: string;
}

interface Response {
  // 该用户的个人资料信息（如果可用）。
  data?: UserData;
}

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

### 类型

此模块中只有两种类型： [`Player`](#Player) 和 [`UserData`](#UserData).

**`Player`**

持有对一个 `userId`.

```ts
interface Player {
  // 用户标识符（对于非访客，即其 Ethereum 地址）。
  userId: string;
}
```

**`UserData`**

保存有关用户、其身份和头像的（可能不完整的）信息。

World Explorers 通过 [内容系统](https://github.com/decentraland/docs/blob/main/contributor/content/overview/README.md).

该 [个人资料实体定义](https://github.com/decentraland/docs/blob/main/contributor/content/entity-types/profiles/README.md) 详细说明这些字段及更多内容。虽然 `UserData` 的结构和键略有不同，但每个字段的含义是相同的。

```ts
export interface UserData {
  // 用户标识符（即其 Ethereum 地址）。
  userId: string;

  // 在界面中称呼他们的名称。
  displayName: string;

  // 他们用于签名的以太坊公钥。
  publicKey?: string;

  // 他们是否已启用 web3 功能。
  hasConnectedWeb3: boolean;

  // 此信息的顺序版本，每次用户更新时递增。
  version: number;

  // 有关其头像的信息（如果可用）。
  avatar?: {
    // 渲染此头像所需资源的指针。
    bodyShape: string;
    wearables: string[];

    // 不同身体部位的十六进制编码 RGB/RGBA 颜色色调。
    skinColor: string;
    hairColor: string;
    eyeColor: string;

    // 此头像“照片”的文件标识符。
    snapshots?: {
      face256: string;
      body: string;
    };
  };
}
```


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
