on_player_placed_wire / on_player_put_item_in_chest

Post Reply
Roblin
Burner Inserter
Burner Inserter
Posts: 15
Joined: Tue Nov 22, 2016 12:06 pm
Contact:

on_player_placed_wire / on_player_put_item_in_chest

Post by Roblin »

I would like to request an event:

on_player_placed_wire
contains:
player :: the player that placed the wire
wire :: the type of wire placed
end_point_1 :: one of the entities connected by the wire
end_point_2 :: the other entity connected by the wire
circuit_network :: the circuit network this wire connects to (not sure if this is even a thing that is recorded, just putting it here for completeness sake)

I intend to use this to make it so that whenever a wire is placed, I get a new wire of the same type for free put into my hand, effectively making wires free beyond the initial crafting cost, I also intend to increase the crafting cost as some self-imposed balance. I'm just fixing the fact that I am annnoyed by the fact that simply experimenting with circuit networks deletes resources from the world and that I can run out of wire while experimenting, forcing me to go get more. tiny amounts, sure, but enough to trigger mini-OCD.

I would only really need the event itself, the player that placed it and to know what type of wire it is, the endpoint/circuit network data just seems like highly related information that others might be interested in using.

I cannot do this with the currently available tools as literally the only event that triggers when placing wires is on_player_cursor_stack_changed, however, it is as far as I can tell impossible to distinguish between:
1. losing an item from your cursor stack because you used it to connect 2 entities with a wire.
2. losing an item from your cursor stack because you put 1 wire into a chest.
both of these actions will only trigger exactly 1 event (on_player_cursor_stack_changed) and your cursor changes the same way for both actions (stack amount -1), therefore rendering these actions indistinguishable.

arguably, it might also be sensible to have the event:

on_player_put_item_in_chest
contains:
player :: the player that put the item in the chest
item :: the item put in the chest
chest :: the chest the item was put into

I don't need it, but someone else might.

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

Re: on_player_placed_wire / on_player_put_item_in_chest

Post by Rseding91 »

on_player_put_item_in_chest isn't going to happen. Not even the game knows where the item went after it did entity.insert(...).

An event for a player connecting wires isn't out of the question but for your specific use case I think a different solution would be better. Something like a property that defines how many wires are needed to connect 2 entities and if wanted a mod could set it to 0 so it doesn't consume anything.
If you want to get ahold of me I'm almost always on Discord.

Roblin
Burner Inserter
Burner Inserter
Posts: 15
Joined: Tue Nov 22, 2016 12:06 pm
Contact:

Re: on_player_placed_wire / on_player_put_item_in_chest

Post by Roblin »

Fair enough, that does seem a lot easier to manipulate for my purposes, what are the odds that something like wires_to_connect will be implemented?

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

Re: on_player_placed_wire / on_player_put_item_in_chest

Post by Rseding91 »

Roblin wrote:Fair enough, that does seem a lot easier to manipulate for my purposes, what are the odds that something like wires_to_connect will be implemented?
I already implemented it for 0.17.
If you want to get ahold of me I'm almost always on Discord.

User avatar
Therax
Filter Inserter
Filter Inserter
Posts: 470
Joined: Sun May 21, 2017 6:28 pm
Contact:

Re: on_player_placed_wire / on_player_put_item_in_chest

Post by Therax »

Miniloader implements a mechanism through existing events to fire on_wire_added and on_wire_removed events. As Rseding has noted, it's not perfect, but it should handle the usual scenario you're talking about of a player placing and removing wires by hand.

https://github.com/mspielberg/factorio- ... placed.lua

As a suggestion, would it make more sense to restore a wire to the player's inventory when a wire is removed? That would make wires reusable, but not completely free.
Miniloader — UPS-friendly 1x1 loaders
Bulk Rail Loaders — Rapid train loading and unloading
Beltlayer & Pipelayer — Route items and fluids freely underground

Post Reply

Return to “Implemented mod requests”