Page 1 of 1

[SOLVED]Modify items in player's starting inventory

Posted: Tue May 01, 2018 7:30 am
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?

Re: Modify items in player's starting inventory

Posted: Tue May 01, 2018 8:12 am
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.

Re: Modify items in player's starting inventory

Posted: Tue May 01, 2018 10:02 am
by Villfuk02
OK, thanks, but where do I get the player_index?
The game doesn't want to accept it just like that.

Re: Modify items in player's starting inventory

Posted: Tue May 01, 2018 10:15 am
by Villfuk02
I just figured it out. It is event.player_index.

Thanks for your help