Modding Basics – DayZ

From Bohemia Interactive Community
Jump to navigation Jump to search



Step by step creation of a simple mod for DayZ


Requirements

  • Steam copy of DayZ
  • DayZ Tools (Availabe through steam by navigating through Library -> Tools)

Setup

It is recommended to setup a Project Drive with extracted game data for optimal workflow:

  • Launch DayZ Tools from Steam
  • Navigate to Settings
  • Set a Drive Letter and your Path to the Project Drive
  • Click apply
  • Navigate to Tools -> Extract Game Data
  • Wait for the process to finish


If you wish to use Workbench and its Script Editor, follow the setup guide here https://community.bistudio.com/wiki/DayZ:Workbench_Script_Debugging#Workbench_Setup

Creating a mod

In the spirit of simplicity, let us create a mod which will print a message into the log upon a certain condition.

In order to do so, we will need to pack our mod into a .pbo file and load it when launching the game. A mod can have several .pbo files but most smaller ones will only ever need a single one.

Scripting syntax documentation is located here https://community.bistudio.com/wiki/DayZ:Enforce_Script_Syntax

Step by step

  • Start by creating a mod folder, in this example we will create one in our P: drive called FirstMod
  • Inside the FirstMod folder, create another folder which will contain our modded class. We will call it WorldScripts
  • PlayerBase.c contains a function suitable for our mod named OnJumpStart() which is called every time player jumps - we will use it in this example
  • Create MyScript.c file in the WorldScripts folder with the following contents

dz modbasics structure.png

modded class PlayerBase		// modded keyword for modding existing class
{
	override void OnJumpStart()	// overriding existing function
	{
		super.OnJumpStart();	// call the original jump function so we don't break stuff
		Print("My first mod, yay!"); // our modded print
	}
}


dz modbasics structure2.png

class CfgPatches
{
	class FirstMod
	{
		requiredAddons[]={""};
	};
};

class CfgMods
{
	class FirstMod
	{
	    type = "mod";
		
	    class defs
	    {
			
			class worldScriptModule		
            {
                value = "";
                files[] = {"FirstMod/WorldScripts"};
            };
        };
    };
};


Using correct script module is important! Vanilla file PlayerBase.c (which contains PlayerBase class we are modding) is located in 4_World so we need to define path to worldScriptModule scripts in our config.cpp in order for our PlayerBase script mod to work.

  • Done! It is time to pack our mod into a .pbo

Packing into pbo

  • Using the DayZ Tools launcher, open Addon Builder
  • Set addon source directory, in our case P:\FirstMod
  • Set destination directory, for example P:\PackedPbos
  • In options, set a path to project folder, in our case it will be P:\
  • Done! Mod can now be loaded using launch parameter -mod=P:\FirstModPacked

Testing the mod

Make sure to always properly test your mod before releasing to public!

Testing mod in singleplayer

Many mods can be tested in SP environment which you can easily set up by creating a ChernarusPlus custom mission folder, for example myMission.ChernarusPlus with a init.c file inside of it with following contents

class CustomMission: MissionGameplay
{
  void CustomMission()
  {
  }
};
 
Mission CreateCustomMission(string path)
{
  return new CustomMission();
}
 
void main()
{
	// Create player
	PlayerBase player = PlayerBase.Cast( ( GetGame().CreatePlayer( NULL, "SurvivorF_Linda", "2200 10 2200", 0, "NONE") ) );

	// Set your gear
	player.CreateInInventory("TShirt_Black");
	
	// Select player
	GetGame().SelectPlayer(NULL, player);
}

Modify the init.c to suit your testing needs, then launch DayZDiag_x64.exe with the following parameters


-mission=pathToMission\myMission.ChernarusPlus -mod=P:\FirstModPacked


which will start the game with a mod in SP environment.


If you are using the Script Editor, you will now see the custom message in the output section every time you jump. If you are not, navigate to your profiles folder ( default: WindowsProfilePath\AppData\Local\DayZ ) and open the most recent script.log file, which will contain the printed message.

Testing in multiplayer

When testing in MP environment, launch the DayZDiag_x64.exe in a server mode using the launch parameters


-server -config=serverDZ.cfg -mod=P:\FirstModPacked


where serverDZ.cfg can be copied from the DayZ Server distribution on Steam. You will need to modify following options:

BattlEye = 0; // turn off BE since diag exe does not run with it

verifySignatures = 0; // if testing mods which aren't properly signed yet

You can then join the server using DayZDiag_x64.exe with -mod=P:\FirstModPacked parameter

You can also use -connect=127.0.0.1 -port=2302 launch parameters to connect to the server directly, skipping the need to go through menu

Publishing

Additional steps you will need to go through when you want to share the mod with the world

  • Use DS utils (DayZ Tools) to create a private and public bikey and use it to sign your pbo, as well as include the public bikey in your mod
  • Use Publisher (DayZ Tools) to upload to Steam Workshop