Your first PK3 project with ZScript

Handy guides on how to do things, written by users for users.
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.

Your first PK3 project with ZScript

Postby Kruno » Sat Apr 27, 2019 7:11 am

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 allExpand view
GameInfo {
   AddEventHandlers = "Cat"
   forcetextinmenus = true
}


NOTES:
AddEventHandlers is a list of EventHandlers you have overwritten.


zscript.txt:
Code: Select allExpand view
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 allExpand view
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.
Kruno
 
Joined: 26 Apr 2019

Return to Tutorials

Who is online

Users browsing this forum: No registered users and 0 guests