From 3a46104dbf4e36ebd2168c3d7fba00ee0b620129 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Fri, 12 Jul 2024 23:27:52 +1000 Subject: [PATCH] refactor(client/vehicle): adjust vehicle properties setter Remove some pointless debug code and adjust the timeout. --- client/vehicle/index.ts | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/client/vehicle/index.ts b/client/vehicle/index.ts index b650c6b4..5cd3c35f 100644 --- a/client/vehicle/index.ts +++ b/client/vehicle/index.ts @@ -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}`); @@ -75,8 +58,7 @@ 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; @@ -84,8 +66,8 @@ AddStateBagChangeHandler('vehicleProperties', '', async (bagName: string, key: s 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); } @@ -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); });