Project Zomboid

Project Zomboid

Not enough ratings
How to create Custom Firearm with working muzzle/attachments.
By Nik
Your first time trying to create your own gun mod, or struggling with making it work? I've been there. I've spend days figuring out why my gun model does not show / is semi transparent / is upside down / is bigger than LV Mall / muzzle flash is bigger than LV Mall / there is no muzzle flash at all / attachments dont show on weapon / attachments show on weapon but only if its held in hands / attachments are too big/small / attachments are placed nicely on weapon while in hands, but once placed on ground they're all over the place.
2
   
Award
Favorite
Favorited
Unfavorite
How to create Firearm mod with working muzzle flash/attachments
When creating my very first gun mod i've spend a lot of time just figuring out how does attachment system work and how to set up your gun model aswell as custom attachments.
With this guide i'll do my best to make sure that you won't go in blind and wander in the dark wondering:
Why is my muzzle flash not showing?
Why does attachment look good on weapon, but if you place it on ground its HUGE/small?
Why do my custom attachment look good on gun when player holds it in hands, but once placed they're all over the place?
Why is my muzzle flash or any other attachment so big/small/stretched?

Most of those will be no longer the case once you follow up with this (i hope so) short guide.
Preparing your gun/attachment model for exporting
I won't be going over how you should model or texture your Gun/Attachment, because there plenty of videos showing such things, however i will be showing you how your model should be set. Sure you can just export your model and hope for "good" placement for when player holds your gun in his hands, but lets not leave it to luck, because it might bite us later when we try to give our gun attachments.
If you creating a Longer firearm that will use vanila animations:
If you want to create a handgun that will be using vanila pistol animations, you have to do exacly like picture above, but then rotate it in edit mode so it's "Upside down". For some godly unknown reasons handguns are upside down:
Short explanation about .txt file
When starting out i'd suggest copying gun script from items_weapons.txt file that can be found in media>scripts> items_weapons.txt.
Remember to add Module Base and its brackets.
If youre not sure what some of those things mean, Here[pzwiki.net] is a place where many things are explained. It will be much better help than me trying to explain it, but if there is something i can do help, i'll do my best to do so.



Since that site explains many things about what code does what, i'll focus on attachments since its something thats i have not found explanation for.
Also here is link to download this mod in case you want to take a look at it yourself[drive.google.com]
I do not give permission to use those models in your mods, they're shared to help modders only.

World Static model on attachment is only there to display that model when attachment is on ground and has no effect on model on gun when attached.

Something to remember:
You can have a single attachment, for example Sling (most common in many mods) assigned to many diffrent guns of diffrent sizes. For each of these guns you can assign diffrent model for said sling. If you again take a look at picture above, Where you see Blue "x2 Scope" you can instead write diffrent model that should be displayed when said attachment is added to weapon (Yellow text in picture above).
Example: This is a single Attachment "Gun Sling" from mod im working on.
Even thought its a single item each gun has slightly modifed model to match its size.

Adding your attachments.
Lets get to it!

We end up with this result
Your muzzle attachment might require rotation.
Once you save anything on one of models with attachment editor, it will automaticly update your .txt file where your model is stated.
If
you have issue with your muzzle flash looking strange, check if your model does not have 2 UV maps by mistake. This might happen when joining 2 diffrent models into one. To fix the issue, remove one of UV maps. Keep in mind that
it might mess with your UV mapping, so make sure to have copy of your model just in case.

Examples of issues that will be fixed if you follow this guide.


Last words
I won't be going over distribution thing, since i am not the best at doing those and i'd rather not teach about things i'm not sure. I hope you will find help regarding those in other modding guides, or maybe by taking a look at any mod that adds custom items and see how they've added them to PZ distribution lists.

This guide was made from my experience with moding guns. Every now and then on PZ discord i see people asking for help with attachments and issues related with them and i hope this will be of help.
If i missed something don't be afraid to let me know. I'll try to keep this guide updated, at least untill b42 since then some things might change.
6 Comments
Nik  [author] 9 hours ago 
@Georjira I'm being told on discord that the guide, at least adding your own model in correct way aswell as attachments work flawlessly. For custom item script i still recommend using vanila firearm scripts and then changing stats for your liking.
Georjira 9 hours ago 
how much of this has changed for b42?
+_:_KingGodder_:_+ Jan 13 @ 10:53am 
I love that scar model, thanks for the help here!
Nik  [author] Nov 13, 2024 @ 9:03pm 
@Francisconov fbx is supported and encouraged by most modders.
Francisconov Nov 13, 2024 @ 1:25pm 
What format should my model be exported? im having a hard time dealing with .x files (my current blender version is not compatible and Direct X developer kit doesnt work for some reason).

I've heard PZ also handles .fbx files format, is this correct?
Texie Sep 12, 2024 @ 12:39pm 
very good guide , easy to understand. Good job! :steamthumbsup: