In this tutorial, we will go through the process of creating a new mod for Natural Selection 2 and uploading it to the Steam Workshop. This tutorial assumes no prior knowledge of programming or modding (but both will certainly help!).

INTRO

In this tutorial, we will go through the process of creating a new mod for Natural Selection 2 and uploading it to the Steam Workshop. This tutorial assumes no prior knowledge of programming or modding (but both will certainly help!).

LAUNCH PAD

The first tool we will discuss is the Launch Pad. This is the application that will create and manage your mods as well as publish these mods to the Steam Workshop. This tool is called LaunchPad.exe and is located in the game’s installation directory.

GAME SETUP

Your file should look like this (if it is different, edit
the file to look like this).

name is what will display in the server browser. If making a NS2 mod, it is best to leave this as ns2. If you are making a new game you should give it a small, unique name.description is the full name of the mod.client, predict, server, and loadingare the “entry points” for executing your mod’s code.

There are also fields not included here for the main menu entry point
(lua/Main.lua) and the icon to use for the mod. These will default to NS2 values so there is no need to add them.

Change the 7th line to:

xml code:

>lua/Loading.lua>

This will cause our mod to use the default loading screen code.

THE FILE SYSTEM

Now is a good time to discuss how the file system works in Spark. This is a very important concept to understand while modding.

The file system is able to “mount” any number of directories as one virtual directory. As an example, the default NS2 installation includes a “ui” directory where all the user interface images in the game exist. But any number of mods may also have their own “ui” directory.

There is a file in the “ui” directory called “crosshairs.dds”. This is the image that contains the crosshairs for the different weapons and abilities in NS2.

So when the game code asks for “ui/crosshairs.dds”, this file will be loaded from the virtual file system.

If I create a mod that includes a “ui” directory, Spark will prioritize files in my mod’s directory over files in the default NS2 “ui” directory.

The file system will load mod files first, falling back
on NS2 files.

ENTRY POINTS

Next we need to create the ModClient.lua, ModPredict.lua, and ModServer.lua entry point files.

Go back to the Source directory and go into the lua directory. Create a new text file in the luadirectory and rename it to ModClient.lua. Do the same forModPredict.lua and ModServer.lua.

PROGRAMMING!

The next step is to add code to these entry point files. We are going to simply make our mod use the NS2 code to start.

Open ModClient.lua and type the following:

lua code:

Script.Load("lua/ModShared.lua")

Do the same for ModPredict.lua and ModServer.lua.

SHARED CODE

Create a new text file in the lua directory called ModShared.lua.

Open this file and type the following:

lua code:

if Server then

Script.Load("lua/Server.lua")

elseif Client then

Script.Load("lua/Client.lua")

elseif Predict then

Script.Load("lua/Predict.lua")

end

Script.Load("lua/Class.lua")

-- Load mod files here.

This tutorial is not going to explain how to program or how to use Lua. For that, your best bet is reading Programming in Lua and/or a Google search.

I will cover what the code is doing however.

WHAT’S GOING ON HERE?

lua code:

if Server then

Script.Load("lua/Server.lua")

elseif Client then

Script.Load("lua/Client.lua")

elseif Predict then

Script.Load("lua/Predict.lua")

end

These 7 lines of code are loading the default NS2 entry point scripts based on which VM is currently running.

The VM (Virtual Machine) is the context for the code currently executing. The primary VMs we will deal with in this tutorial are: Server, Client, and Predict.

Ultimately these lines of code are simply checking if a Lua table exists and then loading the appropriate entry point script based on that. These Lua tables are automatically created by the engine before your mod’s code executes.

lua code:

Script.Load("lua/Class.lua")

This script is part of the modding framework. It should be loaded AFTER the default NS2 code is loaded.

lua code:

-- Load mod files here.

This line is a comment (it is ignored while this script is parsed by the engine). We will include our mod’s code here later.

EXECUTE!

At this point, we technically have a mod we can execute.

Go back to the Launch Pad and double click on the Launch Game button.

This button will automatically
start up NS2 running your mod.

You will see the normal NS2 main menu except you will see your mod’s description in the title bar (I suggest using windowed mode while developing your mod).

Open the console with the ~ key and type map ns2_summit and then press enter.

The console is a modder’s best friend.

After loading, you will be in Summit and everything should be working like it normally does in NS2 except the game is running your mod.

Good work!

UBER SHOTGUN TIME

Now let’s change something.

Create a new text file in the lua source directory and name it UberShotgun.lua

Two people spawn as the fade but the player skin remains as normal human skin and they carry a weapon around looking all normal. These two players then have to kill everyone else before the people work out their identities. They can only attack people when they transform into fade form which takes a second or two. Once they have transformed into fade form, they can't transform back unless they've killed someone and absorb said person's body. (Idea taken from TTT for garry's mod, would be pretty epic having something like this!)