CLICK HERE to visit the new NS2 Wiki! Please do not rely on any information here as it may be inaccurate and/or out of date! For help with NS2, hop onto the official Discord server!


From NS2 community wiki
Jump to: navigation, search

What is Lua?

Lua is an extension programming language that is widely used as a scripting language in applications. Due to its simple syntax, it is used in games such as Garry's Mod, World of Warcraft, Far Cry and many more.

Within Natural Selection 2, the majority of the game code will be written in Lua.
As well as providing a convenient environment for the NS2 team to code in, it will allow users to create modifications of the game.

Visit the official Lua site or the associated Wikipedia article for more information.


Warning Warning: The documentation of Lua within Natural Selection 2 is far from complete. Information may be incorrect and its reliability of data should not be trusted.

Example: Key Input

local function SendKeyEvent(key, down)
    if key == InputKey.Q and down then
        Shared.Message('Hello World')
Event.Hook("SendKeyEvent", SendKeyEvent)

File paths

There are four URL-style path prefixes available to Lua scripts:

The base game directory (ns2) with active mod directories laid on top. Scripts cannot write to this directory.
The per-user config directory, located within the current Windows user profile.
The directory in which pathing data and compiled shaders are stored. In current builds it's inside the config directory.
Unknown location.

Printing to the console

The standard Lua print() function doesn't print to the game console. Use one of these instead:

Prints to the console without decoration.
Prints to the console with the name of the current VM and a timestamp.