From 43d14ec547bd87215e9a4fc6d0e4457da228a5c6 Mon Sep 17 00:00:00 2001 From: David J Date: Fri, 11 Oct 2024 23:42:42 +0200 Subject: [PATCH] refactor: Update player and vehicle getters to use alt.Utils for consistent entity retrieval - Results are consistently sorted by distance to improve reliability --- src/main/server/getters/player.ts | 10 +++++----- src/main/server/getters/vehicle.ts | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/server/getters/player.ts b/src/main/server/getters/player.ts index e8b63e132..7b4ef295e 100644 --- a/src/main/server/getters/player.ts +++ b/src/main/server/getters/player.ts @@ -9,7 +9,7 @@ export function usePlayerGetter() { * * #### Example * ```ts - * const player = Athena.getters.player.byAccount('123456789'); + * const player = Rebar.get.usePlayerGetter().byAccount('123456789'); * if (player) { * console.log(`Found player ${player.id} with account ID ${player.account._id}`); * } else { @@ -171,8 +171,8 @@ export function usePlayerGetter() { * @return {(alt.Player | undefined)} */ function closestToPlayer(player: alt.Player, range = 10): alt.Player | undefined { - const results = alt.getClosestEntities(player.pos, range, player.dimension, -1, 1) as alt.Player[]; - return results.length >= 1 ? results[0] : undefined; + const results = alt.Utils.getClosestPlayer({ pos: player.pos, range }) as alt.Player; + return results ? results : undefined; } /** @@ -182,8 +182,8 @@ export function usePlayerGetter() { * @return {(alt.Player | undefined)} */ function closestToVehicle(vehicle: alt.Vehicle, range = 25): alt.Player | undefined { - const results = alt.getClosestEntities(vehicle.pos, range, vehicle.dimension, -1, 1) as alt.Player[]; - return results.length >= 1 ? results[0] : undefined; + const results = alt.Utils.getClosestPlayer({ pos: vehicle.pos, range }) as alt.Player; + return results ? results : undefined; } /** diff --git a/src/main/server/getters/vehicle.ts b/src/main/server/getters/vehicle.ts index ae99078e1..a8f12ca0e 100644 --- a/src/main/server/getters/vehicle.ts +++ b/src/main/server/getters/vehicle.ts @@ -124,8 +124,8 @@ export function useVehicleGetter() { * @return {(alt.Vehicle | undefined)} */ function closestVehicle(player: alt.Player, range = 25): alt.Vehicle | undefined { - const results = alt.getClosestEntities(player.pos, range, player.dimension, -1, 2) as alt.Vehicle[]; - return results.length >= 1 ? results[0] : undefined; + const results = alt.Utils.getClosestVehicle({ pos: player.pos, range }) as alt.Vehicle; + return results ? results : undefined; } return {