Natural Selection 2 is the sequel to the popular Half-Life mod Natural Selection. It is built on our own engine and will be distributed through Valve's Steam platform.

Report article RSS Feed TIME TO MAKE MODS

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!).

Posted by SgtBarlow on May 13th, 2013
Basic Starting a mod.

Featured Image

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.

On my computer, Launch Pad is located at:

C:\Program Files (x86)\Steam\steamapps\common\Natural Selection 2\LaunchPad.exe


Launch Pad

Launch Pad is the starting point for modding.

Once Launch Pad is open, go get some tea, use the bathroom if needed, and get ready because we are now MODDING.

Press the New button.

This will open the “Mod Wizard” dialog box:


Choosing a sweet name is the most important task while modding.

Choosing a sweet name is the most important
task while modding.

Choose a location for your project and a name. Press the Create button.

All the tools you will need are on the left side of
this window.

BUILDER

Launch Pad is now set-up for the mod. The next task is to run Builder.

Double click on the Builder icon and you will see this window:

Builder will build and copy  all source assets you create into the output directory.
Builder will build and copy all source assets you
create into the output directory.

Click on the Build menu and then click Build.

This has built the mod into the output directory. While you are working on your mod, you should always have Builder running. It will run in the background if you close the window.

THE SOURCE

Go back to Launch Pad and double click on the Source icon. You will see this:

All source assets go into these directories.
All source assets go into these directories.

This is where all of the mod’s source files will be located.

  • lua is for Lua game code.
  • mapsrc is for level files.
  • materialsrc is where material files and textures will go.
  • modelsrc is for your model and animation source files.
  • soundsrc is for FMOD projects and wav files.
  • game_setup.xml is a file that tells the game about your mod.


GAME SETUP

Open game_setup.xml in a text editor such as NotePad++:

Your file should look like this (if it is different, edit the file to look like this).
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 loading are 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.
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 lua directory and rename it to ModClient.lua. Do the same for ModPredict.lua and ModServer.lua.

Creating Entry Points


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.
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.

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


Go back into the ModShared.lua file.

Add this after the comment:

lua code:
-- Load mod files here.

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


Open the UberShotgun.lua file and type the following:

lua code:
function Shotgun:ApplyBulletGameplayEffects(player, hitEnt, impactPoint, direction, damage, surface, showTracer)

if HasMixin(hitEnt, "Fire") then

hitEnt:SetOnFire(player, self)

TESTING THE CHANGE

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

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

Once in the game, open the console again and type cheats 1.

Then join the Marines. Open the console and type give shotgun.

Now go find the Alien base and start shooting.

Now we're cooking with fire!
Now we’re cooking with fire!


PUBLISHING

The last step is to publish the mod to the Steam Workshop.

Go back to the Launch Pad and press the Configure button.


This information will be displayed on the Steam Workshop page for your mod.

This information will be displayed on the Steam
Workshop page for your mod.

Enter in a title for your mod and a description and then press OK.

Next, click the Publish button.


The Status box will alert you to any problems.

The Status box will alert you to any problems.

You can change the visibility to Friends Only or Private when you are testing your mod.

When ready, press the Publish button here to upload your mod to the Steam Workshop.

After that finishes, your mod is now on the Workshop.

CONCLUSION

That covers the basics! I hope this tutorial has given you an idea of how the modding tools work and what is possible in your own mods.

Thanks for reading!

Post comment Comments
GenMoKai
GenMoKai May 14 2013, 3:38am says:

Ow yeah! Modding stuff!

+3 votes     reply to comment
AydinDubstep
AydinDubstep May 14 2013, 5:27am says:

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!)

+2 votes     reply to comment
SgtBarlow Author
SgtBarlow May 14 2013, 5:53am says:

I am having a real hard time with this websites editor, It's really buggy. Some of the code snippets are partly missing.

An intact copy of this tutorial can be found here:

Unknownworlds.com

+2 votes   reply to comment
Orac|
Orac| May 15 2013, 5:40pm says:

So what sort of poly-counts are we talking here for models?

+1 vote     reply to comment
Post a Comment
click to sign in

You are not logged in, your comment will be anonymous unless you join the community today (totally free - or sign in with your social account on the right) which we encourage all contributors to do.

2000 characters limit; HTML formatting and smileys are not supported - text only

Icon
Natural Selection 2
Platforms
Windows, Linux
Developer
Unknown Worlds
Engine
Spark
Contact
Send Message
Official Page
Naturalselection2.com
Release Date
Released Oct 28, 2012
Game Watch
Track this game
Tutorial
Browse
Tutorials
Report Abuse
Report article
Related Games
Natural Selection 2
Natural Selection 2 Multiplayer Real Time Shooter
Related Engines
Spark
Spark Commercial TBD
Related Groups
Unknown Worlds
Unknown Worlds Developer & Publisher with 5 members