да тут дебажить надо, на глаз хрен поймешь. Я если сделаю то только на c#
Как это исправить ? он вниз едет по Z а вот этот другой по Y куОн имеет ввиду, что на видео переписанный скрипт
да тут дебажить надо, на глаз хрен поймешь. Я если сделаю то только на c#
Как это исправить ? он вниз едет по Z а вот этот другой по Y куОн имеет ввиду, что на видео переписанный скрипт
const DEFORMATION_DAMAGE_THRESHOLD = 0.01;
const MAX_DEFORM_ITERATIONS = 2;
function getVehicleOffsetsForDeformation(vehicle) {
const model = vehicle.model;
const dimensions = mp.game.gameplay.getModelDimensions(model);
const min = dimensions.min;
const max = dimensions.max;
const X = (max.x - min.x) * 0.5;
const Y = (max.y - min.y) * 0.5;
const Z = (max.z - min.z) * 0.5;
return [
new mp.Vector3(0.0, Y, Z * 0.5),
new mp.Vector3(0.0, Y, 0.0),
new mp.Vector3(0.0, -Y, Z * 0.5),
new mp.Vector3(0.0, -Y, 0.0),
new mp.Vector3(-X, 0.0, Z * 0.5),
new mp.Vector3(-X, 0.0, 0.0),
new mp.Vector3(X, 0.0, Z * 0.5),
new mp.Vector3(X, 0.0, 0.0),
new mp.Vector3(-X * 0.5, Y * 0.5, Z * 0.5),
new mp.Vector3(X * 0.5, Y * 0.5, Z * 0.5),
new mp.Vector3(-X * 0.5, -Y * 0.5, Z * 0.5),
new mp.Vector3(X * 0.5, -Y * 0.5, Z * 0.5),
new mp.Vector3(-X, Y, Z * 0.5),
new mp.Vector3(X, Y, Z * 0.5),
new mp.Vector3(-X, -Y, Z * 0.5),
new mp.Vector3(X, -Y, Z * 0.5)
];
}
PS : playerEnterVehicle убираем с клеинт сайда что бы в двойне не деформировал машину при входе в нёе
function getVehicleDeformation(vehicle) {
if (!mp.vehicles.exists(vehicle)) return [];
const offsets = getVehicleOffsetsForDeformation(vehicle);
const deformationPoints = [];
offsets.forEach(offset => {
const damageVector = vehicle.getDeformationAtPos(offset.x, offset.y, offset.z);
const dmg = Math.sqrt(damageVector.x ** 2 + damageVector.y ** 2 + damageVector.z ** 2);
if (dmg > DEFORMATION_DAMAGE_THRESHOLD) {
deformationPoints.push({ offset, dmg });
}
});
return deformationPoints;
}
function applyDeformation(vehicle, deformation) {
if (!mp.vehicles.exists(vehicle)) return;
if (deformation && deformation.length > 0) {
setVehicleDeformation(vehicle, deformation);
} else {
vehicle.setFixed();
}
}
function setVehicleDeformation(vehicle, deformationPoints) {
let iteration = 0;
let deform = true;
const deformationDamageMult = vehicle.getHandling('fDeformationDamageMult');
let damageMult = deformationDamageMult > 0 ? deformationDamageMult * 100.0 : 0;
while (deform && iteration < MAX_DEFORM_ITERATIONS) {
deform = false;
deformationPoints.forEach(def => {
const damageVector = vehicle.getDeformationAtPos(def.offset.x, def.offset.y, def.offset.z);
const dmg = Math.sqrt(damageVector.x ** 2 + damageVector.y ** 2 + damageVector.z ** 2);
if (dmg < def.dmg) {
vehicle.setDamage(def.offset.x, def.offset.y, def.offset.z, def.dmg * damageMult, 1000.0, true);
deform = true;
}
});
iteration++;
}
}
function isDeformationWorse(newDef, oldDef) {
if (!oldDef || newDef.length > oldDef.length) {
return true;
} else if (newDef.length < oldDef.length) {
return false;
}
for (let i = 0; i < newDef.length; i++) {
let found = false;
for (let j = 0; j < oldDef.length; j++) {
if (newDef[i].offset.x === oldDef[j].offset.x &&
newDef[i].offset.y === oldDef[j].offset.y &&
newDef[i].offset.z === oldDef[j].offset.z) {
found = true;
if (newDef[i].dmg > oldDef[j].dmg) {
return true;
}
}
}
if (!found) {
return true;
}
}
return false;
}
function isDeformationEqual(newDef, oldDef) {
if (oldDef == null && newDef == null) return true;
if (oldDef == null || newDef == null || newDef.length !== oldDef.length) return false;
for (let i = 0; i < newDef.length; i++) {
if (newDef[i].dmg !== oldDef[i].dmg) {
return false;
}
}
return true;
}
function handleDeformationUpdate(vehicle) {
if (!mp.vehicles.exists(vehicle)) return;
const deformation = getVehicleDeformation(vehicle);
const currentDeformation = JSON.parse(vehicle.getVariable('deformation') || '[]');
if (!isDeformationEqual(deformation, currentDeformation) && isDeformationWorse(deformation, currentDeformation)) {
mp.events.callRemote('storeVehicleDeformationState', vehicle.remoteId, JSON.stringify(deformation));
}
}
mp.events.add('playerLeaveVehicle', vehicle => {
handleDeformationUpdate(vehicle);
});
mp.events.add('playerEnterVehicle', (vehicle, seat) => {
setTimeout(() => {
if (seat === -1) {
const deformation = vehicle.getVariable('deformation');
if (deformation) {
applyDeformation(vehicle, JSON.parse(deformation));
}
}
}, 200);
});
mp.events.add('entityStreamIn', entity => {
if (entity.type === 'vehicle') {
setTimeout(() => {
const deformation = entity.getVariable('deformation');
if (deformation) {
applyDeformation(entity, JSON.parse(deformation));
}
}, 2000);
}
});
mp.events.add('storeVehicleDeformationState', (player, vehicleId, deformation) => {
const vehicle = mp.vehicles.at(vehicleId);
if (vehicle && mp.vehicles.exists(vehicle)) {
vehicle.setVariable('deformation', deformation);
}
});
mp.events.add("VD:fixDeformation", (player, vehicleId) => {
const vehicle = mp.vehicles.at(vehicleId);
if (vehicle && mp.vehicles.exists(vehicle)) {
vehicle.setVariable('deformation', null);
}
});
mp.events.add('fixVehicleDeformation', (player, vehicleId) => {
const vehicle = mp.vehicles.at(vehicleId);
if (vehicle && mp.vehicles.exists(vehicle)) {
vehicle.setFixed();
vehicle.setVariable('deformation', null);
}
});
да тут дебажить надо, на глаз хрен поймешь. Я если сделаю то только на c#
Он имеет ввиду, что на видео переписанный скрипт
лайк чату жпт Царапины это скорее всего декалии, их тоже по идее можно синхронизироватьРешено и получается идеальный результат вот такой вот результат:
Посмотреть вложение 15603Посмотреть вложение 15604
Client side :
Код:const DEFORMATION_DAMAGE_THRESHOLD = 0.01; const MAX_DEFORM_ITERATIONS = 2; function getVehicleOffsetsForDeformation(vehicle) { const model = vehicle.model; const dimensions = mp.game.gameplay.getModelDimensions(model); const min = dimensions.min; const max = dimensions.max; const X = (max.x - min.x) * 0.5; const Y = (max.y - min.y) * 0.5; const Z = (max.z - min.z) * 0.5; return [ new mp.Vector3(0.0, Y, Z * 0.5), new mp.Vector3(0.0, Y, 0.0), new mp.Vector3(0.0, -Y, Z * 0.5), new mp.Vector3(0.0, -Y, 0.0), new mp.Vector3(-X, 0.0, Z * 0.5), new mp.Vector3(-X, 0.0, 0.0), new mp.Vector3(X, 0.0, Z * 0.5), new mp.Vector3(X, 0.0, 0.0), new mp.Vector3(-X * 0.5, Y * 0.5, Z * 0.5), new mp.Vector3(X * 0.5, Y * 0.5, Z * 0.5), new mp.Vector3(-X * 0.5, -Y * 0.5, Z * 0.5), new mp.Vector3(X * 0.5, -Y * 0.5, Z * 0.5), new mp.Vector3(-X, Y, Z * 0.5), new mp.Vector3(X, Y, Z * 0.5), new mp.Vector3(-X, -Y, Z * 0.5), new mp.Vector3(X, -Y, Z * 0.5) ]; } function getVehicleDeformation(vehicle) { if (!mp.vehicles.exists(vehicle)) return []; const offsets = getVehicleOffsetsForDeformation(vehicle); const deformationPoints = []; offsets.forEach(offset => { const damageVector = vehicle.getDeformationAtPos(offset.x, offset.y, offset.z); const dmg = Math.sqrt(damageVector.x ** 2 + damageVector.y ** 2 + damageVector.z ** 2); if (dmg > DEFORMATION_DAMAGE_THRESHOLD) { deformationPoints.push({ offset, dmg }); } }); return deformationPoints; } function applyDeformation(vehicle, deformation) { if (!mp.vehicles.exists(vehicle)) return; if (deformation && deformation.length > 0) { setVehicleDeformation(vehicle, deformation); } else { vehicle.setFixed(); } } function setVehicleDeformation(vehicle, deformationPoints) { let iteration = 0; let deform = true; const deformationDamageMult = vehicle.getHandling('fDeformationDamageMult'); let damageMult = deformationDamageMult > 0 ? deformationDamageMult * 100.0 : 0; while (deform && iteration < MAX_DEFORM_ITERATIONS) { deform = false; deformationPoints.forEach(def => { const damageVector = vehicle.getDeformationAtPos(def.offset.x, def.offset.y, def.offset.z); const dmg = Math.sqrt(damageVector.x ** 2 + damageVector.y ** 2 + damageVector.z ** 2); if (dmg < def.dmg) { vehicle.setDamage(def.offset.x, def.offset.y, def.offset.z, def.dmg * damageMult, 1000.0, true); deform = true; } }); iteration++; } } function isDeformationWorse(newDef, oldDef) { if (!oldDef || newDef.length > oldDef.length) { return true; } else if (newDef.length < oldDef.length) { return false; } for (let i = 0; i < newDef.length; i++) { let found = false; for (let j = 0; j < oldDef.length; j++) { if (newDef[i].offset.x === oldDef[j].offset.x && newDef[i].offset.y === oldDef[j].offset.y && newDef[i].offset.z === oldDef[j].offset.z) { found = true; if (newDef[i].dmg > oldDef[j].dmg) { return true; } } } if (!found) { return true; } } return false; } function isDeformationEqual(newDef, oldDef) { if (oldDef == null && newDef == null) return true; if (oldDef == null || newDef == null || newDef.length !== oldDef.length) return false; for (let i = 0; i < newDef.length; i++) { if (newDef[i].dmg !== oldDef[i].dmg) { return false; } } return true; } function handleDeformationUpdate(vehicle) { if (!mp.vehicles.exists(vehicle)) return; const deformation = getVehicleDeformation(vehicle); const currentDeformation = JSON.parse(vehicle.getVariable('deformation') || '[]'); if (!isDeformationEqual(deformation, currentDeformation) && isDeformationWorse(deformation, currentDeformation)) { mp.events.callRemote('storeVehicleDeformationState', vehicle.remoteId, JSON.stringify(deformation)); } } mp.events.add('playerLeaveVehicle', vehicle => { handleDeformationUpdate(vehicle); }); mp.events.add('playerEnterVehicle', (vehicle, seat) => { setTimeout(() => { if (seat === -1) { const deformation = vehicle.getVariable('deformation'); if (deformation) { applyDeformation(vehicle, JSON.parse(deformation)); } } }, 200); }); mp.events.add('entityStreamIn', entity => { if (entity.type === 'vehicle') { setTimeout(() => { const deformation = entity.getVariable('deformation'); if (deformation) { applyDeformation(entity, JSON.parse(deformation)); } }, 2000); } });
Server Side :
Код:mp.events.add('storeVehicleDeformationState', (player, vehicleId, deformation) => { const vehicle = mp.vehicles.at(vehicleId); if (vehicle && mp.vehicles.exists(vehicle)) { vehicle.setVariable('deformation', deformation); } }); mp.events.add("VD:fixDeformation", (player, vehicleId) => { const vehicle = mp.vehicles.at(vehicleId); if (vehicle && mp.vehicles.exists(vehicle)) { vehicle.setVariable('deformation', null); } }); mp.events.add('fixVehicleDeformation', (player, vehicleId) => { const vehicle = mp.vehicles.at(vehicleId); if (vehicle && mp.vehicles.exists(vehicle)) { vehicle.setFixed(); vehicle.setVariable('deformation', null); } });
Пока что натив царапин не нашёл, ты их знаешь ?лайк чату жпт Царапины это скорее всего декалии, их тоже по идее можно синхронизировать