SetNpcRoute: Difference between revisions
Jump to navigation
Jump to search
Update Lua API reference |
Complete Lua function catalog |
||
| Line 36: | Line 36: | ||
* Route progress emits <code>onNpcRoutePoint</code> and non-looping completion emits <code>onNpcRouteComplete</code>. | * Route progress emits <code>onNpcRoutePoint</code> and non-looping completion emits <code>onNpcRouteComplete</code>. | ||
[[Category:Lua Functions]] | |||
[[Category:Server Functions]] | [[Category:Server Functions]] | ||
[[Category:World Functions]] | [[Category:World Functions]] | ||
[[Category:NPC Functions]] | [[Category:NPC Functions]] | ||
Revision as of 09:55, 15 August 2026
setNpcRoute
Assigns an ordered, optionally looping movement route to a resource-owned NPC.
Syntax
bool setNpcRoute(int npcId, table points [, table options])
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
npcId |
int |
yes | The server-assigned NPC identifier returned by spawnNpc or getNpcs.
|
points |
table |
yes | A one-based array of 1-256 points. Every point has x, y and z in metres and may have yaw in degrees and waitMs from 0 to 3600000. |
options |
table |
no | Optional { loop = bool, speed = number }; speed is 0.1-12 metres per second and defaults to 1.
|
Returns
Returns true when the complete route is validated and started; otherwise returns false.
Examples
Patrol between two guard posts:
setNpcRoute(npcId, {
{ x = 10, y = 5, z = 2, yaw = 90, waitMs = 1500 },
{ x = 18, y = 5, z = 2, yaw = 270, waitMs = 1500 },
}, { loop = true, speed = 1.8 })
Notes
- Available only in server-side resource scripts.
- Movement is simulated by the server and replicated as normal smoothed remote snapshots.
- Route progress emits
onNpcRoutePointand non-looping completion emitsonNpcRouteComplete.