[Request] on_marked_for_deconstruction improvements

Post Reply
Ichorio
Burner Inserter
Burner Inserter
Posts: 10
Joined: Fri Jan 01, 2016 3:12 pm
Contact:

[Request] on_marked_for_deconstruction improvements

Post by Ichorio »

Surprised no one thought of this to be honest.
So, I've got a couple of things that would be insanely useful for mod devs that use it.
If not many, than at least one other dev that is trying to do the same thing I am.
  • event.player - The player that queued the event.
    - As far as I'm aware, a non-player can't mark something for deconstruction.
    This is where mods will probably break that assumption, but it'd be fairly simple to provide a helper script for mods wanting to mark something for deconstruction, as the event will require these values.
  • event.item - The item that was in hand, or used directly to mark the entity for deconstruction.
    - This might not even be necessary, as we can retrieve it from the player that marked the entities, but I thought to include it for sake of posterity.
This allows people with different types of deconstruction-items to distinguish which item caused which event, because as of now, if we wish to have an item that can highlight an area of entities, we have to use the deconstruction-item, and make sure that the item each player has equipped is the one we're looking for, and nothing else. If I find a player with the deconstruction planner, and the balancer checker (My mod's item, I'll not get into now), I have to cancel everything, because I have no idea if the event that was fired was because of my item, or the planner.

This results in poor gameplay, and a shockingly amount of workarounds from each mod that wants an item that highlights an area, to constantly make sure that it has a list of all possible items that it could collide with from other mods.

You might be able to go one step further, and when registering the event handler, take in an item name that is compared against the item that is used, and then only pass in the events from that item.
You could even go one layer out, and create an item that isn't a deconstructor, and highlights the area. Same as the deconstructor, except, when creating the item, providing a callback for all entities that were marked because of the item.
Either way, I hope that once you've gotten through this massive wall of text, that you see that I would greatly appreciate anyone looking into this, and maybe even coming up with a better solution than these.

Thanks for reading.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13232
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [Request] on_marked_for_deconstruction improvements

Post by Rseding91 »

The only thing preventing his is what you've already stated: https://forums.factorio.com/wiki/inde ... nstruction

Scripts can mark any entity for deconstruction/cancel deconstruction on any entity and have no association with a player or deconstruction item.
If you want to get ahold of me I'm almost always on Discord.

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: [Request] on_marked_for_deconstruction improvements

Post by DaveMcW »

event.player can be nil, right? We just need a reliable way to get the player if it exists.

Ichorio
Burner Inserter
Burner Inserter
Posts: 10
Joined: Fri Jan 01, 2016 3:12 pm
Contact:

Re: [Request] on_marked_for_deconstruction improvements

Post by Ichorio »

DaveMcW wrote:event.player can be nil, right? We just need a reliable way to get the player if it exists.
I think that would be the easiest choice, and simplest to use.
I'm assuming that only mods would mark something for destruction without a player.
I can't think of anything in vanilla that wouldn't have the player at hand.

Code: Select all

if event.player then
  -- Blah blah blah
end
Once we have that, all the issues that I mentioned would be solved.

User avatar
StanFear
Fast Inserter
Fast Inserter
Posts: 236
Joined: Sun Dec 15, 2013 2:49 pm
Contact:

Re: [Request] on_marked_for_deconstruction improvements

Post by StanFear »

with pretty much the same idea, a new event that is fired when a player uses a deconstruction planner with as event parameters, the area selected, and the item used.
that way, you don't even have to have items that can be destroyed to know the area the planer was used on !
(maybe this should be a new suggestion ? but since it is in order to achieve the same purpose, ...)

NearlyDutch
Inserter
Inserter
Posts: 47
Joined: Tue Oct 20, 2015 12:56 pm
Contact:

Re: [Request] on_marked_for_deconstruction improvements

Post by NearlyDutch »

Bump for the reason that there are now a handful of mods "misusing" an altered deconstruction planner item as a selection tool for their purposes. The problem that arises from this is that when multiple players hold such an item in hand, all entity markings have to be disregarded (including the ones from the vanilla deconstruction planner), as there is no way of knowing which player issued the event and therefore also no way of knowing which item was used to mark the entity for deconstruction.

I also agree with the posts before that an event.player value that is just nil if the marking was issued by a script would be a clean solution.

Is there any chance of this being implemented in a future release? It is quite a subtle and somewhat inexplicable "error", when people are playing multiplayer and their deconstruction planner items do not work if multiple players hold such items in the cursor stack.

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: [Request] on_marked_for_deconstruction improvements

Post by Choumiko »

I'm gonna jump in, all above solutions would work. Yet another solution:
A new item type "area-selector", it's whole purpose is to work like the decunstruction planner, but only fire an event when the area has been marked, with event.player_index, event_marked_entities, event_selected_area.
Mods then could create their own item, and check if the player holds their item and do their stuff or simply skip the event.

Post Reply

Return to “Implemented mod requests”