Page 1 of 1

Get the mouse hovered entity when blueprint is hold

Posted: Fri Oct 16, 2020 3:58 pm
by aeryen
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().

Re: Get the mouse hovered entity when blueprint is hold

Posted: Fri Oct 16, 2020 5:34 pm
by eradicator
aeryen wrote: Fri Oct 16, 2020 3:58 pm The hovered entity is still marked with the selection (but in red),
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....

Re: Get the mouse hovered entity when blueprint is hold

Posted: Tue Oct 20, 2020 6:32 pm
by aeryen
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

Re: Get the mouse hovered entity when blueprint is hold

Posted: Tue Oct 20, 2020 11:33 pm
by eradicator
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.
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 Also there is no way to deregister from on_tick or is there? As I would only need it for a very short time
Assign nil.

Code: Select all

script.on_event(defines.events.on_tick,nil)
But be careful to remember about reregistering it in on_load if and *only if* it was active.
You can read about it in my tutorial.