Inserting items into character-corpse

Place to get help with not working mods / modding interface.
Post Reply
Pi-C
Smart Inserter
Smart Inserter
Posts: 1654
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Inserting items into character-corpse

Post by Pi-C »

If a player has died, we can access the inventory of the character-corpse per script. We can also use surface.create_entity() to spawn a character-corpse, and we can set properties like character_corpse_player_index, character_corpse_tick_of_death, and character_corpse_death_cause to make this corpse appear somewhat authentic. However, the corpse will have 0 slots in its inventory, and it seems there is no way to insert anything into it. Is there something I'm missing, or is there really no way to put some loot into a corpse created by script?
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

User avatar
Silari
Filter Inserter
Filter Inserter
Posts: 490
Joined: Sat Jan 27, 2018 10:04 pm
Contact:

Re: Inserting items into character-corpse

Post by Silari »

When you spawn the corpse it takes a parameter that tells it what size you want the inventory to be: see https://lua-api.factorio.com/latest/Lua ... ate_entity and look for the 'character-corpse' section, there's an inventory_size parameter. You can then interact with a corpse inventory the same way you do with any other entity inventory.

Pi-C
Smart Inserter
Smart Inserter
Posts: 1654
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Inserting items into character-corpse

Post by Pi-C »

Silari wrote:
Sat Oct 16, 2021 12:02 am
When you spawn the corpse it takes a parameter that tells it what size you want the inventory to be
Thanks, that should work! It would have been too frustrating if I'd wasted two days' work only to find out that what I wanted to achieve was impossible. :-D
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Post Reply

Return to “Modding help”