Przejdź do treści
Gothic MultiplayerMultiplayer
Gothic MP Wiki

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)
ArgumentTypeDescription
pidintegerId 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.

ArgumentTypeDescription
pidintegerId 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).

ArgumentTypeDescription
pidintegerId of the player.
textstringThe 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)
ArgumentTypeDescription
pidintegerId of the player or server-side NPC that died.
killerIdinteger | nilId 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.
weapongmp.WeaponClass | nilWhat 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.

ArgumentTypeDescription
attackerIdinteger | nilId 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.
victimIdintegerId of the player or server-side NPC that was hit.
damagenumberHealth lost (0 = a hit without damage, e.g. a blocked one).
hitTypegmp.enum.HitTypeKind of the hit - gmp.hitPlayer(attackerId, victimId, hitType, weapon) reproduces a similar hit.
weapongmp.WeaponClass | nilWeapon, 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.

ArgumentTypeDescription
pidintegerId of the revived player or server-side NPC.