Beginners basic aricraft tutorial
Posted: Tue May 17, 2016 8:56 am
Recently I have come across the modding community of factorio and decided I'll give it a go myself.However the original tutorial I had hoped to follow was quite outdated with fixes all over the place so I've decided to rewrite the entire tutorial with my own features added in. Original tutorial can be found on the wiki done by FreeER, unfortunately Im unable to list a hyperlink.
Onwards with the tutorial. For this we will be implementing an aircraft to the game, based off the AC-130. This vehicle will have the ability to fly over forests and oceans, and shoot using shells or machine bullets.
1. Setup
4. "item.lua"
Onwards with the tutorial. For this we will be implementing an aircraft to the game, based off the AC-130. This vehicle will have the ability to fly over forests and oceans, and shoot using shells or machine bullets.
1. Setup
- For anyone who hasn't used mods before then this will give a quick overview on the setup required. All mods are stored in the mods folder, generally located at "G:\Users\user\AppData\Roaming\Factorio\mods", user being your own profile. By default the mods folder has not been created so simply create it yourself.
- Next step will be creating your own mod, for now create a folder in mods called "AC130Tutorial". This folder will contain all assets and code that our mod will be using. Create a file called info.json within AC130 and edit using a text editor. If you don't have a decent text editor already I would recommend using Notepad++. In this file we will add the following code, but feel free to change it however you want
Code: Select all
{
"name": "AC130Tutorial",
"version": "0.1.2",
"title": "AC130 Plane",
"author": "SampsonXD",
"description": "Mod that adds a AC130 Plane to Factorio"
}
- Most categories are self explanatory, however you are needed to pay extra attention to the name and version due to how factorio manages mods. That is when it looks at this file it will expect the mod to be contained in a folder with a particular format being "name"_"version". Because of this we will be needed to change our current folder name to "AC130Tutorial_0.1.2". If at a later date we update or modify the version number, the folder name has to reflect this.
- With that the first section of the mod has been completed.
- For now we are going to go add all the files required for the mod, with a brief explanation of what each one will do, however not include any code.
- Within your home folder("AC130Tutorial_0.1.2") create three more folders:
- "graphics" - This will be where we store any graphical files such as what our plane will look like and its icons.
"locale" - Used for language conversion, add a folder within this called en. This will be title/description used for English
"prototype" - All the fun code will be placed here.
- "graphics" - This will be where we store any graphical files such as what our plane will look like and its icons.
- As for the files used we have several:
- In graphics, unzip the attached graphics folder. it should contain AC130.png, AC130-Stripe1.png, AC130-Stripe2.png, icon_AC130.png, icon_AC130_tech.png.
- "AC130" is the initial image created and used for the followup images.
Both "AC130-Stripe" images contain a single stripe of the aircraft for animation purposes. This can be made to contain more as it only currently has 16 possible facing directions. It is split up due the factorio having a limited image size of 2048px in either direction.
"icon_AC130" is used when in the player's hotbar or inventory.
"icon_AC130_tech" is the image used within the tech tree.
- "AC130" is the initial image created and used for the followup images.
For "prototypes" add four files:- "entity.lua" - This will contain the definitions for our modded plane which is an entity. This entity will be built on what is already in the game. For instance, it's a vehicle, so we can get attributes from a car. It can shoot like a tank so we'll also add that. Theres no need to create what has already been made. Its not lazy, just efficient.
"item.lua" - This will be used for when it is in the player's inventory. What exactly it'll look like, and how many it can have in each stack to name a few.
"recipe.lua" - Simply what items are needed to craft the entity and if it requires research
"technology.lua" - Speaking of research, this file will determine prerequisites, and the ingredients needed to research.
Lastly go back to your home folder and add a file called "data.lua". This helps factorio to know about all the files it'll need to run the mod properly. - In graphics, unzip the attached graphics folder. it should contain AC130.png, AC130-Stripe1.png, AC130-Stripe2.png, icon_AC130.png, icon_AC130_tech.png.
- As previously stated this is where we will be telling factorio what to look for. We could put all of the code here. However that would end up producing an extremely long complicated piece of code so instead we split it up. So it'll just list what files are required.
Code: Select all
require("prototypes.item")
require("prototypes.recipe")
require("prototypes.entity")
require("prototypes.technology")
Code: Select all
data:extend({
{
type = "item",
name = "AC130",
icon = "__AC130Tutorial__/graphics/icon_AC130.png",
flags = { "goes-to-quickbar" },
subgroup = "ammo",
place_result="AC130",
stack_size= 1,
}
})
- Containing a bit more than previously we can see what image we are using for the hotbar/inventory, stack size, and other minor attributes. Something to note is the file location. Due to how it is handle we don't include the version number, instead we include the mod name, with two underscores before and after.
- This is the largest section of all, so will be broken up into 3 sections.
These a collection of simple attributes given to our vehicle.
Code: Select all
data:extend({ { type = "car", name = "AC130", icon = "__AC130Tutorial__/graphics/icon_AC130.png", flags = {"pushable", "placeable-neutral", "placeable-off-grid", "player-creation"}, minable = {mining_time = 1, result = "AC130"}, max_health = 4000, corpse = "medium-remnants", dying_explosion = "medium-explosion", energy_per_hit_point = 1, -- Set up to not collide with trees/water -- collision_mask = {}, selection_box = {{-2, -2}, {2, 2}}, braking_power = "200kW", effectivity = 0.5, consumption = "150kW", friction = 2e-3, rotation_speed = 0.005, weight = 50, guns = { "tank-cannon", "tank-machine-gun" }, inventory_size = 24, resistances = { { type = "fire", percent = 50 }, { type = "impact", percent = 30, decrease = 30 } },
Type lets us set it to be similar to a car giving it particular properties.
Now to give it the feel of an aircraft I decided to think what makes a car so different to a plane, well a plane can go over everything. So for this tutorial I simple made a car that doesn't collide with anything using "collision_mask = {}", it can "fly" over trees and even the ocean.
And as a aircraft with weapons I just added the attributes that a tank would normally have such as "guns = { "tank-cannon", "tank-machine-gun" }"
The following code is placed under what we just have.Although a simple functionality I wanted to talk about the changing of a single smoke source to a two and moving them from the back of a car to the the wings of a plane. Again why add something when a car already has what we need.Code: Select all
burner = { effectivity = 0.6, fuel_inventory_size = 1, --Two sources of smoke, 1 for each pair of engines smoke = { { name = "car-smoke", deviation = {0.25, 0.25}, frequency = 200, position = {2, 0}, starting_frame = 0, starting_frame_deviation = 60 }, { name = "car-smoke", deviation = {0.25, 0.25}, frequency = 200, position = {-2, 0}, starting_frame = 0, starting_frame_deviation = 60 } } },
This is the section for the animation of the aircraft. This is very important as we have to use the image strips created to display what direction we are moving. Otherwise we will be constantly facing forwards even if were moving to the left.Code: Select all
animation = { layers = { { width = 250, height = 250, frame_count = 1, direction_count = 16, shift = {0, 0}, animation_speed = 8, max_advance = 0.2, stripes = { { filename = "__AC130Tutorial__/graphics/AC130-Stripe1.png", width_in_frames = 8, height_in_frames = 1, }, { filename = "__AC130Tutorial__/graphics/AC130-Stripe2.png", width_in_frames = 8, height_in_frames = 1, } } } } } } })
Width and height will be of an individual frame, not the whole stripe.
Direction count is the total number of images we can display. in this situation we have two stripes of 8 so there's 16 in total.
Restating from before as we have a pixel limt 0f 2048 we split up the file into 2, however we can include as many as required to get the result needed.
- We have all the basics to start up factorio, and test out our mod to make sure everything is working so far. However we still can't create it.
To solve this we can use a command, first use "~" to bring up the console followed by "/c game.player.character.insert{name="AC130", count=1}" this should give use a AC130 in out hotbar. When you place it down you can jump in and see it requires fuel and ammo if we want to use it. Again you can try this using the previous command and just changing the name from "AC130" to "coal", "cannon-shell" and "basic-bullet-magazine".
Code: Select all
data:extend({
{
type = "recipe",
name = "AC130",
enabled = "false",
ingredients =
{
{"iron-stick",50},
{"electronic-circuit",50},
{"iron-gear-wheel",50},
{"iron-plate",400}
},
result = "AC130"
}
})
- Again this is quite self explanatory, to add ingredients or make it more expensive you can simply change values or add whole new rows.
Enabled however is an exception, it is used to determine if this recipe is unlocked from the start or if it needs to be unlocked through technology.
Code: Select all
data:extend({
{
type = "technology",
name = "AC130tech",
icon = "__AC130Tutorial__/graphics/icon_AC130_tech.png",
effects =
{
{
type = "unlock-recipe",
recipe = "AC130"
}
},
prerequisites = {"flying"},
unit =
{
count = 10,
ingredients =
{
{"science-pack-1", 4},
{"science-pack-2", 1},
{"science-pack-3", 2}
},
time = 40
}
}
})
- Here we use the image that we created earlier, and we determine what happens at unlock the "effects", if there is a prerequisite unlock needed. and the cost. Remember the cost is 10 times the given value, so this will need 40 science pack 1's.
Code: Select all
[item-name]
AC130 = AC-130
[item-description]
--AC130 = Heavy Support Aircraft
[technology-name]
AC130tech = AC-130 Design
[technology-description]
AC130tech = Discover the Power of a AC-130, with its ability to fly, use machine gun fire and launch missiles
- This is just a simple translation file, so where AC130 appears it can be converted to a given text. Such as the items name in game will be "AC-130" not just "AC130".
- And thats all I have, at this point you should be able to jump in game, research the technology and build your own AC130, be it a tad overpowered. There are some bugs such as landing on water and being able to get out, however I feel this has done enough to get any new modders going.
Please let me know about any errors you get or recommended tutorials you'd like to see.