Skip to content

Commit

Permalink
feat(client/vehicle): setup statebag handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat committed Feb 18, 2024
1 parent 4b1fb67 commit 9053297
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
33 changes: 32 additions & 1 deletion client/vehicle/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cache, onServerCallback } from '@overextended/ox_lib/client';
import { cache, onServerCallback, setVehicleProperties, waitFor } from '@overextended/ox_lib/client';
import { DEBUG } from '../config';

if (DEBUG) import('./parser');
Expand All @@ -20,3 +20,34 @@ onServerCallback('ox:getNearbyVehicles', (radius: number) => {

return nearbyEntities;
});

AddStateBagChangeHandler('initVehicle', '', async (bagName: string, key: string, value: any) => {
if (!value) return;

const entity = GetEntityFromStateBagName(bagName);

for (let index = -1; 0; index++) {
const ped = GetPedInVehicleSeat(entity, index);

if (ped && ped !== cache.ped && NetworkGetEntityOwner(ped) === cache.playerId) DeleteEntity(ped);
}

await waitFor(async () => {
if (!IsEntityWaitingForWorldCollision(entity)) return true;
});

if (NetworkGetEntityOwner(entity) !== cache.playerId) return;

SetVehicleOnGroundProperly(entity);

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

AddStateBagChangeHandler('vehicleProperties', '', async (bagName: string, key: string, value: any) => {
const entity = GetEntityFromStateBagName(bagName);

if (NetworkGetEntityOwner(entity) !== cache.playerId) return;

setVehicleProperties(entity, value);
setTimeout(() => Entity(entity).state.set(key, null, true));
});
2 changes: 1 addition & 1 deletion common/locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import { locale, FlattenObjectKeys } from '@overextended/ox_lib';

type Locales = FlattenObjectKeys<typeof import('../locales/en.json')>;

export default <T extends Locales>(str: T, ...args: any[]) => locale(str, ...args);
export default <T extends Locales>(str: T, ...args: any[]) => locale(str, ...args) as string;

0 comments on commit 9053297

Please sign in to comment.