Lua API
Script the game world of Gothic Multiplayer with Lua - characters, items, combat, interactions and events.
Gothic Multiplayer servers are scripted in Lua 5.4. Scripts are plain text files - no compilation
is needed. They react to game events and change the world through the gmp module.
local gmp = require("gmp")
local E = gmp.enum
-- log every death caused by another character
gmp.on("dead", function(who, killer, weapon)
if killer then
print(killer:getName() .. " killed " .. who:getName())
end
end)
-- a guard that hits hard
local guardRequest = gmp.spawnCharacter("CharacterDefinition_Human_OC_GRD_Jackal_201", 1200, -350, 80, 90)
gmp.on("playerSpawn", function(id, who)
if id ~= guardRequest or not who then return end
who:setName("Jackal")
who:giveItem("ItMw_1H_Sword_01", 1)
who:equipItem("ItMw_1H_Sword_01")
who:grantSkill(E.Skill.Melee_OneHanded_Master)
end)Conventions
These rules apply to the whole API:
- Characters are objects. The player, NPCs, monsters and remote players' puppets are
Characterobjects, and actions on them are methods:ch:giveItem("ItMi_Orenugget", 10). - Game classes are passed by name. Items, characters and weapons use the game's class names, e.g.
"ItMi_Orenugget"(ore nugget),"ItMw_1H_Sword_01"(one-handed sword),"CommonPlayerDefinition". Names are case-sensitive. - Units. Distances and positions are in game units: 1 unit = 1 cm. Angles are in degrees (0 = world X axis, 90 = world Y axis).
- Results. Actions return
trueon success andfalsewhen the game rejected the action or the character no longer exists. Getters returnnilwhen the character no longer exists. - Optional parameters are marked with
?in the reference;silent?parameters hide the notification the game would show on the player's HUD. - Constants live in
gmp.enumand are always used by name:gmp.enum.HitType.MeleeHeavy. Tip:local E = gmp.enumkeeps scripts short.
Reference
gmp
The module: registering events, creating characters, story mode and the common types.
Character
Everything a character can do: items, attributes, skills, position, combat, interactions and movement.
WorldObject
Benches, ladders, torches and other interactive objects.
Events
dead, hit, interactionStart, interactionEnd, playerSpawn, respawn.
Constants
gmp.enum: hit types, equipment slots, item types, object types, relations, controls and skills.
Editor support
The API ships with definition files for the Lua Language Server. With the Lua extension for VS Code you get completion, inline documentation and type checking for every function and constant while you write your scripts.
