[SOLVED]Modify items in player's starting inventory

Place to get help with not working mods / modding interface.
Post Reply
Villfuk02
Long Handed Inserter
Long Handed Inserter
Posts: 77
Joined: Mon Apr 30, 2018 7:23 am
Contact:

[SOLVED]Modify items in player's starting inventory

Post by Villfuk02 »

When you spawn in a new world, you already have a furnace, 8 iron and a burner miner. I'd like to add some of my own items to that starting inventory. How can I do that?
Last edited by Villfuk02 on Tue May 01, 2018 2:02 pm, edited 1 time in total.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Modify items in player's starting inventory

Post by bobingabout »

Villfuk02 wrote:When you spawn in a new world, you already have a furnace, 8 iron and a burner miner. I'd like to add some of my own items to that starting inventory. How can I do that?
Adding is fairly easy. there is a script in the control.lua of the scenario that defines what items it gives you, so you'd need to do the same thing in your mod.

As an example... If you create a control.lua in your mod and include the following...

Code: Select all

script.on_event(defines.events.on_player_created, function(event)
  local player = game.players[player_index]
  player.insert({name="iron-plate", count=8})
end)

script.on_event(defines.events.on_player_respawned, function(event)
  local player = game.players[player_index]
  player.insert({name="copper-plate", count=8})
end)
This will give you 8 iron plates when you start, and 8 copper plates when you respawn after death.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

Villfuk02
Long Handed Inserter
Long Handed Inserter
Posts: 77
Joined: Mon Apr 30, 2018 7:23 am
Contact:

Re: Modify items in player's starting inventory

Post by Villfuk02 »

OK, thanks, but where do I get the player_index?
The game doesn't want to accept it just like that.

Villfuk02
Long Handed Inserter
Long Handed Inserter
Posts: 77
Joined: Mon Apr 30, 2018 7:23 am
Contact:

Re: Modify items in player's starting inventory

Post by Villfuk02 »

I just figured it out. It is event.player_index.

Thanks for your help

Post Reply

Return to “Modding help”