Skip to content

Lua

Lua 5.4 is the scripting language of KCD:MP. It runs in two places, and the two talk to each other:

Where What Runs API
Server a game mode - the rules of one server: who spawns where, what chat and commands do, zones, timers, NPC actors, the world clock inside the dedicated server, one script per server, on the simulation thread Server API
Client a client script - the mode’s own half on a player’s game: a marker, a sound, a bit of UI, a value read from the game inside the player’s game, loaded by the player, in the game’s own Lua state Client API

A game mode alone makes a server: freeroam.lua and duel_arena.lua ship with it. A client script is optional and belongs to a mode that needs something on the player’s screen the server cannot draw itself; the two halves talk through script events and state bags. The marker example that ships with the server is a mode with both halves.

  1. Getting started on the server - running a mode, the tick model, ids and units, what happens on an error; then the Server API index: every callback and function by topic, each on its own page with its syntax, arguments, return value and an example.
  2. The combat guide - the model behind the combat callbacks; Constants; Parties - the party model: what the server keeps and the API a mode builds its commands on.
  3. Getting started on the client and the Client API index - when a mode needs its own half on the player’s screen.
  4. The reference lists - every item, soul, buff, mesh, preset, clip, door and container the game has, by the keys these functions take.
  5. Your editor - the whole API as Lua language server definitions (sdk/KcdMp.d.lua in the server folder): completion, documentation on hover and a warning for a wrong name or argument while you write.

The server folder, the first run and the game’s data come before any of it: Setting up. The same functions exist for C# plugins, the native tier the Lua maps onto.