Skip to content

Commit

Permalink
feat(server/vehicle): use SetEntityOrphanMode when spawning vehicles
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat committed Oct 3, 2024
1 parent 0bd4d6c commit a7aae87
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion server/vehicle/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { GetVehicleData, GetVehicleNetworkType } from '../../common/vehicles';
import { setVehicleProperties } from '@overextended/ox_lib/server';
import { Vector3 } from '@nativewrappers/fivem';

const setEntityOrphanMode = typeof SetEntityOrphanMode !== 'undefined' ? SetEntityOrphanMode : () => {};

export class OxVehicle extends ClassInterface {
entity: number;
netId: number;
Expand All @@ -29,7 +31,18 @@ export class OxVehicle extends ClassInterface {
};

static spawn(model: string, coords: Vector3, heading?: number) {
return CreateVehicleServerSetter(model, GetVehicleNetworkType(model), coords.x, coords.y, coords.z, heading || 0);
const entityId = CreateVehicleServerSetter(
model,
GetVehicleNetworkType(model),
coords.x,
coords.y,
coords.z,
heading || 0
);

setEntityOrphanMode(entityId, 2);

return entityId;
}

/** Get an instance of OxVehicle with the matching entityId. */
Expand Down

0 comments on commit a7aae87

Please sign in to comment.