NPCs
Server-side NPCs: creation, removal, AI and routine actions.
NPCs created by server scripts. Every NPC has an id from gmp.getMaxSlots() up, and all Players functions work for it too (name, attributes, items, position, combat...). The functions below work only for server-side NPCs: they control the NPC's AI and routine actions, which make no sense for a player - called with a player id they return false.
Creation and removal
createNpc
gmp.createNpc(class, x, y, z, angle)Creates a server-side NPC and returns its id right away. The NPC appears in the game of every player (each game creates it asynchronously, usually within about a second). It is created exactly as the game makes it - with the stats, skills, inventory, appearance and AI of its class.
local guard = gmp.createNpc("CharacterDefinition_Human_OC_GRD_Jackal_201", 1200, -350, 80, 90)
gmp.setPlayerName(guard, "Jackal")
gmp.setNpcRelation(guard, pid, gmp.enum.Relation.Hostile)| Parameter | Type | Description |
|---|---|---|
class | gmp.CharacterClass | Class of the NPC: a human character definition or a spawn definition of the game. |
x | number | X coordinate of the spawn point (cm). |
y | number | Y coordinate of the spawn point (cm). |
z | number | Z coordinate of the spawn point (cm); give a point slightly above the ground. |
angle | number | Facing angle (yaw) in degrees: 0 = world X axis, 90 = world Y axis. |
Returns: integer - Id of the new NPC (gmp.getMaxSlots() or above).
destroyNpc
gmp.destroyNpc(npcId)Removes a server-side NPC from the world of every player. Its id becomes free.
| Parameter | Type | Description |
|---|---|---|
npcId | integer | Id of the NPC. |
Returns: boolean - false when the id is not an existing server-side NPC.
isNpc
gmp.isNpc(id)Tells whether the id belongs to an existing server-side NPC.
| Parameter | Type | Description |
|---|---|---|
id | integer | Any character id. |
Returns: boolean - false for player ids and for ids of removed or never created NPCs.
AI
setNpcPassive
gmp.setNpcPassive(npcId, passive)Makes the NPC's AI passive: it does not react to threats - does not attack and does not flee.
| Parameter | Type | Description |
|---|---|---|
npcId | integer | Id of the NPC. |
passive | boolean | true = passive. |
Returns: boolean
setNpcInteractable
gmp.setNpcInteractable(npcId, interactable)Enables or disables talking to the NPC and searching it.
| Parameter | Type | Description |
|---|---|---|
npcId | integer | Id of the NPC. |
interactable | boolean | false = players cannot talk to it or search it. |
Returns: boolean
setNpcRelation
gmp.setNpcRelation(npcId, targetId, relation)Sets how the NPC treats another character - whether its AI takes it as a target (attacks it, starts combat music). The relation is ONE-WAY and applies to the NPC's own decisions.
gmp.setNpcRelation(guard, pid, gmp.enum.Relation.Hostile) -- the guard attacks the player| Parameter | Type | Description |
|---|---|---|
npcId | integer | Id of the NPC. |
targetId | integer | Id of the player or server-side NPC the relation refers to. |
relation | gmp.enum.Relation | New relation. |
Returns: boolean
getNpcRelation
gmp.getNpcRelation(npcId, targetId)Returns how the NPC treats another character (one-way, see setNpcRelation).
| Parameter | Type | Description |
|---|---|---|
npcId | integer | Id of the NPC. |
targetId | integer | Id of the player or server-side NPC the relation refers to. |
Returns: gmp.enum.Relation | nil
Routine actions
The NPC uses the nearest world object of the right kind within maxDistance (default 1000 cm): it is placed in front of the object and the game performs the interaction with its animations. An NPC busy with another interaction cannot start a new one (stand up or leave the ladder first).
npcSitDown
gmp.npcSitDown(npcId, maxDistance?)Sits the NPC down on the nearest free bench or chair. It stays seated until npcStandUp.
| Parameter | Type | Description |
|---|---|---|
npcId | integer | Id of the NPC. |
maxDistance (optional) | number | Search radius in cm. Default 1000. |
Returns: boolean - false when there is no free seat within the radius or the game rejected it.
npcStandUp
gmp.npcStandUp(npcId)Makes a seated NPC stand up.
| Parameter | Type | Description |
|---|---|---|
npcId | integer | Id of the NPC. |
Returns: boolean - false when the NPC is not sitting.
npcUseLadder
gmp.npcUseLadder(npcId, fast?, maxDistance?)Makes the NPC climb the nearest ladder from the side it stands at, to the other end, and get off.
| Parameter | Type | Description |
|---|---|---|
npcId | integer | Id of the NPC. |
fast (optional) | boolean | true = climbing up quickly / sliding down. Default false. |
maxDistance (optional) | number | Search radius in cm. Default 1000. |
Returns: boolean - false when there is no ladder within the radius or the game rejected it.
setNpcLadderFast
gmp.setNpcLadderFast(npcId, fast)Speeds up or slows down an NPC that is on a ladder.
| Parameter | Type | Description |
|---|---|---|
npcId | integer | Id of the NPC. |
fast | boolean | true = fast climbing up / sliding down; false = normal steps. |
Returns: boolean - false when the NPC is not on a ladder.
npcLightTorch
gmp.npcLightTorch(npcId, maxDistance?)Makes the NPC light the nearest roadside torch or fire basket. As in the game, the NPC needs a torch in hand.
| Parameter | Type | Description |
|---|---|---|
npcId | integer | Id of the NPC. |
maxDistance (optional) | number | Search radius in cm. Default 1000. |
Returns: boolean - false when there is no torch within the radius or the game rejected it.
npcExtinguishTorch
gmp.npcExtinguishTorch(npcId, maxDistance?)Makes the NPC extinguish the nearest roadside torch or fire basket.
| Parameter | Type | Description |
|---|---|---|
npcId | integer | Id of the NPC. |
maxDistance (optional) | number | Search radius in cm. Default 1000. |
Returns: boolean - false when there is no torch within the radius or the game rejected it.
