Help with building mods
4 4

26 posts in this topic

Recommended Posts

Hi all,

First off I just want to say that I love PZ and I am excited to watch it grow into something great. I've been playing for a while now and I wanted to try my hand at creating a mod or two.

I have an idea for a series of mods that I'm going to start working on called PZMD. I'm a medical student and basically, I'd like to try and inject some more realism regarding human physiology, medicine, pharmacology, etc. However, a lot of this is pretty complex so I wanted to start somewhere easy so my first mod is going to be "PZMD Hygeine". This is what I would like to to do:

    Track player hygeine level and have effects based around poor/good hygiene (increased happiness, decreased chance of infection, etc.)
    Allow player to perform hygiene related actions such as brush teeth, shower, wash hands, etc.

To that end, I've decided to start with the "Brush Teeth" action. I'd like to use the existing toothbrush and toothpaste items in the players inventory to allow for the activation of a timed action when either the player right clicks on a water source (e.g. sink, bathtub) or has a water source in their inventory (e.g. bottle of water).

So, I've started but I think I need a little direction. I've been trying to do some reverse engineering (RoboMat's Lockpicking mod) and I've been looking through the javadocs but I can't seem to figure out how to determine if the player is clicking on a water source item or not. Getting the inventory shouldn't be too difficult but I'm a little lost with the other bits. If any one could havefer a nudge in the right direction, that would be great. Thanks!

Cheers,

 - Vanek

Share this post


Link to post
Share on other sites

Hey. What you need to do is start off low and not too ambitious. Your idea is really great and I would love to help you out. The tooth brushing is a good place to start.  Aside from basic learning basic LUA syntax, you need to know how mod data is stored, how events are triggered and how to add context options (right click menu options).

 

When holding a toothbrush in your primary hand and maybe paste in your left you could add a context option "Brush teeth" which increases the characters hygiene level.

 

A template could look like this.

function brushTeeth(_player)  --1. check player inventory for tooth brush and paste.  --2. make him hold them  --3. check if player is holding tooth brush and tooth paste  -- save hygiene  _player:getModData().hygiene = _player:getModData().hygiene + 1end Events.OnFillWorldObjectContextMenu.Add(brushTeeth)

Last but not least remember to submit your mod to pz-mods.net

Share this post


Link to post
Share on other sites

Hey Aricane,

 

I've read a couple of your articles, they've been a great help. Thank you.

 

Yea, that's pretty much what I've got laid out in my pseudo-code :) I'm pretty comfortable with Obj-C but Java and LUA is new to me so it'll be a learning experience. Thanks for the links! I'd read through the Events Reference one before but the others I hadn't seen. It look as if I should be able to get it done with that. Thanks again.

 

I'll drop another post when I have it done!

 

Cheers,

 

 - Vanek

Share this post


Link to post
Share on other sites

I think my context menu tutorial is a bit dated though. Afaik they have changed the code some versions ago, but it still should give you the right direction to work it out ;)

Share this post


Link to post
Share on other sites

I'm living in NSW, Australia at the moment so I'm running on Australian Eastern Time. 8:45 PM here at the moment.
 

 

I think my context menu tutorial is a bit dated though. Afaik they have changed the code some versions ago, but it still should give you the right direction to work it out ;)

 

 

I certainly hope so! Is there somewhere I can find a library of the current code? Or is it just the javadocs?

Share this post


Link to post
Share on other sites

I'm living in NSW, Australia at the moment so I'm running on Australian Eastern Time. 8:45 PM here at the moment.

Ahh okay, Central European Time here... thanks :)

Share this post


Link to post
Share on other sites

Oh, I was curious. If the player right clicks over some tile (for instance, the tile holding the sink/tub/etc.) does it return a list of "objects" that are on that tile including the "tile type"? Or would it be blank since there aren't any objects on that tile other than the tile itself?

Rawr...Forum spam...The bulk of my coding has been done re: iOS apps, so I'm used to all my debugging and coding being done in one area. Is there a way for me to put PZ into a debug mode so I can see what's going on at a code level? Or at least get a terminal output type of situation?

Share this post


Link to post
Share on other sites

I certainly hope so! Is there somewhere I can find a library of the current code? Or is it just the javadocs?

 

Depends on what you want to look at. The javadocs are also a bit outdated (I hope the team gets around pushing an updated version soonish), but the lua files can be found in plain text in the media/src folder (yay for lua).

 

 

Oh, I was curious. If the player right clicks over some tile (for instance, the tile holding the sink/tub/etc.) does it return a list of "objects" that are on that tile including the "tile type"? Or would it be blank since there aren't any objects on that tile other than the tile itself?

 

It should give you the tile itself too. I was able to use the context menu to read out the tilenames of clicked tiles a few versions ago.

 

Rawr...Forum spam...The bulk of my coding has been done re: iOS apps, so I'm used to all my debugging and coding being done in one area. Is there a way for me to put PZ into a debug mode so I can see what's going on at a code level? Or at least get a terminal output type of situation?

 

There is the ingame debugger (which I rarely used). You'll need to run the game with a -debug or -Ddebug flag (IIRC) and then press F11 ingame. On windows you also get a console.

 

If you are on Mac you can run the game through the terminal to view the output - that should work on linux too I guess.

Share this post


Link to post
Share on other sites
the lua files can be found in plain text in the media/src folder

 

I'm not sure if I'm just not looking in the right place or if there's something different with the OSX architecture but I don't seem to have a media/src folder in my PZ. The closest I could find was media/lua/client(or server or shared) which contained a number of folders of lua files (e.g. Camping, NPCs, Xp System, etc.).

Share this post


