Mod制作指南
这里有一个详细的mod制作教程,如果有问题,请参考此教程. http://www.factorioforums.com/forum/viewtopic.php?f=25&t=4570
准备工作
注意: 1. 请确定在作出更改前备份你的游戏文件 2. 请充分思考你修改部分可能会造成的影响
小技巧: 1. 如果你的改变没有产生影响,有可能是因为游戏版本的问题. 2. 在制作mod之前先了解异星工厂的数据文件是非常有帮助的. 3. 下面的链接会对mod制作者非常有帮助
安装
首先找到你的异星工厂文件夹. This page
制作mod之前,我们需要一个创意,比如我想添加一个可以投掷炸弹的轰炸机. 1)首先在mod文件夹中,创建一个新的文件夹叫 'Bomber Tutorial'.
2)在Bomber Tutorial 中,创建3个文件:
- info.json (关于这个mod的信息)
- data.lua (在这里定义需要加载哪些lua文件)
- control.lua (我们的mod想添加的动作)
3) 编辑info.json(或者复制粘贴):
{ "name": "BomberTutorial", "version": "0.1.1", "title": "FreeER's Step by Step Bomber Mod", "author": "FreeER", "contact": "http://www.factorioforums.com/forum/viewtopic.php?f=25&t=4570", "homepage": "http://www.factorioforums.com/wiki/index.php?title=Modding_Tutorial", "description": "Mod that adds a bomber to Factorio" }
4)在文件夹中创建一个新文件夹叫做'prototypes',这个文件夹将用来存放将要添加的物品之类的数据
我们现在已经拥有了第一个mod,但是目前为止他还没有任何效果.
5) 储存所有文件,然后开启Factorio.点击mod按钮,现在它可以显示我们只做的mod了! 但它目前没有任何效果,我们可以先将异星工厂关闭了.
制作mod内容
现在我们需要一个文件来描述我们的轰炸机,和轰炸机装载的炸弹. 1) 在prototypes文件夹中创建文件:
- item.lua (在这里添加新的物品)
2) 编辑下列代码:
data:extend({ { type = "item", name = "bomber", icon = "__BomberTutorial__/graphics/icon_bomber.png", flags = { "goes-to-quickbar" }, subgroup = "ammo", place_result="bomber", stack_size= 1, }, { type= "item", name= "bomb", icon = "__BomberTutorial__/graphics/icon_bomb.png", flags= { "goes-to-main-inventory" }, subgroup = "ammo", order= "c-d-b", stack_size= 5, } })
下面我们需要为我们的轰炸机添加配方,这样我们才能制造轰炸机.
1) 在prototypes文件夹中创建文件:
- recipe.lua
2) 在recipe.lua中输入:
data:extend({ { type = "recipe", name = "bomber", enabled = "true", ingredients = { {"iron-stick",50}, {"electronic-circuit",50}, {"iron-gear-wheel",50}, {"iron-plate",200} }, result = "bomber" }, { type = "recipe", name = "bomb", enabled = "true", ingredients = { {"electronic-circuit",10}, {"iron-plate",20}, {"explosives",5} }, result = "bomb" } })
现在我们需要一个文件来描述我们的轰炸机:
1) 在prototypes文件夹中添加文件:
- entity.lua
2) 编辑文件:
data:extend({ { type = "car", name = "bomber", icon = "__BomberTutorial__/graphics/icon_bomber.png", flags = {"pushable", "placeable-neutral", "player-creation"}, minable = {mining_time = 1, result = "bomber"}, max_health = 2000, corpse = "medium-remnants", selection_box = {{-0.7, -1.2}, {0.7, 1.2}}, acceleration_per_energy = 0.15, breaking_speed = 0.09, burner = { effectivity = 0.25, emissions = 20, fuel_inventory_size = 2, }, consumption = "1J", friction = 0.01, pictures = { filename = "__BomberTutorial__/graphics/sheet_bomber.png", priority = "high", frame_width = 211, frame_height = 211, direction_count = 9 }, rotation_speed = 0.005, weight = 50, inventory_size = 12 } })
现在我们已经基本完成了,需要告诉mod去加载我们的数据了.
3) 在data.lua中添加:
require("prototypes.item") require("prototypes.recipe") require("prototypes.entity")
4) 储存文件然后去享受你的轰炸机吧.
是时候学会如何投掷炸弹了
打开control.lua,将下列代码复制粘贴.
require "util" require "defines" --The code for FreeER's Step By Step Guide to Modding Factorio (Created for Factorio 0.3.x Updated to 0.10.x) AKA Bomber Mod game.oninit(function() glob.bomber = 0 end) game.onevent(defines.events.ontick, function(event) if game.player.character and game.player.character.vehicle and game.player.character.vehicle.name == "bomber" and game.player.character.vehicle.getinventory(2).getitemcount("bomb") >= 1 and event.tick-glob.bomber >= 180 then local bomb = game.findentities{{game.player.character.vehicle.position.x-5,game.player.character.vehicle.position.y-5}, {game.player.character.vehicle.position.x+5,game.player.character.vehicle.position.y+5}} local drop = false local biters = 0 for k,v in pairs(bomb) do if v.force.equals(game.forces.enemy) then drop = true if v.name == "small-biter" or v.name == "medium-biter" or v.name == "big-biter" then biters = biters + 1 if biters < 5 then --if five or more will be killed then drop drop = false end end end end if drop then glob.bomber = event.tick for k,v in pairs(bomb) do if v.force.equals(game.forces.enemy) then if v.health then v.die() else v.destroy() end end end game.player.character.vehicle.getinventory(2).remove{name="bomb", count=1} end end end)
|