You could make it that the other mods need to pass on their name, then store that with the car id. First thing that comes to mind:
-- On remote call to lock
global.locked[car.unit_number] = {
car = car,
mods = { [mod_name] = true }
}
-- On remote call to unlock
global.locked[car.unit_number].mods[mod_name] = nil
-- Empty table (no other mod locks this car)
if not next(global.locked[car.unit_number].mods) then
local tmp = car.car
global.locked[car.unit_number] = nil
toggle_cars(tmp)
end
-- Additional check for toggle_cars(entity)
if global.locked[entity.unit_number] then return end
-- on_configuration_changed
local function config_changed(event)
-- Check all mods that have been changed
for mod_name, data in pairs(event.mod_changes or {}) do
-- Mod has been removed
if not mod_name.new_version then
-- Remove mod entry from tables of all cars
for c, car in pairs(global.locked) do
car.mods[mod_name] = nil
end
end
end
[EDIT: Added the car entity to the table, that's needed for toggling its state.)