Skip to content

Tutorial: Creating Project Zomboid mods using PZPW

Konijima edited this page May 2, 2023 · 1 revision

Tutorial: Creating Project Zomboid mods using PZPW

PZPW stands for Project Zomboid PipeWrench. It is a Node command-line tool used to create and manage PZPW projects.

This tool allows modders to create mods written in Typescript and easily generate their mods and workshop directory for publishing.

Useful Resources




Prerequisites

Before starting, make sure you have Node.js and npm (Node Package Manager) installed on your system. If you don't have them installed, you can download Node.js here which includes npm.




Step 1: Install PZPW Globally

To install PZPW globally, run the following command in your terminal or command prompt:

npm i -g pzpw

image




Step 2: Create a New Mod

To create a new mod, run the following command:

pzpw new "my-mod-id" "My Mod Name" "My Name"

image

Now, wait for PZPW to finish preparing your new mod environment. Once it's done, you can start working on your mod!




Step 3: Open the New Mod Directory in VSCode

After PZPW has finished setting up your mod environment, you should have a new directory named my-mod-id. To open this directory in Visual Studio Code (VSCode), follow these steps:

  1. Launch Visual Studio Code.
  2. Click on File in the menu bar.
  3. Select Open Folder... from the dropdown menu.
  4. Navigate to the my-mod-id directory.
  5. Click on the Select Folder button.

or right-click in the directory to open it with Visual Studio Code
image

Now your mod directory is open in VSCode, and you can start developing your Project Zomboid mod!




Step 4: Understand the Project Structure

There are two important directories in your mod project:

Assets

The assets directory is where you should store any asset files your mod requires, such as images, sounds, text files, and so on. Organizing these files in the assets folder will make it easier to manage and maintain your mod.

Src

The src directory contains the Typescript files for your mod. This is where you'll write your code, create new classes, and define the logic for your mod.




Step 5: Understand the Assets Folder Structure

To better understand the assets folder, let's dive deeper into its structure:

assets/mods/

The assets/mods/ directory is where you should set your mod icon and poster. Organize your additional assets inside the media sub-directory. This can include textures, sounds, and other files used by your mod.

assets/workshop/

The assets/workshop/ directory is where you should place your workshop preview image and description. The preview image is what users will see when browsing the Steam Workshop, and the description will provide them with more information about your mod.

assets/LICENSE.txt

In the assets/LICENSE.txt file, define your mod's license. This file outlines the terms and conditions under which your mod can be used, modified, and distributed. Choose an appropriate license for your project to ensure proper usage.




Step 6: Understand the Src Directory Structure

The src directory is where you write your mod's Typescript code. It's divided into three main sub-directories:

src/client/my-mod-id/

The src/client/my-mod-id/ directory contains the Typescript files for the client-side logic of your mod. This is where you should implement any functionality that will run on the player's computer, such as UI elements, visual effects, or client-side game mechanics.

src/server/my-mod-id/

The src/server/my-mod-id/ directory contains the Typescript files for the server-side logic of your mod. This is where you should implement any functionality that will run on the server, such as managing multiplayer interactions, synchronizing game states, or enforcing game rules.

src/shared/my-mod-id/

The src/shared/my-mod-id/ directory contains the Typescript files for the shared logic of your mod. This is where you should implement any functionality that will be used by both the client-side and server-side scripts, such as data structures, utility functions, or common game mechanics.




Step 7: Create a Sample Client Script

Now let's create a sample client-side script for your mod. In the src/client/my-mod-id/ directory, create a new file called my-first-script.ts. Add the following code to the file:

import { onGameStart } from "@asledgehammer/pipewrench-events";

onGameStart.addListener(() => {
    print("Hello World!");
});

This simple script imports the onGameStart event from the @asledgehammer/pipewrench-events package. It then adds a listener to this event, which will print "Hello World!" to the console when the game starts.




Step 8: Set Your Mod Info

In your mod project, you'll find a file named pzpw-config.json. This file is used to set all the data that would normally be found in your mod.info file. The data in this file will be automatically generated, so you only need to focus on setting the information in the JSON file.

The pzpw-config.json file uses a schema located at https://raw.githubusercontent.com/Konijima/pzpw-config-schema/master/pzpw-config.schema.json, which provides intellisense to help you understand what data you can add and how it should be structured.

The file has two main parts: mods and workshop.

Mods

The mods object contains information about the mods that are available in this project. You can set various properties such as the mod's ID, name, author, and more.

Workshop

The workshop object contains information about your workshop project. Inside this object, there is an array named mods which allows you to include the mods that you need in the published workshop entry. This helps you manage and bundle multiple mods together for publishing.

By configuring your pzpw-config.json file properly, you can streamline the process of managing your mod's data and publishing it to the Steam Workshop.




Step 9: Preparing the Compiler

Before you can compile your mod project, you need to install and set up the pzpw-compiler. Follow these steps to prepare the compiler:

Install the pzpw-compiler

The first time, you will need to install the pzpw-compiler using the following command:

npm install -g pzpw-compiler

Set the Cache Directory

Once the compiler is installed, you need to set the cache directory of your Project Zomboid location. Use the following command (replace the path with the correct one for your system):

pzpw-compiler cachedir set "C:\Users\Konijima\Zomboid"

Compile Your Mod

Now that the compiler is set up, you can start compiling your mod. There are two ways to compile:

  1. Compile mods into your Zomboid/mods directory:
pzpw-compiler mods
  1. Compile mods into your Zomboid/workshop directory:
pzpw-compiler workshop

Choose the appropriate method based on your needs. After compiling, your mod will be ready for testing and distribution!




Step 10: Add an Additional Mod to Your Project

If you want to add an additional mod to your existing PZPW project, you can do so by using the pzpw add command. For example, to add a mod called "Additional Mod" with the ID "additional-mod", run the following command:

pzpw add "additional-mod" "Additional Mod"

This command will create a new mod within your PZPW project and set up the necessary directories and files. You can then start developing the additional mod alongside your existing mod.

Remember to update your pzpw-config.json file to include the new mod in the mods object and, if necessary, add it to the workshop object as well.

image image