跳到主要内容

NPC_MoveByPath

注意

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

描述

使 NPC 沿预定义路径移动,支持多种移动选项。

参数说明
npcidNPC 的 ID
pathid要跟随的路径 ID
moveType移动类型(默认:NPC_MOVE_TYPE_JOG)
moveSpeed移动速度(默认:NPC_MOVE_SPEED_AUTO)
reversed是否反向跟随路径(默认:false)

返回值

如果 NPC 开始跟随路径返回 true,否则返回 false

示例

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

new count = NPC_GetPathPointCount(PlayerPatrolPath[playerid]);

if (NPC_IsValidPath(PlayerPatrolPath[playerid]))
{
NPC_MoveByPath(npcid, PlayerPatrolPath[playerid], NPC_MOVE_TYPE_WALK);
SendClientMessage(playerid, 0x00FF00FF, "开始巡逻路线,共 %d 个点", npcid, count);

StopPlayerPatrolTimer(playerid);
PlayerPatrolTimer[playerid] = SetTimerEx("CheckPathProgress", 2000, true, "i", playerid);
}
else
{
SendClientMessage(playerid, 0xFF0000FF, "开始巡逻失败");
}
return 1;
}
return 0;
}

注意事项

  • 路径必须通过 NPC_CreatePath 创建,且调用此函数前路径至少需包含一个路径点
  • 使用 NPC_AddPointToPath 构建行进路线,若需重置路径请调用 NPC_ClearPath
  • 设置 reversed = true 可使 NPC 按相反顺序遍历路径
  • 当 NPC 无效、正在执行不兼容动作或路径无法被跟随时,返回 false

相关函数

相关回调