on_put_wire event and on_planned_rails event

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1207
Joined: Wed May 18, 2016 4:55 pm
Contact:

on_put_wire event and on_planned_rails event

Post by Mooncat »

Request:
I would like to have 2 events that are similar to the on_put_item event:
- on_put_wire: Called before players connects wire. Called before on_player_cursor_stack_changed (which is now the only event being called when connecting wires).
- on_planned_rails: Called before players uses RailPlanner to build rails. Called before on_built_entity. Other than player_index, it should also provide how many rails will be used. :mrgreen:

Edit: turns out placing tiles does not invoke the on_put_item event, so I would like to have another event for tiles, or simply, make on_put_item also called for placing tiles. :)


Use case:
I am making a cheat that allows players to keep the last item after building something. Like this:
Build rails
You have only one rail left in your hand, but this cheat allows you to use it infinitely.
The triggered events are printed on the console. The number after "T" is the tick number, e.g. T6598 = tick 6598.

Test Mode users will be familiar with this function. But my cheat has a different logic.
I am relying on the on_put_item event to give a free item based on the player's cursor_stack before the entity is built.
And I also listen on_built_entity. If the built entity is a ghost, I get the item back.

The problem is, using RailPlanner to build rails will not trigger on_put_item. So, I have to use the old trick in Test Mode - supply item in on_built_entity - if the player has no more item for building the entity after the entity is built, give him a free one.
RailPlanner
But I am not satisfied with the result, as you can see that the item slot changes. Anyway, it is just about perfection. :P

Connecting wires has a more serious problem. As I said above, on_player_cursor_stack_changed is the only event being triggered when connecting wires. There is no way I can know the player has used a wire and I should supply it. :(
Wiring
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: on_put_wire event and on_planned_rails event

Post by aubergine18 »

Rather than on_put_wire, I think it would be useful to have on_wire_changed event - that would be triggered when wires are added _or_ removed.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Post Reply

Return to “Modding interface requests”