4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Factorioでmodを作ってみる-その1-

Last updated at Posted at 2018-04-15

基本的には
Factorio API Documents
を参考にLua Scriptを記述すればいい

参考になるのは
英語wikiのModのTutorial

サンプルとして、ゲーム開始時に任意のアイテムを所持するModを開発してみる -> ソース

ファイルの配置は
%AppData%\Factorio\mods\[Mod名のフォルダ]
に下記画像のようにinfo.jsonluaスクリプトを配置すればよい

robotStart.png

特定のイベント発生時にイベントハンドラが呼び出されるように設定する

例としてはゲーム開始時にプレイヤーが生成された時にイベントハンドラが呼び出されるように設定

event.lua
script.on_event(defines.events.on_player_created, on_player_created_event)

なお、イベント一覧に関しては
Eventsを参照

イベントハンドラ内で自作関数を呼び出すように設定する

例としては生成されたプレイヤーを引数として関数を呼び出すように設定

eventHandler.lua
local on_player_created_event = function(event)
  local player = game.players[event.player_index]
  add_items(player)
end

やりたいことを関数内に記述する

例としては引数として渡されたプレイヤーにロボット系のアイテムをいくつか所持するように設定

addItem.lua

local ITEMS_I_WANT = {
  {"roboport", 25},
  {"logistic-robot", 300},
  {"construction-robot", 100},
  {"logistic-chest-passive-provider", 200},
}

local add_items = function(player)
  for _,item in pairs(ITEMS_I_WANT) do
    if game.item_prototypes[item[1]] ~= nul then
      player.insert{name=item[1], count=item[2]}
    end
  end
end

なお、アイテム一覧に関しては
Factorio wikiのData.rawあたりに綺麗に揃っているので参照

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?