Conditions to place ghost via surface.create_entity

Place to get help with not working mods / modding interface.
Post Reply
User avatar
nucleargen
Long Handed Inserter
Long Handed Inserter
Posts: 64
Joined: Sat May 07, 2016 4:51 pm
Contact:

Conditions to place ghost via surface.create_entity

Post by nucleargen »

I'm trying to place multiple ghosts (in different, non-colliding positions), but placing it via surface.create_entity fails with error and (not returned nil as in documentation if creation failed).
Placing entity prototype has flags: {"placeable-neutral", "not-repairable", "player-creation"}, and "container" type.
Method call:

Code: Select all

surface.create_entity{
	name = "entity-ghost",
	force = player.force,
	position = {x,y},
	inner_name = "entity-name",
	expires = true
}
What i do wrong?
The brightest future in the center of a nuclear explosion...2003©nucleargen

d3x0r
Filter Inserter
Filter Inserter
Posts: 316
Joined: Sun Jun 04, 2017 8:56 am
Contact:

Re: Conditions to place ghost via surface.create_entity

Post by d3x0r »

Out of curiosity what type of item is it? Cement, Brick? Rails?

User avatar
nucleargen
Long Handed Inserter
Long Handed Inserter
Posts: 64
Joined: Sat May 07, 2016 4:51 pm
Contact:

Re: Conditions to place ghost via surface.create_entity

Post by nucleargen »

type="container"
same as any chest
The brightest future in the center of a nuclear explosion...2003©nucleargen

User avatar
nucleargen
Long Handed Inserter
Long Handed Inserter
Posts: 64
Joined: Sat May 07, 2016 4:51 pm
Contact:

Re: Conditions to place ghost via surface.create_entity

Post by nucleargen »

Code: Select all

/c game.players[1].print(game.players[1].surface.can_place_entity{name="entity-ghost",position=game.players[1].position,inner_name="my_new_entity",force=game.players[1].force,expires=true})
returns false
Entity prototype is:

Code: Select all

    {
        type = "container",
        name = "my_new_entity",
        flags = {"placeable-neutral", "player-creation"},
        icon = icon_path,
        max_health = 1,
        collision_box = {{-0.35, -0.35}, {0.35, 0.35}},
        selection_box = {{-0.5, -0.5}, {0.5, 0.5}},
        inventory_size = 1,
        picture =
        {
	    filename = sprite_path,
            priority = "extra-high",
            width = 32,
            height = 32,
            shift = {0.0, 0.0}
        },
       map_color = entity_color,
    }
Prototype almost the same as wooden-chest prototype, but ghost placing fails.
The brightest future in the center of a nuclear explosion...2003©nucleargen

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: Conditions to place ghost via surface.create_entity

Post by Choumiko »

You're trying to place the chest at the players position, that's not gonna work.
Try:

Code: Select all

    /c game.player.print(game.player.surface.can_place_entity{name="entity-ghost",position={x=game.player.position.x + 1, y= game.player.position.y }, inner_name="my_new_entity",force=game.player.force,expires=true})
This should print true

User avatar
nucleargen
Long Handed Inserter
Long Handed Inserter
Posts: 64
Joined: Sat May 07, 2016 4:51 pm
Contact:

Re: Conditions to place ghost via surface.create_entity

Post by nucleargen »

Choumiko wrote:You're trying to place the chest at the players position, that's not gonna work.
Try:

Code: Select all

    /c game.player.print(game.player.surface.can_place_entity{name="entity-ghost",position={x=game.player.position.x + 1, y= game.player.position.y }, inner_name="my_new_entity",force=game.player.force,expires=true})
This should print true
Placing ghost entity of wooden chest returns true already on player pos. I've tried different coords, but with new entity - always false.
The brightest future in the center of a nuclear explosion...2003©nucleargen

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5150
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Conditions to place ghost via surface.create_entity

Post by Klonan »

try setting 'expires' to false

User avatar
nucleargen
Long Handed Inserter
Long Handed Inserter
Posts: 64
Joined: Sat May 07, 2016 4:51 pm
Contact:

Re: Conditions to place ghost via surface.create_entity

Post by nucleargen »

Klonan wrote:try setting 'expires' to false
Not working too :(
The brightest future in the center of a nuclear explosion...2003©nucleargen

Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: Conditions to place ghost via surface.create_entity

Post by Nexela »

What does your entity collide with? You are are trying to place an entity on top of your character so your character is probably blocking it.

User avatar
nucleargen
Long Handed Inserter
Long Handed Inserter
Posts: 64
Joined: Sat May 07, 2016 4:51 pm
Contact:

Re: Conditions to place ghost via surface.create_entity

Post by nucleargen »

Nothing collides. I'm trying to place ghost of entity. Tried another coords on flat terrain without anything.
The brightest future in the center of a nuclear explosion...2003©nucleargen

Post Reply

Return to “Modding help”