Get the mouse hovered entity when blueprint is hold

Place to get help with not working mods / modding interface.
Post Reply
aeryen
Burner Inserter
Burner Inserter
Posts: 5
Joined: Sat Apr 27, 2019 8:42 pm
Contact:

Get the mouse hovered entity when blueprint is hold

Post 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().

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Get the mouse hovered entity when blueprint is hold

Post 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....
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.

aeryen
Burner Inserter
Burner Inserter
Posts: 5
Joined: Sat Apr 27, 2019 8:42 pm
Contact:

Re: Get the mouse hovered entity when blueprint is hold

Post 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

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Get the mouse hovered entity when blueprint is hold

Post 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.
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.

Post Reply

Return to “Modding help”