Przejdź do treści
Gothic MultiplayerMultiplayer
Gothic MP Wiki

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)
ParameterTypeDescription
classgmp.CharacterClassClass of the NPC: a human character definition or a spawn definition of the game.
xnumberX coordinate of the spawn point (cm).
ynumberY coordinate of the spawn point (cm).
znumberZ coordinate of the spawn point (cm); give a point slightly above the ground.
anglenumberFacing 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.

ParameterTypeDescription
npcIdintegerId 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.

ParameterTypeDescription
idintegerAny 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.

ParameterTypeDescription
npcIdintegerId of the NPC.
passivebooleantrue = passive.

Returns: boolean

setNpcInteractable

gmp.setNpcInteractable(npcId, interactable)

Enables or disables talking to the NPC and searching it.

ParameterTypeDescription
npcIdintegerId of the NPC.
interactablebooleanfalse = 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
ParameterTypeDescription
npcIdintegerId of the NPC.
targetIdintegerId of the player or server-side NPC the relation refers to.
relationgmp.enum.RelationNew relation.

Returns: boolean

getNpcRelation

gmp.getNpcRelation(npcId, targetId)

Returns how the NPC treats another character (one-way, see setNpcRelation).

ParameterTypeDescription
npcIdintegerId of the NPC.
targetIdintegerId 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.

ParameterTypeDescription
npcIdintegerId of the NPC.
maxDistance (optional)numberSearch 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.

ParameterTypeDescription
npcIdintegerId 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.

ParameterTypeDescription
npcIdintegerId of the NPC.
fast (optional)booleantrue = climbing up quickly / sliding down. Default false.
maxDistance (optional)numberSearch 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.

ParameterTypeDescription
npcIdintegerId of the NPC.
fastbooleantrue = 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.

ParameterTypeDescription
npcIdintegerId of the NPC.
maxDistance (optional)numberSearch 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.

ParameterTypeDescription
npcIdintegerId of the NPC.
maxDistance (optional)numberSearch radius in cm. Default 1000.

Returns: boolean - false when there is no torch within the radius or the game rejected it.