Page 1 of 1

[SOLVED]Need help changing starting items for mod

Posted: Thu Sep 26, 2019 2:40 pm
by Jarumba
Hello modders, i would like to change my starting items in my mod. I found a thread about this but it is 6 years old and would like to see if anyone can help me with this. So far i know i need a control.lua. This is what i have so far.

character.removeitem{name="iron-plate", count=40} -- remove 40 iron plates from the character, or less if character doesn't have 40
character.removeitem{name="coal", count=character.getitemcount("coal")} -- remove all coal from the character

but im getting this error after i try to create the game. not on launch.

control.lua:1: attempt to index global 'character' (a nil value) stack traceback:

Re: Need help changing starting items for mod

Posted: Thu Sep 26, 2019 3:10 pm
by Jarumba
Update: i figured out how to spawn items but still at a loss on how to remove the starting items.

script.on_event(defines.events.on_player_created, function(event)
local player = game.players[event.player_index]
player.insert({name="simple-printing-processor", count=8})
player.insert({name="assembling-machine-1", count=4})
end)

Re: Need help changing starting items for mod

Posted: Thu Sep 26, 2019 4:14 pm
by Schallfalke
You may use remove_item to remove a specific item type, or clear_items_inside to remove all items from inventory.

Code: Select all

player.remove_item{name="iron-plate", count=40}

Code: Select all

player.clear_items_inside()
Factorio API is the site you can find all (most?) Lua commands you can use, so bookmark this.

Re: Need help changing starting items for mod

Posted: Thu Sep 26, 2019 6:08 pm
by Jarumba
SOLVED
Awesome, thank you this worked out great!

On to the next problem, if you want to look at it here it is:
viewtopic.php?f=25&t=76095

Re: Need help changing starting items for mod

Posted: Thu Sep 26, 2019 6:39 pm
by Schallfalke
Jarumba wrote: Thu Sep 26, 2019 6:08 pm SOLVED
Awesome, thank you this worked out great!
Welcome. You can edit and add "[Solved] " to the subject title of your first post, so others will see this thread being solved.