In this page, we are going to share a modding tutorial for Factorio version 1.1. If you want to know information about Factorio modding tutorial, you are able to read this entire article.
A Modding Tutorial for Factorio
Now, let us start making your first mod.
-
- You are going to need a recent install of Factorio.
- You are going to need a text editor, such as Emacs, Vim, Sublime text, etc.
- You are going to need an understanding of the tutorial.
- You are going to need a n understanding of Lua as a programming language. You only need to know the syntax and how it works. If you have prior programming experience, it must not be difficult to pick up.
After you have all of those things, then you are able to begin. For this mod, you are going to make a set of armor which leaves behind damaging fire behind you as you walk. It will be resistant to fire fully, but weaker towards physical damage than heavy armor, making it an armor for hit and run attacks.
Creation of the directory structure
The game will expect mod to be laid out in a particular way. To start out, you have to make a folder in your user data directory or mods folder. The folder must have a specific name, fire-armor. When you are finished, then the mod directory should look like below:
-
- (User data directory, sometimes called. Factorio)
- mods
- fire-armor
Then, inside fire-armor, you have to make two files; info.json and data.lua. Now, the directory should look like below:
-
- (User data directory, sometimes called .Factorio)
- mods
- fire-armor
- data.lua
- info.json
The info.json file
Then, inside info.json, you are able to copy and paste the following into it:
{
“name”: “fire-armor”,
“version”: “0.1.0”,
“title”: “Fire Armor”,
“author”: “You”,
“factorio_version”: “1.1”,
“dependencies”: [“base >= 1.1”],
“description”: “This mod adds in fire armor that leaves behind damaging fire as you walk around.”
}
That is all for info.json. Next, in the data.lua file:
–data.lua
require(“item”)
It is a simple file. All you have to do is tell the game to execute the file called item.lua. Please make a file in fire-armor called item.lua.
Prototype creation
There are two methods to make prototypes in Factorio. Their first way requires making a complete prototype definition based on the documentation. And another way just uses a lua function to copy and modify an already existing definition. Now, we are going to use the last way. Thus, in item.lua, you have to copy and paste the following:
–item.lua
local fireArmor = table.deepcopy(data.raw[“armor”][“heavy-armor”]) — copy the table that defines the heavy armor item into the fireArmor variable
fireArmor.name = “fire-armor”
fireArmor.icons = {
{
icon = fireArmor.icon,
tint = {r=1,g=0,b=0,a=0.3}
},
}
fireArmor.resistances = {
{
type = “physical”,
decrease = 6,
percent = 10
},
{
type = “explosion”,
decrease = 10,
percent = 30
},
{
type = “acid”,
decrease = 5,
percent = 30
},
{
type = “fire”,
decrease = 0,
percent = 100
}
}
local recipe = table.deepcopy(data.raw[“recipe”][“heavy-armor”])
recipe.enabled = true
recipe.name = “fire-armor”
recipe.ingredients = {{“copper-plate”,200},{“steel-plate”,50}}
recipe.result = “fire-armor”
data:extend{fireArmor,recipe}
What we have just done here is we have already copied the definition of heavy armor. After that, changed its properties and injected it into the Factorio init with data:extend.
More on data.raw
When Factorio initializes, then all prototypes are put into a table named data.raw. The table holds all prototype types. Within those all prototype types, individual prototypes are identified by name: local prototype = data.raw[“prototype-type”][“internal-name”].
The control scripting
To finalize the mod, you have to make it be more than simple armor. Let us think about what you want the armor to do. You want the armor to make fire on the ground as we walk with the armor on. The event you are going to use is called on player_changed_position, because you want the fire to be made when the player moves. In your mod folder, you are able to make a file called control.lua. Automatically, the game will execute this file.
Inside control.lua, you have to copy and paste the following:
–control.lua
script.on_event(defines.events.on_player_changed_position,
function(event)
local player = game.get_player(event.player_index) — get the player that moved
— if they’re wearing our armor
if player.character and player.get_inventory (defines.inventory.character_armor). get_item_count (“fire-armor”) >= 1 then
— create the fire where they are standing
player.surface.create_entity{name=”fire-flame”, position=player.position, force=”neutral”}
end
end
)
Locale
If you have already tried loading up Factorio and attempting the mod so far, you may have noticed that the item name of the armor says “Unknown key”. It means that Factorio has the internal name, but it does not know what it should look like to the user. So, you need to make a locale for your mod. In the mod folder, you are able to make a folder called locale. After that, you have to make another folder inside that is called en, and then a file called any_name_can_be_here.cfg.
If you know another language, you are also able to translate your mod by making other language code files inside the locale.
Inside the .cfg file, you have to paste the following:
[item-name]
fire-armor=Fire armor
[item-description]
fire-armor=An armor that seems to catch the ground itself on fire when you take a step. It’s warm to the touch.
Warning: You have to notice how this is not a lua file. Locale is handled with C config files, thus the format is different.
The finished tutorial mod
Well, finally the mod is finished. Because this mod is just a tutorial, there is not much balance to it. If you want to share a mod with other users, it will need to be a zip file. For that, simply zip the fire-armor folder and then you are able to rename the archive to fire-armor_0.1.0 so that it will follow the expected mod zip name pattern of mod-name_version. Remember to not submit this tutorial mod to the mod portal as your own, because this is from the Wiki. But you are free to take this mod and modify it for your own use, adding technologies, changing recipes, and whatever.
AUTHOR BIO
On my daily job, I am a software engineer, programmer & computer technician. My passion is assembling PC hardware, studying Operating System and all things related to computers technology. I also love to make short films for YouTube as a producer. More at about me…
Leave a Reply