Jump to content

Adding more guns


Stormy

Recommended Posts

I've seen two threads already and wanted to try and consolidate all the questions about this here.

 

I've made some changes to the reloading scripts to make it easier to add extra weapons. Provided I can fix the remaining bugs, this should mean that the original lua scripts will not need tampering with in order to have additional weapons take advantage of the reloading scripts.

 

Preparing the mod directory

 

Find  your zomboid mod directory, if you launch the game, click mods, you'll find the path at the bottom of the mod window. Mine is:

 

C:\Users\Stormy\Zomboid\mods\

 

Where Stormy would be your windows user name.

 

Next, extract the following zip to that directory:

 

WARNING: It seems the files in the mod directory do not replace the original lua scripts perfectly. Override the files in the \Steam\steamapps\common\ProjectZomboid\media\lua\Reloading directory with those in the following archive:

 

http://download1653.mediafire.com/62216je2q0wg/cue340cf05muivz/Reloading+-+moddable.zip

 

And extract the following to the mod directory explained above.

 

http://download856.mediafire.com/8x5fpe7hgqyg/tttr0ci0smpr924/moreguns.zip

 

I've sorted out the mod structure for you, so you can continue building on the files inside. Once extracted, the file structure should resemble:

 

C:\Users\Stormy\Zomboid\mods\moreguns

C:\Users\Stormy\Zomboid\mods\moreguns\media

C:\Users\Stormy\Zomboid\mods\moreguns\media\lua

C:\Users\Stormy\Zomboid\mods\moreguns\media\scripts

 

The devs have been clever so that if you name the lua files the same in the mod directory, the game will replace the originals. Therefore, from now on, you can just modify these files to get the results you want. Remember, you'll have to enable the mod once upon starting the game and from then on it will use the mod until you disable it.

 

Note this means REPLACE not MERGE. If a zomboid update changes the original files, the change will not be brought across to the custom files meaning potential bug fixes would be missed. Once I figure out the remaining bugs I ask for these versions to be made 'official'.

 

Defining the items

 

In the directory:

 

C:\Users\Stormy\Zomboid\mods\moreguns\media\scripts\Mods\MoreGuns

 

there is an items.txt. This is where the majority of information about the item is found.

 

module MoreGuns
{
    item Colt45
    {
          item info here
    }
 
    item ColtClip
    {
          item info here
    }
}
 
I've defined the module name 'MoreGuns' which is the same as my mod name. This helps to reduce the difficulty of finding your particular items. Both the module name and the item name must contain no spaces or special characters. I won't go into details about the various fields in the item's information. I've copied mine directly from the existing pistol and changed only the display name.

 

There is an important script that I noticed to do with languages which must have additional entries for each weapon you add for the mod to work. These are to do with language translations. It's not immediately obvious (I don't fully understand it) but goes something like this.

 

In the C:\Users\Stormy\Zomboid\mods\moreguns\media\lua\Mods\Translate there is a file called Items_empty.txt. You need to create entries for your weapons in there. 

 

For your Colt where the weapon name is Colt .45 I've created the entry:

 

DisplayNameColt_.45 = "",

 

Replacing the space with an underscore. Same for the magazine

 

DisplayNameColt_Magazine = "",

 

Compare this with the items.txt in 

 

C:\Users\Stormy\Zomboid\mods\moreguns\media\scripts\Mods\MoreGuns

 

Here's the shorter entry (the magazine) as an example:

 

item ColtClip
{
   CanStack = FALSE,
   Weight = 0.2,
   Type = Normal,
   DisplayName = Colt Magazine,
   Icon = BerettaClip,
}
 
You'll see the name in the Items_empty.txt corresponds to the DisplayName of the item in the items.txt. 
 
Updating the LUA files
 
 
In the folder:
 
C:\Users\Stormy\Zomboid\mods\moreguns\media\lua\Mods\Reloading
 
You should be able to see the file ZMoreGuns.lua. It is named 'ZMoreGuns' rather than 'MoreGuns' because files are loaded in alphabetical order and I need it to load after storymysReload.lua
 
Anyway, if you open the file, you should be able to see two entries. One for the magazine and one for the weapon. I've declared the magazine first. Here is the information broken down:
 
local coltClip = {
name = getItemText("Colt Magazine"), -- Make sure this is the same as the display name in items.txt
moduleName = 'MoreGuns',-- The module the weapon was defined under in items.txt
reloadClass = 'ISReloadableMagazine', -- The type of reloading this item will follow (see below)
clipType = 'ColtClip',-- The item type as defined in the items.txt
ammoType = 'Bullets9mm',-- The type of ammo this item takes. You can create a new ammo type in items.txt
shootSound = 'none',-- The sound to play when this weapon fires
clickSound = nil,-- The sound to play when this weapon dry fires
ejectSound = 'none',-- The sound to play when a magazine is ejected
insertSound = 'stormyRevolverInsertRound',-- The sound to play when a round/magazine is inserted
rackSound = 'stormyRevolverInsertRound',-- The sound to play when this weapon is racked
containsClip = 0,-- Whether the item contains a magazine
maxCapacity = 15,-- The maximum capacity of this item
reloadTime = 30,-- The time taken to insert one round/magazine
rackTime = 10};-- The time taken to rack the item
 
For the colt itself there is one extra value:
 
clipData = coltClip
 
This is just pointing to the local maagzine declared above it. Finally, the following statements are called:
 
ReloadUtil:addWeaponType(colt)
ReloadUtil:addMagazineType(coltClip)
 
These add the weapon and its magazine to the list of weapons and magazines the reload utility is currently managing.
 
Reload Types
 
There are currently three reload types:
 
ISReloadableMagazine
ISSemiAutoWeapon
ISShotgunWeapon
 
A revolver type has not yet been implemented but would likely be restricted to a fixed number of chambers were I to implement it (for reasons to do with saving the reload data).
 
Provided everything compiles there should be no extra steps required.
 
I've left a debug key in the lua. The code for which can be found in the stormysReload.lua script. Press L and the game will give you the original Pistol, the new Colt,  a magazine for each and some ammo. Both use the 9mm ammo type. (I may have commented out the important lines though, make sure you remove the dash that start of any line for which you want to create an item).

 

There seems to be some glitches about the magazine appearing in your inventory. I need to look at these too. Hopefully though, there is enough here for you to make a start with.

Link to comment
Share on other sites

  • 3 months later...

Is it possible to have custom (and original) guns show that a magazine has been loaded, and for magazines to show how many bullets they have remaining?

 

Also, I tried searching the forums, but is there a bug that prevents having multiple magazines in your inventory? I had two pistols at one point, and unloading the magazine from one prevented me from being able to unload the other.

 

Basically, I would like to make a mod where spare magazines can be found, loaded, and then inserted into a pistol via the reload key (with empty magazines being put in the inventory if already present in the pistol)

 

Edit: I figured out the spare magazine issue.

Link to comment
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
×
×
  • Create New...