Przejdź do treści
Gothic MultiplayerMultiplayer
Gothic MP Wiki

Character

A character in the world - the player, NPCs, monsters and puppets: items, attributes, skills, position, combat and interactions.

Every character in the world - the local player, an NPC, a monster or a remote player's puppet - is a Character object. Unless stated otherwise, every method works for all of them - where the game needs a different path for NPCs than for the player, the API picks it automatically. In the examples ch is any Character.

Items

giveItem

ch:giveItem(item, count, silent?)

Gives items to the character (adds them to the backpack).

ParameterTypeDescription
itemgmp.ItemClassClass name of the item, e.g. "ItMi_Orenugget".
countintegerNumber of pieces to give (1 or more).
silent (optional)booleantrue = no "item received" notification on the player's HUD. Default false.

Returns: boolean - true when the items were added.

removeItem

ch:removeItem(item, amount, silent?)

Removes items from the character. Pieces are taken from the backpack first; when equipped pieces have to be removed too (weapon, armor, ring, amulet), they are unequipped first - with their bonuses and visuals removed exactly as when unequipping in the game's inventory screen.

ParameterTypeDescription
itemgmp.ItemClassClass name of the item.
amountintegerNumber of pieces to remove.
silent (optional)booleantrue = no attribute change notifications when equipped jewelry is removed. Default false.

Returns: integer - Number of pieces actually removed (0 = the character had none).

getItemCount

ch:getItemCount(item)

Counts the pieces of an item the character has (backpack and equipped slots together).

ParameterTypeDescription
itemgmp.ItemClassClass name of the item.

Returns: integer | nil - Number of pieces (0 = none), or nil when the character no longer exists.

equipItem

ch:equipItem(item, silent?)

Equips an item the character has in the inventory. The slot is chosen from the item type:

  • bow or crossbow -> ranged weapon slot; melee weapon (one- or two-handed) -> melee weapon slot;
  • armor -> armor slot; amulet -> amulet slot (replaces the equipped one);
  • ring -> a free hand (left first, then right); with both hands taken, a ring other than the one being equipped is replaced.

Equipping a ring or amulet that is already equipped (with no further piece in the backpack) changes nothing and returns true. Not available while a loading screen is shown.

ParameterTypeDescription
itemgmp.ItemClassClass name of the item.
silent (optional)booleantrue = no attribute change notifications from jewelry bonuses (e.g. "+15 Strength"). Default false.

Returns: boolean - false when the item type cannot be equipped, the character does not have the item, or the game rejected it.

unequipItem

ch:unequipItem(item, silent?)

Unequips an equipped item into the backpack. The slot is found automatically (melee or ranged weapon, quick-access bar, armor, rings, amulet); the result is the same as in the game's inventory screen.

ParameterTypeDescription
itemgmp.ItemClassClass name of the item.
silent (optional)booleantrue = no attribute change notifications from jewelry bonuses (e.g. "-15 Strength"). Default false.

Returns: boolean - false when the item is not equipped.

getEquippedItems

ch:getEquippedItems()

Returns all items equipped by the character, with the place where each one is equipped. The weapon slots can also hold a rune or scroll and the quick-access bar holds potions, food, torches, runes and more - use the type field to tell them apart.

Returns: gmp.EquippedItem[] | nil - List of equipped items (empty when nothing is equipped), or nil when the character no longer exists.

getInventory

ch:getInventory()

Returns the whole inventory of the character: every stack in the backpack and every equipped item.

Returns: gmp.InventoryItem[] | nil - List of items (empty when the inventory is empty), or nil when the character no longer exists.

clearInventory

ch:clearInventory()

Empties the character's inventory: unequips everything (without notifications) and removes every item.

Returns: integer | nil - Number of removed item kinds (classes), or nil when the character no longer exists.

Attributes

Setters change the BASE value of an attribute; bonuses from rings, amulets, armor and effects are added on top of it by the game. Getters return the CURRENT value including bonuses - exactly what the game shows. Example: setStrength(100) with a +15 ring equipped -> getStrength() = 115. The game limits Health to MaxHealth and Mana to MaxMana - set the maximum first.

setStrength

ch:setStrength(value, silent?)

Sets the base strength of the character.

ParameterTypeDescription
valuenumberNew base value.
silent (optional)booleantrue = no attribute change notification on the player's HUD (e.g. "+90 Strength"). Default false.

Returns: boolean

getStrength

ch:getStrength()

