SpawnNpc: Difference between revisions
Jump to navigation
Jump to search
Complete Lua function catalog |
Document G1R:MP 0.1.2 navigation collision API |
||
| Line 1: | Line 1: | ||
= spawnNpc = | = spawnNpc = | ||
<div style="background:#fff5f5; border:1px solid #d13b3b; border-left:5px solid #d13b3b; color:#111111; padding:0.85rem 1rem; margin:0.75rem 0 1rem;"> | |||
<div style="color:#111111; font-weight:bold; letter-spacing:0.04em;">IMPROVED FROM UPDATE 0.1.2</div> | |||
<div style="color:#111111; margin-top:0.25rem;">This function is available in earlier releases and has corrected or expanded behavior in G1R:MP 0.1.2 and later. The contract below describes the updated behavior.</div> | |||
</div> | |||
Creates a server-owned human visual NPC at an authoritative position. | Creates a server-owned human visual NPC at an authoritative position. | ||
== Syntax == | == Syntax == | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
int|false spawnNpc(string name, string skinKey, number x, number y, number z [, number yaw = 0]) | int|false spawnNpc(string name, string skinKey, number x, number y, number z [, number yaw = 0] [, table options]) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 23: | Line 27: | ||
|- | |- | ||
| <code>yaw</code> || <code>number</code> || no || Optional initial yaw in degrees; defaults to 0. | | <code>yaw</code> || <code>number</code> || no || Optional initial yaw in degrees; defaults to 0. | ||
|- | |||
| <code>options</code> || <code>table</code> || no || Optional table. Set <code>navigationCollisionMode</code> to <code>"combined"</code>, <code>"builtin"</code>, or <code>"custom"</code>; the default is <code>"combined"</code>. | |||
|} | |} | ||
| Line 31: | Line 37: | ||
Place a guard and equip it: | Place a guard and equip it: | ||
<syntaxhighlight lang="lua" line> | <syntaxhighlight lang="lua" line> | ||
local npcId = spawnNpc("North Gate Guard", "guard_01", 12.5, 4.0, 1.8, 180) | local npcId = spawnNpc("North Gate Guard", "guard_01", 12.5, 4.0, 1.8, 180, { | ||
navigationCollisionMode = "combined", | |||
}) | |||
if npcId then | if npcId then | ||
setNpcArmor(npcId, "guard_armor") | setNpcArmor(npcId, "guard_armor") | ||
| Line 41: | Line 49: | ||
* Available only in server-side resource scripts. | * Available only in server-side resource scripts. | ||
* The calling resource owns the NPC and is the only resource allowed to mutate or remove it. | * The calling resource owns the NPC and is the only resource allowed to mutate or remove it. | ||
* The selected navigation collision mode is applied to initial placement. Pass it during spawn when replacing a known baked false positive with custom blockers. | |||
* Identity, transform, skin, armor and weapon are replicated on relevance entry and late join. | * Identity, transform, skin, armor and weapon are replicated on relevance entry and late join. | ||
* This creates a script-controlled visual proxy; routes are configured separately with <code>setNpcRoute</code>. | * This creates a script-controlled visual proxy; routes are configured separately with <code>setNpcRoute</code>. | ||
Latest revision as of 13:52, 4 September 2026
spawnNpc
IMPROVED FROM UPDATE 0.1.2
This function is available in earlier releases and has corrected or expanded behavior in G1R:MP 0.1.2 and later. The contract below describes the updated behavior.
Creates a server-owned human visual NPC at an authoritative position.
Syntax
int|false spawnNpc(string name, string skinKey, number x, number y, number z [, number yaw = 0] [, table options])
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
name |
string |
yes | Validated display name for the NPC. |
skinKey |
string |
yes | A preset returned by getPlayerSkinNames.
|
x |
number |
yes | Spawn X coordinate in metres. |
y |
number |
yes | Spawn Y coordinate in metres. |
z |
number |
yes | Spawn Z coordinate in metres. |
yaw |
number |
no | Optional initial yaw in degrees; defaults to 0. |
options |
table |
no | Optional table. Set navigationCollisionMode to "combined", "builtin", or "custom"; the default is "combined".
|
Returns
Returns the new numeric NPC identifier, or false when validation or spawning fails.
Examples
Place a guard and equip it:
local npcId = spawnNpc("North Gate Guard", "guard_01", 12.5, 4.0, 1.8, 180, {
navigationCollisionMode = "combined",
})
if npcId then
setNpcArmor(npcId, "guard_armor")
setNpcWeapon(npcId, "1h_sword_01")
end
Notes
- Available only in server-side resource scripts.
- The calling resource owns the NPC and is the only resource allowed to mutate or remove it.
- The selected navigation collision mode is applied to initial placement. Pass it during spawn when replacing a known baked false positive with custom blockers.
- Identity, transform, skin, armor and weapon are replicated on relevance entry and late join.
- This creates a script-controlled visual proxy; routes are configured separately with
setNpcRoute.