gmp
The gmp module on the client side: event handlers, creating and finding characters, story mode.
The gmp module is the entry point of every script:
local gmp = require("gmp")On the client side it registers event handlers, creates and finds characters and controls the story mode. Actions on characters are methods of Character; common types and constants are shared with the server side.
Events
on
gmp.on(event, handler)Registers a handler for a game event. 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, puppets), also when the cause is an API call (e.g. ch:kill()).
gmp.on("dead", function(who, killer, weapon)
if killer then
print(killer:getName() .. " killed " .. who:getName())
end
end)| Parameter | Type | Description |
|---|---|---|
event | gmp.EventName | Name of the event. |
handler | function | Function called when the event occurs; its arguments depend on the event (see Events). |
Characters
spawnCharacter
gmp.spawnCharacter(class, x, y, z, angle)Requests creation of a character at the given point. The game creates characters
asynchronously, so the function returns a request number immediately and the ready character
arrives about 1 second later in the "characterSpawned" event (with the same id).
The character is created exactly as the game makes it - only the facing angle is set. Many characters can be requested at once (each request has its own number). Different human character definitions requested in quick succession are created one after another (about 1-3 seconds each).
local requestId = gmp.spawnCharacter("SpawnAIAgentDefinition_BigMolerat", 1200, -350, 80, 90)
gmp.on("characterSpawned", function(id, who)
if id == requestId and who then who:setName("Molerat") end
end)| Parameter | Type | Description |
|---|---|---|
class | gmp.CharacterClass | Class of the character to create. |
x | number | X coordinate of the spawn point (cm). |
y | number | Y coordinate of the spawn point (cm). |
z | number | Z coordinate of the spawn point (cm); give a point slightly above the ground. |
angle | number | Facing angle (yaw) in degrees: 0 = world X axis, 90 = world Y axis. |
Returns: integer | nil - Request number, or nil when the class is not a valid character class, there is no world, or the game rejected the request.
getCharacterById
gmp.getCharacterById(serverId)Returns the character with the given server id. The server gives every character it manages an id:
0toslots - 1- players, one id per player slot of the server (the local player has one too);slotsand above - NPCs created by server-side scripts.
slots is the number of player slots configured on the server.
local ch = gmp.getCharacterById(0)
if ch then print(ch:getName()) end| Parameter | Type | Description |
|---|---|---|
serverId | integer | Server id of the character: a player slot, or the id of a server-side NPC. |
Returns: gmp.Character | nil - The character, or nil when no character with this id is present on this client (an empty player slot, or an NPC that does not exist or has not been created here yet).
Story mode
disableStoryMode
gmp.disableStoryMode()Disables the game's story for the rest of the session. It cannot be undone: removed NPCs stay removed (also in a save game, if the game makes one).
Effects:
- story cutscenes do not start - neither the intro after the loading screen nor any later one; a cutscene that is already running is skipped;
- no NPC pulls the player into a conversation (e.g. Diego's greeting); conversations started by the player work as usual;
- all NPCs and monsters of the game are removed from the world, including those that appear later (respawns, streamed-in parts of the world); characters created through the API stay;
- the glossary is not updated by the removed NPCs (no "Glossary updated" notifications).
Best called before the world loads (in the main menu) - a new game then starts without the intro.
Returns: boolean - Always true.
isStoryModeEnabled
gmp.isStoryModeEnabled()Tells whether the game's story is enabled.
Returns: boolean - false after gmp.disableStoryMode() was called.
Types
EventName
Names of the client-side events accepted by gmp.on. See Events for the handler arguments.
| Value | Description |
|---|---|
"dead" | A character died. |
"hit" | A character was hit (every damage application). |
"interactionStart" | A character started an interaction with a world object. |
"interactionEnd" | A character finished an interaction with a world object. |
"characterSpawned" | A character requested with gmp.spawnCharacter was created. |
"respawn" | A character was revived with Character:respawn. |
