cursor position
Posted: Thu Sep 08, 2016 4:10 am
Hello,
I am working on a mod and that needs to access two things:
a) the position of the player's cursor
b) the placed entities under the player's cursor
I have struggled to get this working.
In regards to a), the player's cursor, I did look at http://lua-api.factorio.com/latest/LuaP ... r_position but this appears to be in screen coordinates, whereas I need the coordinates relative to the world and I don't know how I would translate those.
My current work around is to require the player to place an invisible entity, which triggers a) events.on_built_entity and that immediately destroys the placed item, and b) events.on_put_item which provides an event with a position. The problem is you cannot place items on top of other entities, or in water, so I am kind of getting stuck with that. Is there a cleaner way to do this? I have not fully explored surfaces, which might allow placing the invisible object anywhere, or capsules which might be able to deal with water? Any suggestions?
In regards to b), getting the entity under the player's cursor, I see on_player_selected_area, and player.selected, but I really need some sort of "on_cursor_hover" or some other event. Is there something obvious I am missing?
Any help is appreciated, or examples of other mods.
Thanks,
Lux
I am working on a mod and that needs to access two things:
a) the position of the player's cursor
b) the placed entities under the player's cursor
I have struggled to get this working.
In regards to a), the player's cursor, I did look at http://lua-api.factorio.com/latest/LuaP ... r_position but this appears to be in screen coordinates, whereas I need the coordinates relative to the world and I don't know how I would translate those.
My current work around is to require the player to place an invisible entity, which triggers a) events.on_built_entity and that immediately destroys the placed item, and b) events.on_put_item which provides an event with a position. The problem is you cannot place items on top of other entities, or in water, so I am kind of getting stuck with that. Is there a cleaner way to do this? I have not fully explored surfaces, which might allow placing the invisible object anywhere, or capsules which might be able to deal with water? Any suggestions?
In regards to b), getting the entity under the player's cursor, I see on_player_selected_area, and player.selected, but I really need some sort of "on_cursor_hover" or some other event. Is there something obvious I am missing?
Any help is appreciated, or examples of other mods.
Thanks,
Lux