Page 1 of 1
on_player_placed_equipment by mod/player
Posted: Fri Jul 10, 2020 10:17 am
by Linver
Hi, is possible add to the event
on_player_placed_equipment a new argument like "raised_by_a_mod" or a sort of, that with a boolean value, will inform the callback if the event was raised from a mod using the function
LuaEquipmentGrid.put(...) ?
As always, thank you for the attention.
Re: on_player_placed_equipment by mod/player
Posted: Fri Sep 03, 2021 11:55 am
by ickputzdirwech
They added two new events on_equipment_inserted and on_equipment_removed. However you still can't isolate when equipment was inserted/removed by script, since the new events also fire when it was done by the player. In case there is a way to do it, I would be interested in that.
Re: on_player_placed_equipment by mod/player
Posted: Fri Sep 03, 2021 12:09 pm
by eradicator
Afaik the player can only insert into grids they have an open gui of. So you should be able to isolate the cases that are definetly by script, leaving a mangled rest of player-or-script situations. (Based on basic logic without having had a look at the events.)
Re: on_player_placed_equipment by mod/player
Posted: Fri Sep 03, 2021 1:52 pm
by curiosity
A better and unambiguous logic would be to check if both events fire. If yes, then placed by a player (and you get which from the player event). The effectiveness of this depends on the event order though.
Re: on_player_placed_equipment by mod/player
Posted: Mon Nov 15, 2021 11:09 am
by mrudat
Perhaps an optional player field in on_equipment_inserted, if nil, it wasn't a player?
Do note that an inserter can... insert equipment into a grid under the correct conditions.
Re: on_player_placed_equipment by mod/player
Posted: Mon Nov 15, 2021 1:45 pm
by Rseding91
Why does it matter if it was done by a player or not?
Re: on_player_placed_equipment by mod/player
Posted: Mon Nov 15, 2021 4:25 pm
by DarkShadow44
mrudat wrote: Mon Nov 15, 2021 11:09 am
Do note that an inserter can... insert equipment into a grid under the correct conditions.
Uuuh, how?

Re: on_player_placed_equipment by mod/player
Posted: Tue Nov 16, 2021 8:20 am
by mrudat
Edit: To actually address the topic:
I suspect that one reason to want to know if the event was raised by a script is to avoid two scripts duelling over what precisely should be in the equipment grid or not.
I assume that that's a large part of why the script_raised events exist.
---
At least in 0.18, an item that is both a fuel item and equipment will be happily inserted by an inserter into a locomotive with an equipment grid's equipment grid.*
I don't know if it works in the general case of equipment that isn't also a fuel item, or if it still works that way in 1.1, but it was definitely a "Huh, that's weird" moment.
* This sentence was provided to you by the Department of Redundancy Department.