Link to post
Share on other sites

So I ran PZ with the -Ddebug flag but no joy on the F11 (or any other F-key) bringing something up. I also tried running it via Terminal but it gave me an error "Trace/BPT trap 5" whatever that means. I wonder if I can't run a Steam game via Terminal? Or am I missing something? I just ran the Project Zomboid.app with the "open" command.

 

Edit: I just found the little video RathLord made re: getting terminal output. So, that'd good now :)

Share this post


Link to post
Share on other sites

So, it seems I'm already stuck :( I'm starting to remember how it felt when I was learning ObjC and XCode :P I apologise if I'm a little needy as I'm getting started.

 

So, I wanted to start really small. I just wanted my mod to simply output a line to the terminal when the player right-clicked (i.e. print to terminal when a context menu is created). So, I wrote the most basic code possible I believe:

PZMDHygiene = {};-- ----------------- ---- --- Functions --- ---- ----------------- ---- Create the context menu items.function PZMDHygiene.createMenuEntries()    print("We're inside the context menu creation function.")end-- ------------- ---- --- Hooks --- ---- ------------- --Events.OnPreFillInventoryObjectContextMenu.Add(PZMDHygiene.createMenuEntries);

I booted into PZ and the terminal window informed me that my lua file was being loaded. However, when I started in Sandbox mode, nothing happened when I right clicked. Does print perhaps not print to the terminal?

Share this post


Link to post
Share on other sites

Huzzah! I figured it out. Turns out I was working with the wrong Event. I needed OnPreFillWorldObjectContextMenu. Duh...

 

Thanks Aricane :) I just saw that as I posted my reply.

Share this post


Link to post
Share on other sites

Can anyone make sense of my terminal output? When I run this, this is what I get:

 

We're in the create menu entries function!

table 0x145836625

zombie.iso.IsoObject@2f86104c

nil

 

It seems as if it is fetching the clicked objects properly (at least the first item, assuming there are multiples if a sink is clicked). And it seems that the object I am getting is one of IsoObject type. However, when I call the getName function on it I get no value returned.

 

Edit: it seems there is also a function called getObjectName. I tried it and it does return a result, however, that result is simply IsoObject.

function PZMDHygiene.createMenuEntries(_player, _context, _worldObjects)    print("We're in the create menu entries function!");        local player = getSpecificPlayer(_player);    local objects = _worldObjects;    local objectName;    local waterSource;        print(objects);        -- Output all of the objects to terminal.    for _, object in ipairs(objects) do        objectName = object:getName();        print(object);        print(objectName);    endend

Share this post


Link to post
Share on other sites

Hi all,

First off I just want to say that I love PZ and I am excited to watch it grow into something great. I've been playing for a while now and I wanted to try my hand at creating a mod or two.

I have an idea for a series of mods that I'm going to start working on called PZMD. I'm a medical student and basically, I'd like to try and inject some more realism regarding human physiology, medicine, pharmacology, etc. However, a lot of this is pretty complex so I wanted to start somewhere easy so my first mod is going to be "PZMD Hygeine". This is what I would like to to do:

    Track player hygeine level and have effects based around poor/good hygiene (increased happiness, decreased chance of infection, etc.)

    Allow player to perform hygiene related actions such as brush teeth, shower, wash hands, etc.

To that end, I've decided to start with the "Brush Teeth" action. I'd like to use the existing toothbrush and toothpaste items in the players inventory to allow for the activation of a timed action when either the player right clicks on a water source (e.g. sink, bathtub) or has a water source in their inventory (e.g. bottle of water).

So, I've started but I think I need a little direction. I've been trying to do some reverse engineering (RoboMat's Lockpicking mod) and I've been looking through the javadocs but I can't seem to figure out how to determine if the player is clicking on a water source item or not. Getting the inventory shouldn't be too difficult but I'm a little lost with the other bits. If any one could havefer a nudge in the right direction, that would be great. Thanks!

Cheers,

 - Vanek

I can't wait to see and use your mod(s) when you get everything written up. I always thought PZ needed this type of element added for my roleplaying fun. Good luck and welcome to the community.   

Edited by Kidlonewolf

Share this post


Link to post
Share on other sites

 

I can't wait to see and use your mod(s) when you get the written up. I always thought PZ needed this type of element added for my roleplaying fun. Good luck and welcome to the community.

 

Thanks :) I certainly hope I'll be able to get them done! Baby steps.

Share this post


Link to post
Share on other sites

Fellow Aussie from NSW as well :) I Have just started modding PZ and was wondering if you managed to get console to print out usable names or at least work out what the isos meant?

Share this post


Link to post
Share on other sites

Fellow Aussie from NSW as well :) I Have just started modding PZ and was wondering if you managed to get console to print out usable names or at least work out what the isos meant?

 

Hey ZimTown,

 

Sorry, this got lost in my inbox :( I did manage to get the console to print out usable names for me. This is how I did it. This function prints out whatever is on the gridSquare under the mouse cursor. You could easily adapt it to whatever is under the player or npc, etc.

function objectsUnderMouse()	local world = getWorld();	local cell = world:getCell();	local mx = getMouseX();	local my = getMouseY();	local player = getPlayer();	local wz = math.floor(player:getZ());	local wx, wy = ISCoordConversion.ToWorld(mx, my, wz);	wx = math.floor(wx);	wy = math.floor(wy);	print("Under the mouse:");	local square = cell:getGridSquare(wx, wy, wz);	local objects = square:getObjects();	for i=0, objects:size() - 1 do		print(i);		local v = objects:get(i);		local t = v:getTextureName();		print(t);	endend

I hope that helps :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
4 4