From e224efd4499453b5cda42eed06520ebf0cf5ca2f Mon Sep 17 00:00:00 2001 From: stuyk Date: Thu, 13 Jun 2024 12:50:12 -0600 Subject: [PATCH] feat: delay model update for global objects --- src/main/server/controllers/object.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/server/controllers/object.ts b/src/main/server/controllers/object.ts index 7f8aa63cc..d6fc8aa2c 100644 --- a/src/main/server/controllers/object.ts +++ b/src/main/server/controllers/object.ts @@ -37,15 +37,24 @@ export function useObjectGlobal(objectData: iObject) { } } - function updateModel(model: number) { + async function updateModel(model: number) { + objectData.model = model; + const newObjectInstance = new alt.Object( + objectData.model, + objectData.pos, + objectData.rot ?? alt.Vector3.zero, + 255, + ); + newObjectInstance.dimension = objectData.dimension ?? 0; + newObjectInstance.setStreamSyncedMeta('data', objectData.data); + + await alt.Utils.wait(1000); + try { newObject.destroy(); } catch (err) {} - objectData.model = model; - newObject = new alt.Object(objectData.model, objectData.pos, objectData.rot ?? alt.Vector3.zero, 255); - newObject.dimension = objectData.dimension ?? 0; - newObject.setStreamSyncedMeta('data', objectData.data); + newObject = newObjectInstance; } function updatePosition(pos: alt.Vector3) {