Page 1 of 1

entities.color: add car to entities

Posted: Sat Sep 21, 2019 11:40 pm
by Pi-C
I'd like to set the color of entities with type == "car" to always be the color of a certain player, whether the car is empty or whether anybody is in it. Here is a more detailed description.

According to the wiki, the car is not among the entities that allow to set the color. Could you add it, please?

Re: entities.color: add car to entities

Posted: Sun Sep 22, 2019 10:39 am
by darkfrei
+1

It's not synced between car color and player color, if the player changes his color, the color of the car will be not changed. The car has own color!
2019-09-22T12_35_39-Window.png
2019-09-22T12_35_39-Window.png (78.19 KiB) Viewed 1591 times
2019-09-22T12_35_52-Window.png
2019-09-22T12_35_52-Window.png (88.61 KiB) Viewed 1591 times

Re: entities.color: add car to entities

Posted: Sun Sep 22, 2019 11:52 am
by Pi-C
The car may have its own color, but it is set to the current color of the last player driving it, or the current color of the last player in it:

Make a multiplayer game. Place a car, it will have a neutral color. Let player 1 get inside -- he is the new driver, and the car will have the same color player 1 currently has. Switch users, and enter the same car as player 2. Player 2 is passenger now, the car will still have the color it inherited from player 1. Switch users again. As player 1, leave the car. The car has no driver now, but there still is a passenger (player 2). The car will be recolored using the current color of player 2. Switch users again, and as player 2, leave the car. It will still have the color it had after player 1 left it.

Obviously,, there is a connection between current player color and color of the car. Somehow, this color must be set, and I'm looking for a way to set it from a mod whenever on_player_driving_changed_state is triggered. (Perhaps also if the player changes his own color -- can't look into that now, though. REading glasses are at home, and the sunlight makes reading on this laptop too hard.)

Re: entities.color: add car to entities

Posted: Mon Sep 23, 2019 12:45 pm
by Bilka
Okay, added for the next version. Keep in mind that passenger color overrides the color that can be set through LuaEntity::color. So, setting a color only applies when the car is empty, otherwise the car will use the passenger color.

Re: entities.color: add car to entities

Posted: Mon Sep 23, 2019 4:52 pm
by Pi-C
Bilka wrote:
Mon Sep 23, 2019 12:45 pm
Okay, added for the next version.
Thank you!
Keep in mind that passenger color overrides the color that can be set through LuaEntity::color. So, setting a color only applies when the car is empty, otherwise the car will use the passenger color.
Am I correct in assuming that vehicle color set per mod will be overridden by a new driver first, and by passenger only if there is no driver? In this case, I could eject any passenger that gets into a car when there is no driver, and recolor the car again.

Re: entities.color: add car to entities

Posted: Mon Sep 23, 2019 5:08 pm
by Bilka
Passenger/driver is the same to me (when talking about cars in factorio). So, to clarify, both driver and gunner override the color when they're in the car, driver takes priority. The color that you see on the empty car is only set once the player leaves the car, so you can override it after they do that.

Re: entities.color: add car to entities

Posted: Tue Oct 22, 2019 8:54 pm
by Pi-C
Bilka wrote:
Mon Sep 23, 2019 5:08 pm
Passenger/driver is the same to me (when talking about cars in factorio). So, to clarify, both driver and gunner override the color when they're in the car, driver takes priority. The color that you see on the empty car is only set once the player leaves the car, so you can override it after they do that.
I've implemented that now (update hasn't been released yet), and it works great! Vehicles always have the color of the "owner" now, unless the owner isn't inside but somebody else is. As soon as the last player leaves the vehicle, it is recolored again (owner.color if there is an owner, {r=0, g=0, b=0, a=0} otherwise).