How to add new resource

Let’s create mod that adding new resource to game. As an example, it will be a mod that allows make nails from ore and pig iron at smith and use it for construction some buildings. You can download the whole mod example at the end of article.

Resources

 * 1) First of all, create new Steam Workshop mod. Edit icon.png and localization.csv as you like.
 * 2) Create imageset with 25x25 resource icon and place it in mod folder. Be sure, that you use full path to imagefile in your imageset and check it name. It is highly recommended to use for imageset the same name as your mod id.  [[File:Resedit 01.png]]
 * 3) Create *.lua script.  [[File:Rescreate 02.png]]

Code
Now let’s fill script.lua. Start by loading our imageset by filename: loadImageset( '937284520.imageset' ) Then define our resource at resParamsConfig : fv.core.resParamsConfig.nails {  weight = 1500 , storageClass = "MATERIAL" , sequence = 32 , limitCategory = "LOGS_CATEGORY" , mine = 7000 , icon = "937284520/nailIcon" , prefab = "/models/resources/Wood_stack_01.prefab" , transportPrefab = "/models/resources/Trans_wood_stack_01.prefab" , transportAnimation = "transport" , visibleName = loc( "nails" ) }

You can start with one of exsiting resource config and edit some parameters. As you can see, we set icon to image from our imageset and set visibleName to nails record from our localization.csv by loc function. Next step is editing craftConfig that contains information about all craft recipes. Add new record called nailCraft in it: fv.core.craftConfig.nailCraft = {  resourceOut = "nails" , resources = { pig_iron = 1 , ore = 2 },  craftCount = 3 , time = 4500 , visibleName = loc( "nails" ), } Now you can add this craft recipe to existing craft building. For instance, to the smithy. Redefine init function of it. It is good practice to save original function and call it in start of overridden function: local originalSmithyInit = fv.core.Smithy.init function fv.core.Smithy: init originalSmithyInit( self ) self :addCraftRecipes( "nailCraft" ) end

Finally, add nails to price of some buildings: fv.core.House_small1.config.price.nails = 3 fv.core.House_small1_2.config.price.nails = 3 That’s all.

Further improvements
Well... it's not really all yet.

If you go back and check the code for resParamsConfig, then you'll notice, that our new ressource is still using the 3D model of the woodstack. You can of cause edit this (upload a new 3D model) so your new ressource actually looks different, too.

prefab = "/models/resources/Wood_stack_01.prefab", transportPrefab = "/models/resources/Trans_wood_stack_01.prefab",

Download
You can download the whole mod example here: [nails example].