---
title: "NPC_Move | open.mp"
description: "让 NPC 移动到指定位置。"
canonical: https://omp.itsneufox.com/zh-CN/docs/scripting/functions/NPC_Move
language: zh-CN
---

# NPC\_Move

注意

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

## 描述

让 NPC 移动到指定位置。

| 参数 | 说明 |
| --- | --- |
| npcid | NPC 的 ID。 |
| Float:x | 要移动到的 X 坐标。 |
| Float:y | 要移动到的 Y 坐标。 |
| Float:z | 要移动到的 Z 坐标。 |
| NPC\_MOVE\_TYPE:moveType | [移动类型](https://omp.itsneufox.com/zh-CN/docs/scripting/resources/npc-constants#%E7%A7%BB%E5%8A%A8%E7%B1%BB%E5%9E%8B)（默认: `NPC_MOVE_TYPE_JOG`）。 |
| Float:moveSpeed | [移动速度](https://omp.itsneufox.com/zh-CN/docs/scripting/resources/npc-constants#%E7%A7%BB%E5%8A%A8%E9%80%9F%E5%BA%A6)（默认: `NPC_MOVE_SPEED_AUTO`）。 |
| Float:stopRange | 停止前到目标的距离（默认: 0.2）。 |

## 返回值

如果移动成功开始则返回`true`，否则返回`false`。

## 示例

```c
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (!strcmp(cmdtext, "/npcmove", true))
    {
        new npcid = PlayerNPC[playerid];
        if (npcid == INVALID_NPC_ID)
            return SendClientMessage(playerid, 0xFF0000FF, "你没有在调试NPC。");

        if (!NPC_IsValid(npcid))
            return SendClientMessage(playerid, 0xFF0000FF, "无效的NPC。");

        new Float:x, Float:y, Float:z;
        GetPlayerPos(playerid, x, y, z);

        NPC_Move(npcid, x, y, z, NPC_MOVE_TYPE_JOG, NPC_MOVE_SPEED_AUTO, 0.2);

        SendClientMessage(playerid, 0x00FF00FF, "NPC %d 正在移动到 (%.2f, %.2f, %.2f)", npcid, x, y, z);
        return 1;
    }
    return 0;
}
```

## 注意事项

备注

-   NPC 将寻路到目标位置。
-   移动类型影响动画和速度。
-   停止范围决定 NPC 在停止前离目标多近。

技巧

使用 [NPC\_IsMoving](https://omp.itsneufox.com/zh-CN/docs/scripting/functions/NPC_IsMoving) 检查 NPC 当前是否正在移动

## 相关函数

-   [NPC\_MoveToPlayer](https://omp.itsneufox.com/zh-CN/docs/scripting/functions/NPC_MoveToPlayer): 让 NPC 移动跟随玩家。
-   [NPC\_StopMove](https://omp.itsneufox.com/zh-CN/docs/scripting/functions/NPC_StopMove): 停止 NPC 移动。
-   [NPC\_IsMoving](https://omp.itsneufox.com/zh-CN/docs/scripting/functions/NPC_IsMoving): 检查 NPC 是否正在移动。
-   [NPC\_MoveByPath](https://omp.itsneufox.com/zh-CN/docs/scripting/functions/NPC_MoveByPath): 让 NPC 沿预定义路径移动。

## 相关回调

-   [OnNPCFinishMove](https://omp.itsneufox.com/zh-CN/docs/scripting/callbacks/OnNPCFinishMove): NPC 完成移动时调用。

## 相关资源

-   [NPC 常量](https://omp.itsneufox.com/zh-CN/docs/scripting/resources/npc-constants)
