SpawnNpc

From Wiki G1R-MP G1 Remake Multiplayer
Revision as of 09:55, 15 August 2026 by QCherry (talk | contribs) (Complete Lua function catalog)
Jump to navigation Jump to search

spawnNpc

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])

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.

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)
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.
  • 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.