Create_entity - Item Help [Solved]

Place to get help with not working mods / modding interface.
Post Reply
TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Create_entity - Item Help [Solved]

Post by TheSAguy »

Hi,

I'm trying to create a "Small Alien Artifact" when an unit dies.
However, the Small Alien Artifact is an "Item" and not an "Entity"

So I can't create it and add it to a table, using the below:

Code: Select all

        local worm_larva = surface.create_entity({
            name = "alien-artifact",
            position = entity.position,
            force = game.forces.enemy
        })

        
        global.small_alien_artifact_created[entity.unit_number] = {
            artifact = entity,
            time = event.tick
        }
How does one create an Item on the ground?

Thanks.
Last edited by TheSAguy on Sun Jun 25, 2023 5:07 pm, edited 1 time in total.

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2253
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: Create_entity - Item Help

Post by boskid »

When an item is on the surface, its actually an entity of prototype type `item-entity` that is created and registered on the surface. It holds a stack of items it represents and when being drawn it draws the item so it appears to be an item on ground. You want to create an instance of `item-on-ground` entity (that is of entity prototype type 'item-entity'), for example by doing this:

Code: Select all

surface.create_entity{name = "item-on-ground", position = entity.position, stack = "alien-artifact", force = "enemy"}

User avatar
Stringweasel
Filter Inserter
Filter Inserter
Posts: 323
Joined: Thu Apr 27, 2017 8:22 pm
Contact:

Re: Create_entity - Item Help

Post by Stringweasel »

A better way might be to instead tell the game to do it automatically, instead of through scripting, if it works for your use case. It would be much more reliable, and waaaay better for UPS. It's the usual way mods do it.

https://wiki.factorio.com/Prototype/Ent ... ealth#loot
Alt-F4 Author | Factorio Modder
Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby

TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Re: Create_entity - Item Help [Solved]

Post by TheSAguy »

Thanks for the feedback.

Post Reply

Return to “Modding help”