Raise an event if color of an entity is changed by player or script

Post Reply
Pi-C
Smart Inserter
Smart Inserter
Posts: 1698
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Raise an event if color of an entity is changed by player or script

Post by Pi-C »

TLDR:
I need an event that triggers when the color of an entity is changed. The event should support filters, and it should be possible to use it with script.raise_event().
What?
The event on_entity_renamed will be raised whenever the name (actually, it's entity_label) of an entity based on a spider-vehicle prototype is changed. While players can also use the GUI of a spider-vehicle to change its color, no event is raised in this case.

I'd like to get an event that is triggered when an entity's color is changed by a player or per script. Ideally, this event should be raised for any entity prototype. If that isn't feasible, I'd like to get this event at least for entities based on the prototypes that allow players to modify the color (character, locomotive, train-stop, and spider-vehicle). Also, it would be nice if the event could be filtered and if it could be used with script.raise_event(), as that would allow mods to ignore events raised by their own changes.
Use case:
GCKI will set the color of vehicles based on a car or spider-vehicle prototype to the color of the player who has claimed or locked them. Once a vehicle is released, its color will be reset to {r=0, g=0, b=0, a=0} -- even if the player had changed it to another color before GCKI took over.

Usually this is relevant only for spider-vehicles, but the mod Custom Color attaches a color mixer to the GUIs of characters, cars, and fluid/cargo wagons as well (that's why I'd prefer having this event for all kinds of prototypes). I should update my data if a player uses Custom Color to recolor a vehicle, and if my mod recolors a vehicle, Custom Color should update its own data and GUI. We are working on this problem, but let's face it: Having two custom events (both in GCKI and Custom Color) for the same thing isn't as efficient as having one vanilla event we both could listen to.
Even worse, I've another mod that closely interacts with GCKI -- for this mod I'd also have to add a custom event the other mods could respond to!
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

DiRten
Burner Inserter
Burner Inserter
Posts: 5
Joined: Sat Mar 04, 2023 9:01 pm
Contact:

Re: Raise an event if color of an entity is changed by player or script

Post by DiRten »

As the author of the CustomColor mod, I fully support it.

Bilka
Factorio Staff
Factorio Staff
Posts: 3218
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Raise an event if color of an entity is changed by player or script

Post by Bilka »

Hello, this was added at some point: https://lua-api.factorio.com/latest/eve ... or_changed
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Post Reply

Return to “Implemented mod requests”