Knights Lua API

Knights allows you to extend and modify the game by writing Lua code. This section of the wiki explains how this works.

Note we don't try to explain how to code in Lua itself (there are already plenty of tutorials on the web for that). Instead we focus on the interface between Lua code and the Knights engine itself.

Getting Help

If you are trying to make a mod, but you can't figure out how to do a certain thing, or your code isn't working, or you are just generally having problems, then please do not hesitate to post your question to the Knights forum and we will do our best to answer it.

Also, the Knights Lua API is still quite new and incomplete, so you might find it is missing certain key features that you need. If this happens please also post to the forum and we will see what can be done to solve the problem.


Knights Lua code is organized into "modules". Each module resides in a subdirectory under knights_data/server/. The module system is described in full here:

The Knights module system

When making a module, you can optionally enable "strict checking" by calling use_strict. This checks for certain errors like forgetting a module prefix. It is recommended to always use this in new modules.

Knights itself comes with two "standard" modules:

classic -- This includes all the "classic" gameplay from the original Amiga Knights.
menu -- This includes some utility functions for manipulating the Quest Selection menu.

The following document explains how to write a module, by way of an example "multiwand" module (originally written by ImpassIve_rus):

Adding a "multiwand" module

Knights Lua differences

The version of Lua implemented in Knights has some minor differences from the standard Lua. These are documented here:

Differences between Knights Lua and standard Lua

Knights API documentation

The following documents describe in detail the interface between your Lua code and the Knights engine itself.

  • Knights Lua objects -- describes what types of "userdata" objects Knights creates.
  • The "kts" table -- most Knights API functions reside in a global table named "kts"; they are described here.
  • Legacy Actions -- more functions in the "kts" table (note: despite the name, these are very much supported in the current Knights version).
  • Quest selection menu and game startup procedure -- Explains how the quest selection menu works, and what happens when you start a game.
  • Dungeon layout tables -- Explains the dungeon layouts (Basic, Huge, Snake etc) and gives a bit of info about how the dungeon generator works.
  • cxt -- Explains the "context table" that is used by certain Knights functions.
Last modified 5 years ago Last modified on 12/29/12 14:22:01