---
title: "NPC_AddPointToPath | open.mp"
description: "向 NPC 路径添加路径点。"
canonical: https://omp.itsneufox.com/zh-CN/docs/scripting/functions/NPC_AddPointToPath
language: zh-CN
---

# NPC\_AddPointToPath

注意

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

## 描述

向 NPC 路径添加一个路径点。

| 参数 | 说明 |
| --- | --- |
| pathid | 要添加路径点的路径 ID |
| x | 路径点的 X 坐标 |
| y | 路径点的 Y 坐标 |
| z | 路径点的 Z 坐标 |
| stopRange | 认为到达该点时的距离阈值 |

## 返回值

成功时返回 `true`，失败时返回 `false`。

## 示例

```c
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (!strcmp(cmdtext, "/addpatrolpos", true))
    {
        new Float:x, Float:y, Float:z;
        GetPlayerPos(playerid, x, y, z);

        // 尝试添加巡逻点
        if (NPC_AddPointToPath(PlayerPatrolPath[playerid], x, y, z, 1.5))
        {
            SendClientMessage(playerid, 0x00FF00FF, "已在你的当前位置向路径 %d 添加路径点", PlayerPatrolPath[playerid]);
        }
        else
        {
            SendClientMessage(playerid, 0xFF0000FF, "向路径添加路径点失败");
        }
        return 1;
    }
    return 0;
}

```

## 注意事项

-   路径点按顺序添加以形成路径路线
-   `stopRange` 参数定义 NPC 需要距离点多近才能移动到下一个点
-   较小的 `stopRange` 值使 NPC 更精确地沿路径移动
-   在添加路径点前，必须先使用 `NPC_CreatePath` 创建路径

## 相关函数

-   [NPC\_CreatePath](https://omp.itsneufox.com/zh-CN/docs/scripting/functions/NPC_CreatePath): 创建新路径
-   [NPC\_RemovePointFromPath](https://omp.itsneufox.com/zh-CN/docs/scripting/functions/NPC_RemovePointFromPath): 从路径中移除路径点
-   [NPC\_GetPathPoint](https://omp.itsneufox.com/zh-CN/docs/scripting/functions/NPC_GetPathPoint): 获取特定点的详细信息
-   [NPC\_MoveByPath](https://omp.itsneufox.com/zh-CN/docs/scripting/functions/NPC_MoveByPath): 使 NPC 沿路径移动
-   [NPC\_GetPathPointCount](https://omp.itsneufox.com/zh-CN/docs/scripting/functions/NPC_GetPathPointCount): 获取路径中的路径点数量

## 相关回调

-   [OnNPCFinishMovePathPoint](https://omp.itsneufox.com/zh-CN/docs/scripting/callbacks/OnNPCFinishMovePathPoint): NPC 到达每个路径点时调用
-   [OnNPCFinishMovePath](https://omp.itsneufox.com/zh-CN/docs/scripting/callbacks/OnNPCFinishMovePath): NPC 完成沿路径移动时调用
-   [OnNPCFinishMove](https://omp.itsneufox.com/zh-CN/docs/scripting/callbacks/OnNPCFinishMove): NPC 完成任何移动时调用
