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)| Argument | Type | Description |
|---|---|---|
who | gmp.Character | The character that died. |
killer | gmp.Character | nil | The attacker of the last hit within 5 seconds before the death; nil when unknown (a fall, drowning, ch:kill()). |
weapon | gmp.WeaponClass | nil | What 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.
| Argument | Type | Description |
|---|---|---|
attacker | gmp.Character | nil | The character that dealt the hit; nil when there is no attacker (a fall). |
victim | gmp.Character | The character that was hit. |
damage | number | Health lost (0 = a hit without damage, e.g. a blocked one). |
hitType | gmp.enum.HitType | Kind of the hit - attacker:hit(victim, hitType, weapon) reproduces a similar hit. |
weapon | gmp.WeaponClass | nil | Weapon, 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.
| Argument | Type | Description |
|---|---|---|
who | gmp.Character | The character. |
object | gmp.WorldObject | The object. |
objectType | gmp.enum.ObjectType | Seat, 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".
| Argument | Type | Description |
|---|---|---|
who | gmp.Character | The character. |
object | gmp.WorldObject | The object. |
objectType | gmp.enum.ObjectType | Kind 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(...)).
| Argument | Type | Description |
|---|---|---|
id | integer | The request number returned by gmp.spawnCharacter. |
who | gmp.Character | nil | The 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).
| Argument | Type | Description |
|---|---|---|
who | gmp.Character | The revived character. |
