Your first PK3 project with ZScript

Handy guides on how to do things, written by users for users.

Moderators: GZDoom Developers, Raze Developers

Forum rules
Please don't start threads here asking for help. This forum is not for requesting guides, only for posting them. If you need help, the Editing forum is for you.
Post Reply
Kruno
Posts: 8
Joined: Fri Apr 26, 2019 9:43 pm

Your first PK3 project with ZScript

Post by Kruno »

It took me 2 days to cobble the information together to create my first ZScript PK3 project. I will now present it here so future users can benefit.

You need 3 files (no file extensions unless added):
MAPINFO
zscript.txt
script.zs

The bare data you need in these files are as follows:

MAPINFO:

Code: Select all

GameInfo {
	AddEventHandlers = "Cat"
	forcetextinmenus = true
}
NOTES:
AddEventHandlers is a list of EventHandlers you have overwritten.


zscript.txt:

Code: Select all

version "4.0"

#include "script.zs"
NOTES:
You can include all ZScript files of your project in here. Make sure you place things in the order they are used.


script.zs:

Code: Select all

class Cat : EventHandler 
{
	Actor player;

	override void WorldLoaded(WorldEvent e) 
	{
		super.WorldLoaded(e);
		self.player = players[consoleplayer].mo;

		Console.Printf("%s", "Activating Mod...");
	}


	override void WorldThingSpawned(WorldEvent e) 
	{
		super.WorldThingSpawned(e);

		Actor npc = e.Thing;

		if (!npc.bIsMonster 
			|| npc.IsFriend(self.player) 
			|| npc.GetClassName() == "Lost Soul") {
			return;
		}

		double rand = Random(0, 1);
		if (rand) {
			return;
		}

		npc.Health *= Random(2.0, 3.0);
		npc.SetDamage(npc.Damage*1.10);
	}
}
NOTES:
Grabs the player on Map load and prints a message. Also increases health and damage of monsters roughly 50% of the time. I shaded them in at one point but could not get the monsters to look the way I wanted to. I will play with this in future. I also hate Lost Souls!


FINAL:
Create a zip file called whatever name you want, but rename it so the extension is "pk3", copy the above files to it, and drag it onto GZDoom.exe and pick a game to play.

-------------------------------------------------------------------------------------

Why post this? I spent 2 days reading the forum, watching videos and reading the wiki, and looking at other people's work before I could get a simple hello world mod working. I figured if I posted this here I can use this as a reference in future and others will have a place to start. I will hopefully follow up with a simple set of tutorials that do things, but in a way that is very simple to follow and understand.
User avatar
Tartlman
Posts: 226
Joined: Thu Oct 11, 2018 5:24 am
Location: meme hell
Contact:

Re: Your first PK3 project with ZScript

Post by Tartlman »

Gonna be honest, the title is misleading and this is more of a guide on how to do your first event handler rather than something else. Also, you can probably roll back the required version of zscript to something older, which is a good practice in my opinion.
Post Reply

Return to “Tutorials”