Returns the current strength of the character (including bonuses).

Returns: number | nil

setDexterity

ch:setDexterity(value, silent?)

Sets the base dexterity of the character.

ParameterTypeDescription
valuenumberNew base value.
silent (optional)booleantrue = no attribute change notification on the player's HUD. Default false.

Returns: boolean

getDexterity

ch:getDexterity()

Returns the current dexterity of the character (including bonuses).

Returns: number | nil

setHealth

ch:setHealth(value, silent?)

Sets the health points of the character. The value is limited to the maximum health - to raise health above the current maximum, call setMaxHealth first.

ParameterTypeDescription
valuenumberNew health points.
silent (optional)booleantrue = no attribute change notification on the player's HUD. Default false.

Returns: boolean

getHealth

ch:getHealth()

Returns the current health points of the character.

Returns: number | nil

setMaxHealth

ch:setMaxHealth(value, silent?)

Sets the maximum health points of the character.

ParameterTypeDescription
valuenumberNew maximum health.
silent (optional)booleantrue = no attribute change notification on the player's HUD. Default false.

Returns: boolean

getMaxHealth

ch:getMaxHealth()

Returns the current maximum health points of the character (including bonuses).

Returns: number | nil

setMana

ch:setMana(value, silent?)

Sets the mana of the character. The value is limited to the maximum mana - to raise mana above the current maximum, call setMaxMana first.

ParameterTypeDescription
valuenumberNew mana.
silent (optional)booleantrue = no attribute change notification on the player's HUD. Default false.

Returns: boolean

getMana

ch:getMana()

Returns the current mana of the character.

Returns: number | nil

setMaxMana

ch:setMaxMana(value, silent?)

Sets the maximum mana of the character.

ParameterTypeDescription
valuenumberNew maximum mana.
silent (optional)booleantrue = no attribute change notification on the player's HUD. Default false.

Returns: boolean

getMaxMana

ch:getMaxMana()

Returns the current maximum mana of the character (including bonuses).

Returns: number | nil

Skills

grantSkill

ch:grantSkill(skill, silent?)

Grants a skill to the character for free (no learning points, no teacher). The levels of one skill replace each other: granting a higher level removes the lower one (e.g. Melee_OneHanded_Master replaces Melee_OneHanded_Trained).

Magic circles (Mage_Circle_1 ... Mage_Circle_6) also set the character's circle level, so the runes and scrolls of that circle can be used. Mana is not changed - use setMaxMana / setMana.

ch:grantSkill(gmp.enum.Skill.Mage_Circle_2)
ch:setMaxMana(60) ; ch:setMana(60)
ParameterTypeDescription
skillgmp.enum.SkillThe skill and its level.
silent (optional)booleantrue = no "new skill" notification on the player's HUD. Default false.

Returns: boolean - false when the skill could not be granted.

getSkills

ch:getSkills()

Returns the skills of the character - one level per skill, including the default ones the character starts with (e.g. Picklock_Untrained).

Returns: gmp.enum.Skill[] | nil - List of skills, or nil when the character no longer exists.

Position and name

setPosition

ch:setPosition(x, y, z)

Teleports the character to the given point. The facing direction does not change.

ParameterTypeDescription
xnumberX coordinate (cm).
ynumberY coordinate (cm).
znumberZ coordinate (cm); give a point slightly above the ground.

Returns: boolean - true when the game accepted the new position.

getPosition

ch:getPosition()

Returns the position of the character.

Returns:

ValueTypeDescription
xnumber | nilX coordinate (cm), or nil when the character no longer exists.
ynumber | nilY coordinate (cm).
znumber | nilZ coordinate (cm).

setAngle

ch:setAngle(yaw)

Sets the facing direction of the character. For the local player the camera is turned as well, so it stays behind the character.

ParameterTypeDescription
yawnumberAngle in degrees around the vertical axis: 0 = world X axis, 90 = world Y axis.

Returns: boolean - true when the game accepted the rotation.

getAngle

ch:getAngle()

Returns the facing direction of the character.

Returns: number | nil - Angle in degrees, -180 to 180.

setName

ch:setName(name)

Changes the name of this character only - the name the game shows above the character, when aiming at it and in conversations. Other characters of the same kind keep their names.

ParameterTypeDescription
namestringNew name (UTF-8; Polish and other national characters are supported). "" restores the game's name.

Returns: boolean

getName

ch:getName()

Returns the name of the character as the game shows it.

Returns: string | nil - Name in UTF-8.

