Ghosts created in LUA code are not aligned to the grid

Place to get help with not working mods / modding interface.
Post Reply
kds71
Long Handed Inserter
Long Handed Inserter
Posts: 91
Joined: Fri Mar 06, 2015 12:27 pm
Contact:

Ghosts created in LUA code are not aligned to the grid

Post by kds71 »

I'm trying to make a mod that would automatically find certain entities, mark them for deconstruction and place ghosts in their place. The problem is that every ghost created by game.createentity is somehow not aligned to the grid. This is part of code responsible for the replacement:

Code: Select all

  local player = game.getplayer(event.playerindex)
  local pos = player.position

  local entities = game.findentitiesfiltered{
      area = {{ pos.x - 32, pos.y - 32 }, { pos.x + 32, pos.y + 32 }},
      name = "basic-transport-belt"
  }

  for i = 1,#entities do

      local entity = entities[i]

      entity.orderdeconstruction(player.force)
      game.createentity{
          name = "ghost",
          innername = "fast-transport-belt",
          position = entity.position,
          direction = entity.direction,
          force = player.force
      }

  end
I was also trying to do it in console in game:

Code: Select all

/c game.createentity{ name = "ghost", innername = "fast-transport-belt", position = game.player.position, direction = 0, force = game.player.force }
And this is the result: http://i.imgur.com/s9t6vBW.png

Creating normal entities:

Code: Select all

/c game.createentity{ name = "fast-transport-belt", position = game.player.position, direction = 0, force = game.player.force }
works well - entity is aligned to the grid, why ghosts are not? Am I doing something wrong?

Kevin94
Inserter
Inserter
Posts: 46
Joined: Mon Dec 08, 2014 10:39 pm
Contact:

Re: Ghosts created in LUA code are not aligned to the grid

Post by Kevin94 »

No you aren't doing anything wrong. I also stumbled upon this problem and found ghost buildings created by scripts are aligned to the wrong grid: They are allways placed on the grid lines (.0) and not in the center of cells (.5) like all entities.
You could solve it by changing the ghost prototype (or creating an own ghost prototype) to not be aligned to the grid but than you have to take special care were you place it.
I took another aproach and wrote a lua method for this wich also supports specifying most of the entities settings (Recipe and logistic options especially):

Code: Select all

function buildEntity(args,ghost,recipe)
	local area = {{args.position.x-0.5,args.position.y-0.5},{args.position.x+0.5,args.position.y+0.5}}
	if game.canplaceentity (args) then
		 local e = game.createentity (args)
		 if recipe then
			e.recipe = recipe --todo station names
		end
		if ghost then
			e.die()
			local corpses = game.findentitiesfiltered {area=area, type="corpse"}
			for _,c in pairs(corpses) do
				c.destroy()
			end
		end
		return true
	end
	local e = util.findfirstentity(area, args.name)
	return e and e.direction == args.direction and (not e.getrecipe or e.recipe == recipe) --TODO other options
end
Only downside to this method is the creation of an explosion animation each time (corpse gets deleted).

kds71
Long Handed Inserter
Long Handed Inserter
Posts: 91
Joined: Fri Mar 06, 2015 12:27 pm
Contact:

Re: Ghosts created in LUA code are not aligned to the grid

Post by kds71 »

Thank you. I think I will try with creating / altering ghost prototype. Did you report this behaviour in bugs section? I want to report it but I don't want to make a duplicate.

Kevin94
Inserter
Inserter
Posts: 46
Joined: Mon Dec 08, 2014 10:39 pm
Contact:

Re: Ghosts created in LUA code are not aligned to the grid

Post by Kevin94 »

No, i didn't. I saw it as intended behavior and planned a larger feature request on this problem until I paused work on this mod and forgot it.

Post Reply

Return to “Modding help”