Starter items

Place to get help with not working mods / modding interface.
Post Reply
User avatar
AlexPhoenix
Fast Inserter
Fast Inserter
Posts: 149
Joined: Tue Feb 18, 2014 7:48 am
Contact:

Starter items

Post by AlexPhoenix »

i making my mod as total overhault of base game, so i need to change(change, not add) items with which the player starts. so, how can i do this?

SilverWarior
Filter Inserter
Filter Inserter
Posts: 559
Joined: Mon Mar 04, 2013 9:23 am
Contact:

Re: Starter items

Post by SilverWarior »

The initial items and technologies that player starts with are defined in control.lua file. For instance if you want to cahnge which are intial times in freeplay then you need to change freeplay.lua.

NOTE: I don't recomend replacing original freeplay.lua file with your mod as it will prevent players to start freepla game without your mod. Instead make new file and place it into scenarios folder (I think) and it would alow players to start new custom scenario suited for your mod.
Last edited by SilverWarior on Fri Feb 21, 2014 7:42 am, edited 1 time in total.

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: Starter items

Post by FreeER »

The start items given in new worlds are within the data/base/scenarios/freeplay/control.lua file (that is go into Factorio's install location and find the data folder inside, then the base, then scenarios, then freeplay, then open control.lua with any text editor), then either scroll down to line 40 or search for "character.insert" to quickly find the relevant lines. However, if you changed this file you would have to distribute it to players and have them replace their freeplay, which would make it somewhat annoying if they decided to uninstall your mod, so instead of changing these I would use your own control.lua to instead remove the unwanted items added by the base game (see code block below), the exception would be if you were (for some reason) actually removing the base items from the game entirely (in which case you would want to instead supply an alternate freeplay scenario with your mod and players would use the 'custom scenario' option to start their world).

Code: Select all

game.oninit(function()
  if game.player.character then 
    --remove the items you do not want the player to have
    game.player.character.getinventory(defines.inventory.playermain).remove{name="iron-plate", count=8}
    game.player.character.getinventory(defines.inventory.playerguns).remove{name="pistol", count=1}
    game.player.character.getinventory(defines.inventory.playerammo).remove{name="basic-bullet-magazine", count=10}
    game.player.character.getinventory(defines.inventory.playerquickbar).remove{name="burner-mining-drill", count = 1}
    game.player.character.getinventory(defines.inventory.playerquickbar).remove{name="stone-furnace", count = 1}

    --now add the items you want
    game.player.character.insert{name="a-new-item", count=7}
  end
end)
You have to use getinventory because 'remove' is not a method/command/function of the character entity (only of inventories) and the defines.inventory.x are from the /data/core/lualib/defines.lua file (they specify the individual inventories of the player character). The if statement is to prevent an error in 'sandbox'/'god' mode.

User avatar
AlexPhoenix
Fast Inserter
Fast Inserter
Posts: 149
Joined: Tue Feb 18, 2014 7:48 am
Contact:

Re: Starter items

Post by AlexPhoenix »

i mean items for custom generated world, not scenarios.

immibis
Filter Inserter
Filter Inserter
Posts: 303
Joined: Sun Mar 24, 2013 2:25 am
Contact:

Re: Starter items

Post by immibis »

Try this in oninit to remove all starting items. Not tested.

Code: Select all

if game.player.character then
    for _, invtype in pairs({defines.inventory.playerquickbar, defines.inventory.playermain, defines.inventory.playerguns, defines.inventory.playertools, defines.inventory.playerammo, defines.inventory.playerarmor}) do
        local inv = game.player.character.getinventory()
        for name, count in pairs(inv.getcontents()) do
            inv.remove({name=name, count=count})
        end
    end
end

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: Starter items

Post by FreeER »

When you start a new game using Play->New Game, Factorio uses the freeplay scenario as it's template. If you want confirmation of that open the /data/base/scenarios/freeplay/locale/en.cfg file (in any text editor) and see if the msg-intro looks familiar to you :)
immibis wrote:Try this in oninit to remove all starting items. Not tested.
I think this would work better, tested using console

Code: Select all

if game.player.character then
    for _, invtype in pairs({defines.inventory.playerquickbar, defines.inventory.playermain, defines.inventory.playerguns, defines.inventory.playertools, defines.inventory.playerammo, defines.inventory.playerarmor}) do
        local inv = game.player.character.getinventory(invtype)
        inv.clear() --function provided to clear inventory, instead of getting the contents and looping through to remove each individually.
    end
end
The problem with this is if someone wanted to use another mod at the same time, this would also have a high chance of removing the other mod's start items as well (depends on which mod's oninit function was run first). That may not be what you want.

User avatar
AlexPhoenix
Fast Inserter
Fast Inserter
Posts: 149
Joined: Tue Feb 18, 2014 7:48 am
Contact:

Re: Starter items

Post by AlexPhoenix »

i override base mod, so i'm not really thinking about other mods now.

thanks, i will try when i'll by at home.

Post Reply

Return to “Modding help”