---
title: "GetPlayers | open.mp"
description: "获取当前在线玩家的ID数组"
canonical: https://omp.itsneufox.com/zh-CN/docs/scripting/functions/GetPlayers
language: zh-CN
---

# GetPlayers

注意

这个函数是在omp v1.1.0.2612中添加的，在以前的版本中不起作用！

## 描述

获取当前服务器在线玩家的 ID 数组

| 参数 | 说明 |
| --- | --- |
| players\[\] | 存储玩家 ID 的数组（通过引用传递） |
| size | 数组的容量大小 |

## 返回值

返回实际存入数组的玩家数量

## 示例代码

假设服务器有 5 个在线玩家：

```c
new players[MAX_PLAYERS];
new length;

length = GetPlayers(players, sizeof(players));
// players数组现在包含在线玩家ID：{ 0, 1, 2, 3, 4 }
// length变量的值为5
```

## 相关函数

-   [GetVehicles](https://omp.itsneufox.com/zh-CN/docs/scripting/functions/GetVehicles): 获取已创建车辆的 ID 数组
-   [GetActors](https://omp.itsneufox.com/zh-CN/docs/scripting/functions/GetActors): 获取已创建演员的 ID 数组
