---
title: "NPC_ClearPath | open.mp"
description: "清除 NPC 路径中的所有路径点。"
canonical: https://omp.itsneufox.com/zh-CN/docs/scripting/functions/NPC_ClearPath
language: zh-CN
---

# NPC\_ClearPath

注意

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

## 描述

清除 NPC 路径中的所有点，使其变为空路径。

| 参数 | 说明 |
| --- | --- |
| pathid | 要清除的路径 ID |

## 返回值

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

## 示例

```c
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (!strcmp(cmdtext, "/clearpatrol", true))
    {
        // 获取清除前的点数
        new count = NPC_GetPathPointCount(PlayerPatrolPath[playerid]);

        // 尝试清除路径
        if (NPC_ClearPath(PlayerPatrolPath[playerid]))
        {
            SendClientMessage(playerid, 0x00FF00FF, "已清除路径 %d（移除了 %d 个点）", PlayerPatrolPath[playerid], count);
        }
        else
        {
            SendClientMessage(playerid, 0xFF0000FF, "清除路径失败");
        }

        return 1;
    }
    return 0;
}
```

## 注意事项

-   此函数会从指定路径中移除所有路径点
-   路径本身保持有效状态，可以重复使用
-   当前正在沿此路径移动的任何 NPC 将停止移动

## 相关函数

-   [NPC\_CreatePath](https://omp.itsneufox.com/zh-CN/docs/scripting/functions/NPC_CreatePath): 创建新路径
-   [NPC\_AddPointToPath](https://omp.itsneufox.com/zh-CN/docs/scripting/functions/NPC_AddPointToPath): 向路径添加点
-   [NPC\_RemovePointFromPath](https://omp.itsneufox.com/zh-CN/docs/scripting/functions/NPC_RemovePointFromPath): 移除特定点
-   [NPC\_GetPathPointCount](https://omp.itsneufox.com/zh-CN/docs/scripting/functions/NPC_GetPathPointCount): 获取路径中的点数

## 相关回调

-   [OnNPCFinishMovePath](https://omp.itsneufox.com/zh-CN/docs/scripting/callbacks/OnNPCFinishMovePath): NPC 完成路径时调用