State and behavior

setImmortal

ch:setImmortal(immortal)

Makes the character immortal (or mortal again). An immortal character takes hits but does not die.

ParameterTypeDescription
immortalbooleantrue = immortal.

Returns: boolean

isImmortal

ch:isImmortal()

Tells whether the character is immortal.

Returns: boolean | nil

setKillableWithoutDefeat

ch:setKillableWithoutDefeat(killable)

Humans in Gothic are normally knocked down (defeated) at 0 health instead of dying. With this option enabled the character dies right away at 0 health, without being knocked down first.

ParameterTypeDescription
killablebooleantrue = dies without a knockdown; false = the game's default behavior.

Returns: boolean

setRelation

ch:setRelation(other, relation)

Sets how this character treats another character. The relation is ONE-WAY: it decides whether this character takes other as a target (attacks it, starts combat music). Damage is also decided by the attacker's relation - e.g. with puppet:setRelation(player, Relation.Neutral) the puppet does not attack the player, while the player can still hit the puppet.

ParameterTypeDescription
othergmp.CharacterThe character the relation refers to.
relationgmp.enum.RelationNew relation.

Returns: boolean

getRelation

ch:getRelation(other)

Returns how this character treats another character (one-way, see setRelation).

ParameterTypeDescription
othergmp.CharacterThe character the relation refers to.

Returns: gmp.enum.Relation - Relation.Unknown when it cannot be determined.

setPassive

ch:setPassive(passive)

Makes the character's AI passive: it does not react to threats - does not attack and does not flee. Note: on a character created moments ago, the game's AI initialization can reset this during the first seconds; set it again if needed.

ParameterTypeDescription
passivebooleantrue = passive.

Returns: boolean

setInteractable

ch:setInteractable(interactable)

Enables or disables interacting with the character (talking to it, searching it).

ParameterTypeDescription
interactablebooleanfalse = other characters cannot interact with it.

Returns: boolean

setCollision

ch:setCollision(enabled)

Enables or disables the character's collision. Without collision the character passes through other characters and the world.

ParameterTypeDescription
enabledbooleanfalse = no collision.

Returns: boolean

stopAnimation

ch:stopAnimation()

Interrupts the action animation the character is playing (attack swing, throw, gesture).

Returns: boolean - false when no action animation is playing.

freezeMovement

ch:freezeMovement(frozen)

Freezes the character in place: the game does not move it (no walking, no gravity). setPosition still works on a frozen character.

ParameterTypeDescription
frozenbooleantrue = frozen; false = moves normally again.

Returns: boolean

Combat and death

kill

ch:kill()

Kills the character, with the death animation. Works for the player too.

Returns: boolean

isDead

ch:isDead()

Tells whether the character is dead.

Returns: boolean | nil - true when the character is dead or dying.

respawn

ch:respawn(keepPlace)

Revives a dead character the game's way. Health is restored to full if the game does not restore it itself. After reviving, the "respawn" event is fired.

