Zum Inhalt springen
Gothic MultiplayerMultiplayer
Gothic MP Wiki

Events

Game events delivered to client-side scripts: deaths, hits, interactions, spawned and revived characters.

Events are received by registering a handler with gmp.on. Several handlers can be registered for the same event; they are called in the order of registration.

Events are reported for every character - the player, NPCs, monsters, animals and puppets - also when the cause is an API call (ch:kill(), ch:hit(...), ch:sitDown(...)...). Handlers run after the game has finished processing the event, so any API function can be used inside them.

dead

A character died (the game's death; a knockdown is not a death).

gmp.on("dead", function(who, killer, weapon)
  print(who:getName() .. " died")
end)
ArgumentTypeDescription
whogmp.CharacterThe character that died.
killergmp.Character | nilThe attacker of the last hit within 5 seconds before the death; nil when unknown (a fall, drowning, ch:kill()).
weapongmp.WeaponClass | nilWhat dealt the last blow (weapon, projectile or spell); nil when no weapon was involved.

hit

gmp.on("hit", function(attacker, victim, damage, hitType, weapon)
  -- ...
end)

A character was hit. Reported for every damage application: a swing, a punch, an arrow, a spell, a damage-over-time tick (burning, channeled spells), a fall.

ArgumentTypeDescription
attackergmp.Character | nilThe character that dealt the hit; nil when there is no attacker (a fall).
victimgmp.CharacterThe character that was hit.
damagenumberHealth lost (0 = a hit without damage, e.g. a blocked one).
hitTypegmp.enum.HitTypeKind of the hit - attacker:hit(victim, hitType, weapon) reproduces a similar hit.
weapongmp.WeaponClass | nilWeapon, projectile or spell that dealt the hit; nil when no weapon was involved.

interactionStart

gmp.on("interactionStart", function(who, object, objectType)
  -- ...
end)

A character started an interaction with a world object (the game accepted it). Interactions without an object (e.g. animals' wander points) are not reported.

ArgumentTypeDescription
whogmp.CharacterThe character.
objectgmp.WorldObjectThe object.
objectTypegmp.enum.ObjectTypeSeat, Ladder, Torch, or Other (door, chest, crafting table...).

interactionEnd

gmp.on("interactionEnd", function(who, object, objectType)
  -- ...
end)

A character finished an interaction with a world object (stood up, got off the ladder, finished lighting the torch...). The object and type are the same as in the matching "interactionStart".

ArgumentTypeDescription
whogmp.CharacterThe character.
objectgmp.WorldObjectThe object.
objectTypegmp.enum.ObjectTypeKind of the object.

characterSpawned

gmp.on("characterSpawned", function(id, who)
  -- ...
end)

A character requested with gmp.spawnCharacter was created. It stands at the requested place with the requested angle and is ready for further calls (e.g. who:setName(...)).

ArgumentTypeDescription
idintegerThe request number returned by gmp.spawnCharacter.
whogmp.Character | nilThe new character; nil when it could not be created (the game rejected the request or did not create the character within 10 seconds).

respawn

gmp.on("respawn", function(who)
  -- ...
end)

A character was revived with Character:respawn. It is already at its target place (where it died or where it first appeared).

ArgumentTypeDescription
whogmp.CharacterThe revived character.