Skip to content

Commit

Permalink
Merge pull request #172 from d2kk/main
Browse files Browse the repository at this point in the history
refactor: Update player and vehicle getters to use alt.Utils for consistent entity retrieval
  • Loading branch information
Booster1212 authored Oct 14, 2024
2 parents 59d5e75 + 43d14ec commit e1ed42a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/main/server/getters/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/server/getters/vehicle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e1ed42a

Please sign in to comment.