ParameterTypeDescription
keepPlacebooleantrue = the character gets up where it died; false = at the place and with the angle where it first appeared in the world (for characters from gmp.spawnCharacter - the requested place and angle; for the player and the game's NPCs - their first appearance in this session).

Returns: boolean - false when the character is alive.

hit

ch:hit(victim, hitType, weapon?, impact?, magnitude?)

Makes this character hit another character, with the game's own damage, reactions and effects. This character is the attacker; melee and ranged hits use the weapon it has equipped.

Hit types (gmp.enum.HitType):

  • Fists - a punch;
  • Melee - a light swing with the equipped melee weapon (short stagger);
  • MeleeMedium - a medium swing: a stronger stagger without a knockdown;
  • MeleeHeavy - a heavy swing: knocks the victim down;
  • Arrow - a projectile from the equipped bow or crossbow (no knockdown);
  • Spell - a spell projectile: weapon = spell projectile definition class, impact = impact tag (default "Combat.HitType.Standard");
  • Tick - damage without a weapon (burning, damage over time, falling): magnitude = health change, negative = damage.
attacker:hit(victim, gmp.enum.HitType.MeleeHeavy)
attacker:hit(victim, gmp.enum.HitType.Tick, nil, nil, -25)
ParameterTypeDescription
victimgmp.CharacterThe character that is hit.
hitTypegmp.enum.HitTypeKind of the hit.
weapon (optional)gmp.WeaponClassWeapon override; required for Spell (spell projectile definition class).
impact (optional)gmp.ImpactTagImpact override for Spell.
magnitude (optional)numberHealth change for Tick (negative = damage).

World interactions

The game performs the interaction (walking to the place, animations, finishing) - the API only starts it, like pressing the "use" button. A character that is busy with another interaction cannot start a new one (stand up or leave the ladder first). An NPC is placed in front of the object; the player only when standing farther than 2.5 m away. Not available while a loading screen is shown.

findNearestObject

ch:findNearestObject(objectType, maxDistance?)

Finds the world object of the given kind nearest to the character.

ParameterTypeDescription
objectTypegmp.enum.ObjectTypeSeat, Ladder or Torch (Other is not searched).
maxDistance (optional)numberSearch radius in cm. Default 1000.

Returns: gmp.WorldObject | nil - The nearest object, or nil when there is none within the radius.

sitDown

ch:sitDown(seat)

Sits the character down on a bench or chair, on the nearest free place. The character stays seated until standUp is called.

ParameterTypeDescription
seatgmp.WorldObjectA bench or chair (ObjectType.Seat).

Returns: boolean - false when the object is not a seat, there is no free place, or the game rejected it.

standUp

ch:standUp()

Makes a seated character stand up (with the game's stand-up animation).

Returns: boolean - false when the character is not sitting.

useLadder

ch:useLadder(ladder, fast?)

Makes the character climb a ladder from the side it stands at: from the bottom it climbs up, from the top it climbs down. An NPC climbs to the other end and gets off by itself; the player keeps controlling the climb with the keys, as in the game.

ParameterTypeDescription
laddergmp.WorldObjectA ladder (ObjectType.Ladder).
fast (optional)booleantrue = fast from the start (climbing up quickly / sliding down). Default false.

Returns: boolean - false when the object is not a ladder, the ladder cannot be entered from here, or the game rejected it.

setLadderFast

ch:setLadderFast(fast)

Speeds up or slows down a character that is on a ladder - like holding or releasing Shift. Can be called any number of times while on the ladder. After getting off the ladder the speed-up is removed automatically.

ParameterTypeDescription
fastbooleantrue = fast climbing up / sliding down; false = normal steps.

Returns: boolean - false when the character is not on a ladder.

lightTorch

ch:lightTorch(torch)

Lights a roadside torch or a fire basket, with the character's animation as in the game. As in the game, the character needs a torch in hand. An object that is already burning is left as it is (returns true).

ParameterTypeDescription
torchgmp.WorldObjectA torch or fire basket (ObjectType.Torch).

Returns: boolean - false when the object cannot be lit or the game rejected it.

extinguishTorch

ch:extinguishTorch(torch)

Extinguishes a roadside torch or a fire basket, with the character's animation as in the game. An object that is not burning is left as it is (returns true).

ParameterTypeDescription
torchgmp.WorldObjectA torch or fire basket (ObjectType.Torch).

Returns: boolean - false when the object cannot be extinguished or the game rejected it.

Camera

setCameraAngle

ch:setCameraAngle(yaw)

Sets the camera angle of the character. For the local player this turns their camera.

ParameterTypeDescription
yawnumberAngle in degrees: 0 = world X axis, 90 = world Y axis.

Returns: boolean

getCameraAngle

ch:getCameraAngle()

Returns the camera angle of the character. For the local player - the angle of their camera; for other characters - the angle set with setCameraAngle (or the character's facing).

Returns: number | nil - Angle in degrees.

Types

EquippedItem

An item equipped by a character (Character:getEquippedItems).

FieldTypeDescription
slotgmp.enum.EquipSlotWhere the item is equipped.
indexintegerPosition on the quick-access bar (EquipSlot.QuickBar); 0 for the other slots.
typegmp.enum.ItemTypeWhat the item is (weapon, rune, potion...).
itemgmp.ItemClassClass name of the item.
countintegerStack size on the quick-access bar; 1 for the other slots.

InventoryItem

An item in a character's inventory (Character:getInventory).

FieldTypeDescription
itemgmp.ItemClassClass name of the item.
typegmp.enum.ItemTypeWhat the item is (weapon, rune, potion...).
countintegerNumber of pieces in this stack.
equippedbooleantrue when the item is equipped.
slotgmp.enum.EquipSlot | nilWhere the item is equipped; nil for items in the backpack.
indexintegerEquipped items: position on the quick-access bar (0 for the other slots). Backpack items: id of the stack in the backpack.