Skip to content

Commit

Permalink
refactor(client/vehicle): adjust vehicle properties setter
Browse files Browse the repository at this point in the history
Remove some pointless debug code and adjust the timeout.
  • Loading branch information
thelindat committed Jul 12, 2024
1 parent 577f35f commit 3a46104
Showing 1 changed file with 3 additions and 26 deletions.
29 changes: 3 additions & 26 deletions client/vehicle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,6 @@ AddStateBagChangeHandler('initVehicle', '', async (bagName: string, key: string,
setTimeout(() => Entity(entity).state.set(key, null, true));
});

function doesfivemworkyet(obj1: any, obj2: any) {
for (let key in obj1) {
if (obj1.hasOwnProperty(key)) {
if (typeof obj1[key] === 'object' && obj1[key] !== null) {
if (!doesfivemworkyet(obj1[key], obj2[key])) {
return false;
}
} else {
if (obj2[key] !== obj1[key]) {
return false;
}
}
}
}
return true;
}

AddStateBagChangeHandler('vehicleProperties', '', async (bagName: string, key: string, value: any) => {
if (!value) return DEBUG && console.info(`removed ${key} state from ${bagName}`);

Expand All @@ -75,17 +58,16 @@ AddStateBagChangeHandler('vehicleProperties', '', async (bagName: string, key: s

if (!entity) return;

// properties and serverside vehicles are one of the most retarded features of fivem
// let's set this dumb bullshit in an interval and see if they actually bother setting
// properties sometimes fail to set for whatever reason, so here's a dumb workaround.
const resolved = await new Promise((resolve) => {
let i = 0;
let interval: CitizenTimer;

interval = setInterval(() => {
i++;

if (i > 10 || !DoesEntityExist(entity)) {
resolve(i > 10 ? 1 : 0);
if (i > 5 || !DoesEntityExist(entity)) {
resolve(i > 5 ? 1 : 0);
return clearInterval(interval);
}

Expand All @@ -95,10 +77,5 @@ AddStateBagChangeHandler('vehicleProperties', '', async (bagName: string, key: s

if (!resolved) return;

const properties = getVehicleProperties(entity);

if (!doesfivemworkyet(value, properties))
console.error(`vehicle properties probably didn't fully set properly. thanks fivem.`);

Entity(entity).state.set(key, null, true);
});

0 comments on commit 3a46104

Please sign in to comment.