Skip to content

Commit

Permalink
feat: updateModel, updatePosition for global objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuyk committed Jun 13, 2024
1 parent eaa3bba commit 3c505a0
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/main/server/controllers/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function useObjectGlobal(objectData: iObject) {
objectData.uid = Utility.uid.generate();
}

const newObject = new alt.Object(objectData.model, objectData.pos, objectData.rot ?? alt.Vector3.zero, 255);
let newObject = new alt.Object(objectData.model, objectData.pos, objectData.rot ?? alt.Vector3.zero, 255);
newObject.dimension = objectData.dimension ?? 0;
newObject.setStreamSyncedMeta('data', objectData.data);

Expand All @@ -37,6 +37,21 @@ export function useObjectGlobal(objectData: iObject) {
}
}

function updateModel(model: number) {
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);
}

function updatePosition(pos: alt.Vector3) {
newObject.pos = pos;
}

return {
destroy,
getData() {
Expand All @@ -46,6 +61,8 @@ export function useObjectGlobal(objectData: iObject) {
return newObject;
},
update,
updateModel,
updatePosition,
};
}

Expand Down

0 comments on commit 3c505a0

Please sign in to comment.