Adding templates files to mods


Recommended Posts

In commondefs.lua you'll find templates used for items. I'll name a few examples:

  • item_template
  • weapon_template
  • melee_template

 

To create a new item in a mod with any of those templates is easy. Just add to the top of the file:

  • local commondefs = include ( "sim/unitdefs/commondefs" )

Now, let's say I want to create my own template my other mod files will use. Is there any way to add the path to this new template without merging the items I create and the template in the same file?

 

modinit.lua gets access to the variable modApi which is allowed to ask for the scriptpath for the mod, but as far as I am able to see none of the other script files have this luxury.

Link to comment
Share on other sites

I don't need it, but it would streamline a lot of what I'm trying to do, and let me split parts of the mod in manageable pieces instead of having a massive file with everything in it.

 

I tried your suggestion, but couldn't make it work.

 

Made a file with:

local commondefs = include("sim/unitdefs/commondefs")

commondefs.melee_template2 = util.extend(commondefs.item_template) {}

 

and in another file:

local commondefs = include("sim/unitdefs/commondefs")

item_tazer = util.extend(commondefs.melee_template2) {}

 

The melee_template2 works when it's in the same file as item_tazer, but not when I split them. Can you spot my error?

 

Figured it out. Simply had to include the file in the modinit.lua load function. Thanks for the help! Opens up a lot of doors for me.

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.