SpawnNpc

From Wiki G1R-MP G1 Remake Multiplayer
Jump to navigation Jump to search

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.