I'm trying to make a tool that the player can hold in their cursor and click to select a single point, like the artillery remote. My first attempt was to use a capsule of type artillery-remote, but that seems hard-coded to have artillery behavior. All the capsule types seem to have some undesired hardcoded behavior. I settled on using the use-on-self type with an action that has infinite range and does 0 damage on yourself. The undesired behavior here is that the item gets used up, so in my event handler I have to give the player another one -- but, it doesn't get used up until after the event handler so what I actually have to do is set a flag so that the on_tick handler (which I use anyway) can give it back on the next tick.
Obviously, that's a mess. Is there a better way to do this? Note that I don't want to allow the user to select an area, so selection-tool is not helpful unless I missed a way to tell it to only select a point. Also, being able to use it in the zoomed-out map view, like the artillery-remote, would be ideal but isn't required.
How to make a point selection tool (like artillery remote)?
Re: How to make a point selection tool (like artillery remote)?
I would recommend the selection tool
If you make the selection box invisible, people won't be inclined to select an area,
And even if they do select and area, you can always just use the center of that area or something
maybe we could be some way to select from the map view, not sure
It also has the added benefit that 'shift + click' can have different functionality
If you make the selection box invisible, people won't be inclined to select an area,
And even if they do select and area, you can always just use the center of that area or something
maybe we could be some way to select from the map view, not sure
It also has the added benefit that 'shift + click' can have different functionality
- eradicator
- Smart Inserter
- Posts: 5206
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: How to make a point selection tool (like artillery remote)?
You have to make extra sprites to also hide the selection boxes around everything in the selected area for that to work, because there is no selection_mode = 'none' (Consider this a request ;). Here's the comment in my code from when i tried that last week:Klonan wrote:I would recommend the selection tool
If you make the selection box invisible, people won't be inclined to select an area,
And even if they do select and area, you can always just use the center of that area or something
Code: Select all
-- Valid values are: blueprint, deconstruct, cancel-deconstruct, items, trees, buildable-type, tiles, items-to-place, any-entity, any-tile, matches-force
selection_mode = {'any-entity'},
An easier implementation would be to add an invisible (or visible if you want a targeting marker) place_result entity with (collision_mask={},flags={'placeable-off-grid'}) to your item and use on_put_item, which is also raised if the player uses it outside of building_reach. Side effects: The entity-preview is dynamicallay tinted green/yellow/red depending on building_reach.
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: How to make a point selection tool (like artillery remote)?
in 0.17 we have force conditions you can set on the flag, so you can hide it with two incompatible conditions:eradicator wrote:You have to make extra sprites to also hide the selection boxes around everything in the selected area for that to work, because there is no selection_mode = 'none' (Consider this a request . Here's the comment in my code from when i tried that last week:Klonan wrote:I would recommend the selection tool
If you make the selection box invisible, people won't be inclined to select an area,
And even if they do select and area, you can always just use the center of that area or somethingApart from that it's probably the cleanest implementation you can get. Remaining side effect would be that that event is raised on mouse_up instead of mouse_down like everything else. Where right_bottom would be the coordinates of the cursor on mouse_up.Code: Select all
-- Valid values are: blueprint, deconstruct, cancel-deconstruct, items, trees, buildable-type, tiles, items-to-place, any-entity, any-tile, matches-force selection_mode = {'any-entity'},
An easier implementation would be to add an invisible (or visible if you want a targeting marker) place_result entity with (collision_mask={},flags={'placeable-off-grid'}) to your item and use on_put_item, which is also raised if the player uses it outside of building_reach. Side effects: The entity-preview is dynamicallay tinted green/yellow/red depending on building_reach.
Code: Select all
selection_mode = {"friend", "enemy"}
The other solution of the entity and on_put_item works well, I use it in MIRV:
https://github.com/Klonan/MIRV/blob/master/control.lua
- eradicator
- Smart Inserter
- Posts: 5206
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: How to make a point selection tool (like artillery remote)?
I didn't even consider multi-conditions. Though intuitively i'd have assumed they'd be combined by OR and not AND, had you not explained that.Klonan wrote: in 0.17 we have force conditions you can set on the flag, so you can hide it with two incompatible conditions:
Code: Select all
selection_mode = {"friend", "enemy"}
Hrng. Yea.Klonan wrote:Right bottom isn't always the last mouse position, you can create the selection box in any direction:
Haven't used MIRV yet. Does it have a target marker ala command-and-conquer? And if yes how do you handle the tinting of the entity preview? (Can we perhaps get a prototype flag/property to disable the tinting?)Klonan wrote: The other solution of the entity and on_put_item works well, I use it in MIRV:
https://github.com/Klonan/MIRV/blob/master/control.lua
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.