Client side
addDebugHook ("postFunction", function(sourceResource, functionName, isAllowedByACL, luaFilename, luaLineNumber, ... )
if sourceResource == getThisResource() then return end
local args = {...}
local veh = args[1]
local comp = args[2]
local visible = args[3]
local compVisible = getElementData(veh, "component_visible") or {}
compVisible[comp] = visible
setElementData(veh, "component_visible", compVisible)
end, {"setVehicleComponentVisible"})
addEventHandler ("onClientElementStreamIn", root, function()
if getElementType(source) ~= "vehicle" then return end
local compVisible = getElementData(source, "component_visible") or {}
for comp, visible in pairs (compVisible) do
setVehicleComponentVisible (source, comp, visible)
end
end)
addEventHandler ("onClientElementDataChange", root, function(db, _, visible)
if db ~= "component_visible" then return end
if getElementType (source) ~= "vehicle" then return end
local compVisible = getElementData(source, "component_visible") or {}
for comp, visible in pairs (compVisible) do
setVehicleComponentVisible (source, comp, visible)
end
end)