[SOLVED]Need help changing starting items for mod

Place to get help with not working mods / modding interface.
Post Reply
Jarumba
Burner Inserter
Burner Inserter
Posts: 8
Joined: Thu Apr 05, 2018 4:31 am

[SOLVED]Need help changing starting items for mod

Post 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:
Last edited by Jarumba on Thu Sep 26, 2019 7:30 pm, edited 1 time in total.

Jarumba
Burner Inserter
Burner Inserter
Posts: 8
Joined: Thu Apr 05, 2018 4:31 am

Re: Need help changing starting items for mod

Post 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)

Schallfalke
Fast Inserter
Fast Inserter
Posts: 162
Joined: Sun Oct 28, 2018 7:57 am
Contact:

Re: Need help changing starting items for mod

Post 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.

Jarumba
Burner Inserter
Burner Inserter
Posts: 8
Joined: Thu Apr 05, 2018 4:31 am

Re: Need help changing starting items for mod

Post 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

Schallfalke
Fast Inserter
Fast Inserter
Posts: 162
Joined: Sun Oct 28, 2018 7:57 am
Contact:

Re: Need help changing starting items for mod

Post 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.

Post Reply

Return to “Modding help”