Vehicle Properties
Save snow chains in ESX, QBCore or Qbox vehicle properties.
Chains are kept by plate in the zyke_snowchains table out of the box, so this guide is optional. If your garage saves vehicle properties, you can also keep the chains in the properties under zykeSnowChains, so they travel with the rest of the vehicle.
SetVehicleChainData only asks the server to restore. The server puts back the chains your framework saved in that plate's properties (owned_vehicles.vehicle on ESX, player_vehicles.mods on QBCore and Qbox), never a copy a client sends, so players can't give themselves chains.
#ESX
Open es_extended/client/functions.lua.
References:
In ESX.Game.GetVehicleProperties, scroll to the bottom of the returned table and add zykeSnowChains after the last existing field:
diff modWindows = GetVehicleMod(vehicle, 46),
modLivery = GetVehicleMod(vehicle, 48) == -1 and GetVehicleLivery(vehicle) or GetVehicleMod(vehicle, 48),
modLightbar = GetVehicleMod(vehicle, 49),
+ zykeSnowChains = exports["zyke_snowchains"]:GetVehicleChainData(vehicle),
}
end
In ESX.Game.SetVehicleProperties, scroll to the bottom and add the setter after ESX applies props.tyreBurst, before the function closes:
diff if props.tyreBurst ~= nil then
for k, v in pairs(props.tyreBurst) do
if v then
k = tonumber(k)
if k then
SetVehicleTyreBurst(vehicle, k, true, 1000.0)
end
end
end
end
+
+ if (props.zykeSnowChains ~= nil) then
+ exports["zyke_snowchains"]:SetVehicleChainData(vehicle, props.zykeSnowChains)
+ end
end
#QBCore
Open qb-core/client/functions.lua.
References:
In QBCore.Functions.GetVehicleProperties, scroll to the bottom of the returned table and add zykeSnowChains after the last existing field:
diff modLivery = modLivery,
modKit49 = GetVehicleMod(vehicle, 49),
liveryRoof = GetVehicleRoofLivery(vehicle),
+ zykeSnowChains = exports["zyke_snowchains"]:GetVehicleChainData(vehicle),
}
else
return
end
end
In QBCore.Functions.SetVehicleProperties, scroll to the bottom and add the setter after the last existing prop apply, before the outer end:
diff if props.liveryRoof then
SetVehicleRoofLivery(vehicle, props.liveryRoof)
end
+ if (props.zykeSnowChains ~= nil) then
+ exports["zyke_snowchains"]:SetVehicleChainData(vehicle, props.zykeSnowChains)
+ end
end
end
#Qbox / ox_lib
Open ox_lib/resource/vehicleProperties/client.lua.
References:
ox_liblib.getVehiclePropertiesox_libreturned props table endox_liblib.setVehiclePropertiesox_libfixVehicleand return pointqbx_corevehicle persistence watches selected prop keysqbx_coresaves changed props server-side
In lib.getVehicleProperties, scroll to the bottom of the big return { ... } table and add:
diff tyres = damage.tyres,
bulletProofTyres = GetVehicleTyresCanBurst(vehicle),
driftTyres = gameBuild >= 2372 and GetDriftTyresEnabled(vehicle),
+ zykeSnowChains = exports["zyke_snowchains"]:GetVehicleChainData(vehicle),
-- no setters?
-- leftHeadlight = GetIsLeftVehicleHeadlightDamaged(vehicle),
In lib.setVehicleProperties, scroll to the bottom and add this after fixVehicle, before the final return:
diff if fixVehicle then
SetVehicleFixed(vehicle)
end
+
+ if (props.zykeSnowChains ~= nil) then
+ exports["zyke_snowchains"]:SetVehicleChainData(vehicle, props.zykeSnowChains)
+ end
return not NetworkGetEntityIsNetworked(vehicle) or NetworkGetEntityOwner(vehicle) == cache.playerId
end
In qbx_core/client/vehicle-persistence.lua, add zykeSnowChains to the watched keys:
diff local watchedKeys = {
'bodyHealth',
'engineHealth',
'tankHealth',
'fuelLevel',
'oilLevel',
'dirtLevel',
'windows',
'doors',
'tyres',
+ 'zykeSnowChains',
}
In qbx_core/server/vehicle-persistence.lua, save the diff before SaveVehicle:
diff if diff.tyres then
props.tyres = diff.tyres ~= 'deleted' and diff.tyres or nil
end
+
+ if diff.zykeSnowChains then
+ props.zykeSnowChains = diff.zykeSnowChains ~= 'deleted' and diff.zykeSnowChains or nil
+ end
exports.qbx_vehicles:SaveVehicle(vehicle, {
props = props,
})