Unturned

Unturned

78 ratings
Workshop: Modules
By SDGNelson
This guide documents the Modules feature and how to write custom C# code for use in Unturned.
 
Rate  
Favorite
Favorited
Unfavorite
Intro
Note: 3rd-party modules can't be loaded with BattlEye enabled. To disable BattlEye you can select the alternative launch option in Steam "Play without BattlEye", or temporarily move your modules out of the Unturned directory before starting the game with BattlEye.

I'm currently working on cleaning up and modularizing Unturned's code into a "Framework" component which will contain core editor and gameplay elements, and a "Unturned" component housing Unturned-specific features like zombies or crafting.

The goal is that then you can create your own Modules which can add new features to Unturned itself, convert it into a completely different game (e.g. HL1 -> TF2), or build off of other modules to improve functionality.

Right now very few Unturned features are built with this module support in mind, but over time we'll get there! I'm also currently considering opening Unturned's sourcecode to GitHub so that you can submit pull requests for any changes you need. In the meantime the functionality is there to get started with a custom module as instructed below:
Module
All module files go in the Unturned/Modules directory. For security reasons they are not allowed on the Steam Workshop, but they are fairly straightforward to install.

To get started you can create a folder to house your module. Inside of this you will have any number of *.module files which show in the Workshop/Modules window or when using the "Modules" command.

Below is an example of a .module file, in this case saved as Example.module, and here are the explanations of what each variable does:

IsEnabled gets set by the game from the modules menu, or you can alter it manually for example to temporarily disable a module on the server.

Name is the linked identifier for this module. Other modules will use this name for their dependencies, so do not change it. You can change the display name in the localization files.

Version represents main.major.minor.patch. It is displayed and used for dependencies and checking installed modules when joining a server.

Assemblies are a list of the .dll files which make up the actual code of your module. Path is relative to the folder the .module file is in. Role can be set to Client, Server, Both_Optional and Both_Required. Client assemblies aren't loaded on the dedicated server and vice versa. Both_Optional is for cases where a client can safely join the server even if they don't have the module, maybe showing error messages when interacting with missing features. Both_Required is for total conversions where missing the assembly breaks everything, so clients are rejected from the server.

Dependencies are a list of modules that must be loaded before this one. The load order is automatically calculated. If a module with that name and at least that version aren't available this module isn't loaded.

Additionally alongside your .module file(s) you can include localization .dat with a "Name" and "Description" key and an "Icon.png" shown in the menu.

{ "IsEnabled": true, "Name": "UnturnedExampleMod", "Version": "2.1.0.3", "Assemblies": [ { "Path": "/UnturnedExampleModule.dll", "Role": "Both_Required" }, { "Path": "/UnturnedExampleModuleCommands.dll", "Role": "Server" } ], "Dependencies": [ { "Name": "Core", "Version": "3.0.0.0" }, { "Name": "OtherMod", "Version": "2.5.0.0" } ] }
C#
To set up the assemblies for your mod you'll want to create a new project in Visual Studio and add Unturned/Unturned_Data/Managed/Assembly-CSharp.dll and Unturned/Unturned_Data/Managed/UnityEngine.dll as references. In the future these will be references to the Framework and Unturned modules. You can configure your build output to put just the project .dll file in your module folder, or manually copy it over after building.

In these early days of Unturned scripting support your mod might break with higher frequency as my code is cleaned up and moved into separate .module files to better support custom mods, but I'll do my best to avoid that. I'd recommend you try to maintain backwards compatibility as well incase other mods depend on yours.

Modules are hooked into essentially the earliest point in the game's startup, so you have quite a bit of control. To define your module's entry (initialize) and exit (shutdown) points implement the IModuleNexus interface from SDG.Framework.Modules in as many of your classes as you like. These classes will be instantiated when loading the modules, but held onto to avoid garbage collection. Weird interface name maybe, but I've always liked naming my main class "Nexus"!
< >
36 Comments
SunderMind Oct 24, 2018 @ 6:50am 
I see. So basically no rotating surveillance camera for me.
Chronic_Rogue May 30, 2018 @ 3:08pm 
erm, ive been looking through guides and stuff, i cant join any servers cause its missing a module but idk how to disable my modules
Ceans Mar 24, 2017 @ 4:33am 
Take a look at the flow's tutorial
BuLg Dec 4, 2016 @ 3:05am 
lol
the_blaster179 Nov 23, 2016 @ 1:29pm 
Just noticed that in the .module exemplar, you have a formatting error in it where it shows [/nocode] in it, and it could confuse some people.
rockhopper Nov 16, 2016 @ 7:44pm 
SO i don't understand, when we are to "create a project" do we create a c# console file? or what?
Lumejr Nov 13, 2016 @ 12:13pm 
I think that something like TWD Modules will be cool, you know. Killing zombies Headshot Only, and when someone dies, spawn zombie on him. Ok, the second thing would be harder beacause of zones... But I don't understand this tutorial so... I'll wait for video on YT,
LeeIzaZombie Nov 6, 2016 @ 2:22pm 
I think there's an example in Bundles/Sources/ not sure... I did my first module by implementing interface in a class and using the references
Azim Nov 5, 2016 @ 8:47am 
Can u put an example.module , which will print 'hello world' somewhere, with all it's .dll s 'n stuff? So we can read, understand and do our best?