Can't get to access to the area an entity is covering

Place to get help with not working mods / modding interface.
Post Reply
Helldragger
Burner Inserter
Burner Inserter
Posts: 11
Joined: Mon May 15, 2017 11:20 pm
Contact:

Can't get to access to the area an entity is covering

Post by Helldragger »

I need to access to the area tiles an entity will take when built, and I can't get to find a way to get the entity size in my event handler,
I tried to use the collision_box property but it returns a () instead of a bounding_box,
I also tried to use the tile_width and tile_height properties but cannot seem to access it neither,
the bounding_box seems to be a nil in the on_built_event,
I can't get any access to the position of the player's cursor neither, I can't find any other solution..

I need help, is there a way to get the size of an entity being built?

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

Re: Can't get to access to the area an entity is covering

Post by Klonan »

Helldragger wrote:I need to access to the area tiles an entity will take when built, and I can't get to find a way to get the entity size in my event handler,
I tried to use the collision_box property but it returns a () instead of a bounding_box,
I also tried to use the tile_width and tile_height properties but cannot seem to access it neither,
the bounding_box seems to be a nil in the on_built_event,
I can't get any access to the position of the player's cursor neither, I can't find any other solution..

I need help, is there a way to get the size of an entity being built?
You should be able to get the collision box through the entity prototype:

Code: Select all

script.on_event(defines.events.on_built_entity, function(event)
  local entity = event.created_entity
  local prototype = game.entity_prototypes[entity.name]
  game.print(serpent.line(prototype.collision_box))
end)

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

Re: Can't get to access to the area an entity is covering

Post by Nexela »

If you are using the on_built event then you have an entity you can work with and get the bounding_box with the correct position offset using

script.on_event(defines.events.on_built_entity, function(event)
local entity = event.created_entity
local area = entity.bounding_box
game.print(serpent.line(area))
end)

Helldragger
Burner Inserter
Burner Inserter
Posts: 11
Joined: Mon May 15, 2017 11:20 pm
Contact:

Re: Can't get to access to the area an entity is covering

Post by Helldragger »

OMG I am so so so stupid, I tried Nexela approach before and got a nil because I used regular indexes instead of the x and y key values...

Thanks to both of you for your quick and helpful answers, kudos to both of you! It works! :P Let's see if I can make biomes more interesting now!

Edit: btw, thanks to you I discovered the serpent library :P so useful damn!

Post Reply

Return to “Modding help”