Custom Color

by DiRten

More Colors for Vehicles, Players, Trains, Train Stops, Tanks, Cargo-wagons, Fluid-Wagons, Spidertrons -RGB value (Including color saturation) -Copy/Paste color (Shift-RMB -> Shift-LMB) *Vehicle don't change color with player*

Utilities
1 year, 5 months ago
1.1
4.08K
Transportation Trains

g Compatibility issues

1 year, 8 months ago
(updated 1 year, 8 months ago)

Hi! Looking at "Cars keep their color regardless of the player's color" on your info page, it seems your mod doesn't work well with GCKI and Autodrive.

GCKI allows players to "claim" and "lock" vehicles (cars + spider-vehicle prototypes). Locked vehicles can't be used by anybody (vehicle.active, vehicle.minable, and vehicle.operable are set to false), claimed vehicles can be summoned and will then be teleported to a place near the owner. In order to mark the owned/reserved state, I make sure to always set vehicle color to the color of the player who has claimed/locked it.

Autodrive is a poor man's version of "AAI Programmable Vehicles" that allows you to let vehicles (car + spider-vehicle prototypes) path automatically to a destination, either with or without a player inside. The vehicle color will be set to the color of the player who remote-controls it in Autodrive, unless it also has been claimed in GCKI (GCKI color will win over Autodrive color).

As our mods have opposite premises (vehicle should/should not have the same color as the player), they constantly try to undo the changes made by the other mods. Obviously, this is bad and confusing! So how should we cope with it?

  • Add conflicts with each other's mods. That's the easiest way out, but I'm more a friend of peaceful coexistence.
  • You don't allow setting the color for vehicles that are managed by my mods.
  • You tell my mods whenever you change the color of a vehicle, I store the color with my vehicle data and use it instead of player.color.

A quick grep for "remote" running over you files didn't find anything, but my mods already provide remote functions you could use. Therefore, option 2 would be easier to implement:

local v_data
if remote.interfaces.GCKI and remote.interfaces.GCKI.get_vehicle_data then
  v_data = remote.call("GCKI", "get_vehicle_data", vehicle)
elseif remote.interfaces.autodrive and remote.interfaces.autodrive.get_vehicle_data then
  v_data = remote.call("autodrive", "get_vehicle_data", vehicle)
end

if v_data and (v_data.owner or v_data.locker) then
  -- Don't set color
else
  -- Set color
end

However, I'd also be willing to either add new functions to my interface that you could call, or to listen to custom events you'd raise.

If you're interested in cooperating on this, we could discuss this per PM on the forums (I didn't find your name there, otherwise I'd have sent you a PM). If that's not an option, let's stay here (I'm not on Discord and don't intend to ever register there).

1 year, 8 months ago

Thanks for the report. I'll review your report, after I'm free, I'll look into this matter. It takes a little time, and we will make full compatibility.

1 year, 8 months ago

I have never used a "remote" before. My omission. I will study the issue more deeply.

1 year, 8 months ago

The simplest solution, I see checking not the player's color, but in the case of my mod, there is a list of all existing cars by their unique id (spidertron does not count). In this list, there is also their color. You can check the list and the color of the car in it.

1 year, 8 months ago

Exampe:
global.car_catalog[entity.unit_number] = entity.color

1 year, 8 months ago

"If you're interested in cooperating on this, we could discuss this per PM on the forums (I didn't find your name there, otherwise I'd have sent you a PM). If that's not an option, let's stay here (I'm not on Discord and don't intend to ever register there)."
I registered in forum. I can not write private messages due to lack of authority. :D

1 year, 8 months ago

The simplest solution, I see checking not the player's color, but in the case of my mod, there is a list of all existing cars by their unique id (spidertron does not count). In this list, there is also their color. You can check the list and the color of the car in it.

I know about your global.car_catalog (peeked into your mod with gvv). However, the global table in the control stage is only global to your own mod and can't be accessed by other mods. That makes sense, otherwise different mods that use identical table names (e.g. global.player_data) would break if the data you're expecting to find there have been overwritten by another mod.

This is where the remote interface comes in handy: It allows you to define an interface with one or more functions that can be called by other mods. In my earlier post, your mod would call remote.interfaces.autodrive.get_vehicle_data, then my mod would take over and run its function "get_vehicle_data", then return a table with the values that I want it to return. If there was a function set_vehicle_data on my interface (there isn't), I would allow you to manipulate the data I've stored -- but I would decide what arguments you can pass on.

If you'd want to push out information to several mods at once (even if you don't know whether any of the mods present will need it), custom events are the way to go: First you generate a new event ID (usually you'd also provide a remote function that other mods can call in order to get the ID of your event), then other mods register your custom event, and if you raise it and can pass on your data to all mods listening to your event. (By the way, there a a couple of vanilla events that can be raised manually as well. This is useful as you can pass on customized data in addition to the default data included by the game.)

1 year, 8 months ago

I registered in forum. I can not write private messages due to lack of authority. :D

Thanks! I didn't realize you were not registered there before (you could have used different names on the forums and the mod portal). Not being able to write private messages is a spam protection, so that no bot would register on the forum and annoy people by spamming them in their private messages. The way to get authorized is to post something on the forum first.

1 year, 8 months ago

I registered in forum. I can not write private messages due to lack of authority. :D

Thanks! I didn't realize you were not registered there before (you could have used different names on the forums and the mod portal). Not being able to write private messages is a spam protection, so that no bot would register on the forum and annoy people by spamming them in their private messages. The way to get authorized is to post something on the forum first.

Thanks a lot for the explanation. I am currently rewriting the code for my mods. Including I will include a remote in it. I will also study the issue of custom events. I make a clean readable library (including for you) so that anyone can read the code comfortably and understand everything. It will take a little time to study and clean work. I'll try to get access to a private message (Hopefully :D)

1 year, 8 months ago

I registered in forum. I can not write private messages due to lack of authority. :D

Thanks! I didn't realize you were not registered there before (you could have used different names on the forums and the mod portal). Not being able to write private messages is a spam protection, so that no bot would register on the forum and annoy people by spamming them in their private messages. The way to get authorized is to post something on the forum first.

While there is no access, I will create a separate discussion thread for you to be convenient.

New response