Page 1 of 1

Create_entity - Item Help [Solved]

Posted: Sat Jun 24, 2023 12:10 am
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.

Re: Create_entity - Item Help

Posted: Sat Jun 24, 2023 11:45 am
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"}

Re: Create_entity - Item Help

Posted: Sat Jun 24, 2023 3:24 pm
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

Re: Create_entity - Item Help [Solved]

Posted: Sun Jun 25, 2023 5:07 pm
by TheSAguy
Thanks for the feedback.