Page 1 of 1

Conditions to place ghost via surface.create_entity

Posted: Tue Jul 18, 2017 3:01 pm
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?

Re: Conditions to place ghost via surface.create_entity

Posted: Tue Jul 18, 2017 6:43 pm
by d3x0r
Out of curiosity what type of item is it? Cement, Brick? Rails?

Re: Conditions to place ghost via surface.create_entity

Posted: Wed Jul 19, 2017 12:48 am
by nucleargen
type="container"
same as any chest

Re: Conditions to place ghost via surface.create_entity

Posted: Wed Jul 19, 2017 2:14 am
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.

Re: Conditions to place ghost via surface.create_entity

Posted: Wed Jul 19, 2017 9:18 am
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

Re: Conditions to place ghost via surface.create_entity

Posted: Wed Jul 19, 2017 9:45 am
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.

Re: Conditions to place ghost via surface.create_entity

Posted: Wed Jul 19, 2017 9:54 am
by Klonan
try setting 'expires' to false

Re: Conditions to place ghost via surface.create_entity

Posted: Wed Jul 19, 2017 9:58 am
by nucleargen
Klonan wrote:try setting 'expires' to false
Not working too :(

Re: Conditions to place ghost via surface.create_entity

Posted: Wed Jul 19, 2017 8:36 pm
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.

Re: Conditions to place ghost via surface.create_entity

Posted: Thu Jul 20, 2017 12:26 am
by nucleargen
Nothing collides. I'm trying to place ghost of entity. Tried another coords on flat terrain without anything.