How to create new building

Let’s modding to add new building to the game!

Your first building
Add a simple Shack like in the game but as own.

First Steps
Make a good base to modding :
 * Create a new Steam Workshop Item (see this guide and select Modification type when it will be requested)
 * In your mod folder create a new file "myHouse.lua"

Simple code
Open "myHouse.lua", write : MyHouse = Class("MyHouse", fv.core.Shack) fv.core.GameMenu.model:regBuilding(MyHouse, 'livingHouses.MyHouse', 'GameLook1/iconHouseShack', 'MyHouse \n@Cost@: @priceShack@', 1)

And save it.

Test
Run the game, enable your mod and test if works! < Read more about Mod >

Explanation
In "myHouse.lua" : MyHouse = Class("MyHouse", fv.core.Shack) Add a new class MyHouse with class-name "MyHouse" inherit of Shack class. So MyHouse is exact copy of Shack. < Read more about Class >

You need to write "fv.core" before ".Shack" because it is a class of core script. fv.core.GameMenu.model:regBuilding(MyHouse, 'livingHouses.MyHouse', 'GameLook1/iconHouseShack', 'MyHouse \n@Cost@: @priceShack@', 1) Add a new button in GameMenu Houses. < Read more about Game Menu >

New custom building
It would be simple hangar with own icon and button in game menu. You can download the whole mod example at the end of this section.

Resources

 * 1) You can create new Steam Worshop Item (see this guide and select Modification type when it will be requested) or clean your own.
 * 2) Create imageset with 22x22 building icon and place it in mod folder. Building icon is white silhouette on transparent background. It will change color automatically corresponding to game theme. 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:Hangarxml.png]]
 * 3) Also you need of course prefab with 3D model of your building. You can create your own prefab (and place it in mod folder) or use one of existing in game (in this case you need only specify correct path to it later in guide).
 * 4) Create *.lua script.  [[File:Hangarfiles.png]]

Building Script
Let's fill hangar.lua. Start by creation new class by inherit one of buildings:

Hangar = Class( "Hangar", fv.core.House_small1)

At this point, hangar is exact copy of House_small1. Lets change some config values:

Hangar.config = {    visibleName = loc( 'hangarVisibleName' ), description = loc( 'hangarDescription' ), price = { logs = 6 },    doorPosition = "-1.5 0" , icon = "938362548/hangarIcon" , burnedPrefab = "/mods/938362548/Hangar.prefab" , damagedPrefab = "/mods/938362548/Hangar.prefab" , destroyPrefab = "/mods/938362548/Hangar.prefab" , prefabSteps = { "/mods/938362548/Hangar.prefab" } }

Note, that we defined only changed values. For instance, we set visibleName and description'' to records from localization.csv by loc function; set icon to image from our imageset; changed price and path to prefab. All other config values will be inherited from House_small1.

You can continue to alter Hangar building by overriding some of its function:

function Hangar: onStateChange -- new logic end function Hangar: onPrefabChange -- new logic end

Don't forget to load imageset by filename:

loadImageset( '938362548.imageset' )

Menu button
To be able to build house you need to add corresponding button to game menu. Write at the end of script file something like this:

fv.core.GameMenu.model:regBuilding(Hangar, 'livingHouses.hangar', '938362548/hangarIcon' , loc( 'tooltip' ), 1.5 )

Again, we used here icon from our imageset and record from localization.csv as tooltip text.

< Read more about this function >

Tooltip
In your localization.csv at tootip shortCode line insert : "Hangar \n@Cost@: @price938362548.Hangar@".

Hangar is the name, don't forgot to translate it for other languages. "\n" is a carriage return. @Cost@ is a tag, it be remplaced in game by translation of "Cost". @price...@ is a tag, it be remplaced in game by a translation of price with the resources cost and them icons. The model of price tag is @price[ItemID].[ClassName]@.

(see this guide to know how to find your Item ID)

< Read more about Classes >

Window
Also you can override createWindow function to change its popup window if you like:

function Hangar: createWindow return HouseWindow( self ) end

< Read more how to create custom window >.

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