Events
Server events: players joining, leaving and chatting; deaths, hits and respawns of players and server-side NPCs.
Server 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.
Characters are passed as ids: players 0 to gmp.getMaxSlots() - 1, server-side NPCs from gmp.getMaxSlots() up - use gmp.isNpc to tell them apart.
playerJoin
A player connected to the server and got a player slot.
gmp.on("playerJoin", function(pid)
gmp.sendMessageToAll(gmp.getPlayerName(pid) .. " entered the Colony")
end)| Argument | Type | Description |
|---|---|---|
pid | integer | Id of the player (their slot). |
playerLeave
gmp.on("playerLeave", function(pid)
-- ...
end)A player disconnected from the server (left the game, lost the connection or was kicked). The slot becomes free after the handlers have run.
| Argument | Type | Description |
|---|---|---|
pid | integer | Id of the player. |
playerChat
gmp.on("playerChat", function(pid, text)
-- ...
end)A player sent a chat message (not a command - commands go to their handlers
registered with gmp.registerCommand).
| Argument | Type | Description |
|---|---|---|
pid | integer | Id of the player. |
text | string | The message (UTF-8). |
playerDead
A player or a server-side NPC died (the game's death; a knockdown is not a death).
gmp.on("playerDead", function(pid, killerId, weapon)
if killerId and not gmp.isNpc(killerId) then
gmp.sendMessageToAll(gmp.getPlayerName(killerId) .. " killed " .. gmp.getPlayerName(pid))
end
end)| Argument | Type | Description |
|---|---|---|
pid | integer | Id of the player or server-side NPC that died. |
killerId | integer | nil | Id of the attacker of the last hit within 5 seconds before the death; nil when unknown (a fall, drowning, gmp.killPlayer) or when it was not a player or server-side NPC. |
weapon | gmp.WeaponClass | nil | What dealt the last blow (weapon, projectile or spell); nil when no weapon was involved. |
playerHit
gmp.on("playerHit", function(attackerId, victimId, damage, hitType, weapon)
-- ...
end)A player or a server-side NPC was hit. Reported for every damage application: a swing, a punch, an arrow, a spell, a damage-over-time tick, a fall.
| Argument | Type | Description |
|---|---|---|
attackerId | integer | nil | Id of the player or server-side NPC that dealt the hit; nil when there is no attacker (a fall) or it is not a player or server-side NPC. |
victimId | integer | Id of the player or server-side NPC 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 - gmp.hitPlayer(attackerId, victimId, hitType, weapon) reproduces a similar hit. |
weapon | gmp.WeaponClass | nil | Weapon, projectile or spell that dealt the hit; nil when no weapon was involved. |
playerRespawn
gmp.on("playerRespawn", function(pid)
-- ...
end)A player or a server-side NPC was revived with gmp.respawnPlayer. It is
already at its target place.
| Argument | Type | Description |
|---|---|---|
pid | integer | Id of the revived player or server-side NPC. |
