mp.events.add('vehicleDamageSync', () => {
const vehicle = mp.players.local.vehicle;
if (vehicle) {
const damageData = {
bodyHealth: vehicle.getBodyHealth(),
engineHealth: vehicle.getEngineHealth(),
doorsDamaged: [
vehicle.isDoorDamaged(0),
vehicle.isDoorDamaged(1),
vehicle.isDoorDamaged(2),
vehicle.isDoorDamaged(3)
],
windowsDamaged: !vehicle.areAllWindowsIntact(),
tiresBurst: [
vehicle.isTyreBurst(0, false),
vehicle.isTyreBurst(1, false),
vehicle.isTyreBurst(2, false),
vehicle.isTyreBurst(3, false)
]
};
mp.events.callRemote('syncVehicleDamage', JSON.stringify(damageData));
}
});
mp.events.add('updateVehicleDamage', (vehicle, damageDataJson) => {
const damageData = JSON.parse(damageDataJson);
vehicle.setBodyHealth(damageData.bodyHealth);
vehicle.setEngineHealth(damageData.engineHealth);
// Восстановление состояния дверей
damageData.doorsDamaged.forEach((isDamaged, index) => {
if (isDamaged) {
vehicle.setDoorBroken(index, true);
}
});
// Восстановление окон
if (!damageData.windowsDamaged) {
for (let i = 0; i < 4; i++) {
vehicle.fixWindow(i);
}
}
// Восстановление состояния покрышек
damageData.tiresBurst.forEach((isBurst, index) => {
if (isBurst) {
vehicle.setTyreBurst(index, true, 1000); // burst the tire
}
});
});