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:
[SOLVED]Need help changing starting items for mod
[SOLVED]Need help changing starting items for mod
Last edited by Jarumba on Thu Sep 26, 2019 7:30 pm, edited 1 time in total.
Re: Need help changing starting items for mod
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)
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)
-
- Fast Inserter
- Posts: 162
- Joined: Sun Oct 28, 2018 7:57 am
- Contact:
Re: Need help changing starting items for mod
You may use remove_item to remove a specific item type, or clear_items_inside to remove all items from inventory.
Factorio API is the site you can find all (most?) Lua commands you can use, so bookmark this.
Code: Select all
player.remove_item{name="iron-plate", count=40}
Code: Select all
player.clear_items_inside()
Re: Need help changing starting items for mod
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
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
-
- Fast Inserter
- Posts: 162
- Joined: Sun Oct 28, 2018 7:57 am
- Contact:
Re: Need help changing starting items for mod
Welcome. You can edit and add "[Solved] " to the subject title of your first post, so others will see this thread being solved.