I'm trying to get the hovered entity when the player presses a key. Using player.selected works just fine, except in the case when the player holds a blueprint (and an entity in the blueprint is under the cursor). Then player.entity will not be set.
Is there a way to get the entity when the player is holding a blueprint?
The hovered entity is still marked with the selection (but in red), so the game knows which entity the mouse is over at that time.
As I understand it, I can't really get the mouse cursor's world position, so I can't use player.update_selected_entity().
Get the mouse hovered entity when blueprint is hold
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Get the mouse hovered entity when blueprint is hold
That's a collision rectangle, not the selection box - as can be seen by the entity info tooltip *not* being shown. So... nope, API doesn't offer any way to read that as far as i know. Except for ye know... deleting the blueprint, reading the cursor the next tick and then putting the blueprint back again and putting an epilepsy warning on your mod....aeryen wrote: Fri Oct 16, 2020 3:58 pm The hovered entity is still marked with the selection (but in red),
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: Get the mouse hovered entity when blueprint is hold
Thanks. I thought about the tick - while deleting the blueprint isn't a problem (I want to set a blueprint up myself, so won't change it back to the original), I don't think this will work in multiplayer as I don't think that the entity under cursor will be set in the next tick then. But I might be wrong as I don't know how multiplayer is handled for that. For the single player case it should work fine.
Also there is no way to deregister from on_tick or is there? As I would only need it for a very short time
Also there is no way to deregister from on_tick or is there? As I would only need it for a very short time
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Get the mouse hovered entity when blueprint is hold
Usually there is no difference. And in this case other people don't see the BP anyway, only the holder.aeryen wrote: Tue Oct 20, 2020 6:32 pm But I might be wrong as I don't know how multiplayer is handled for that. For the single player case it should work fine.
Assign nil.aeryen wrote: Tue Oct 20, 2020 6:32 pm Also there is no way to deregister from on_tick or is there? As I would only need it for a very short time
Code: Select all
script.on_event(defines.events.on_tick,nil)
You can read about it in my tutorial.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.