Skip to content

fix(es_extended/server/modules/onesync): decouple player proximity from veh spawning#1666

Merged
FBFezz merged 7 commits into
esx-framework:devfrom
Kenshiin13:fix-veh-spawn-dim
Jul 13, 2025
Merged

fix(es_extended/server/modules/onesync): decouple player proximity from veh spawning#1666
FBFezz merged 7 commits into
esx-framework:devfrom
Kenshiin13:fix-veh-spawn-dim

Conversation

@Kenshiin13

@Kenshiin13 Kenshiin13 commented Jul 6, 2025

Copy link
Copy Markdown
Contributor

Description

This PR refactors ESX.OneSync.SpawnVehicle to decouple vehicle spawning from the presence or proximity of any specific player, and introduces a new optional routingBucket parameter to ESX.OneSync.GetClosestPlayer.

Previously, we attempted to get the vehicle type from the closest player and then waited for that player to become the network owner (regardless of what dimension they are in). This caused issues when spawning vehicles in other dimensions, specifically when the player was not in dimension 0—blocking vehicle creation indefinitely. Since we spawn vehicles in dimension 0, getting a closest player that is not in that dimension will make it impossible for them to become the net owner of that vehicle and so the spawning will fail.

Now, the logic is much more robust:

  • If a vehicleType is not provided, the server falls back to the first available player (if any) to determine it. Regardless of dimension or distance.
  • If no players are online and no vehicleType is provided, spawning fails early with a clear error.
  • Otherwise, vehicle creation proceeds without awaiting a network owner. If a player is nearby in dimension 0, ownership is handled normally. If not, the vehicle still spawns and the caller can set the vehicle into the correct dimension.
  • Vehicle properties will still be applied once a player enters scope.

Motivation

Issue #1646

This change resolves a long-standing issue where /car and similar commands would fail in non-zero dimensions. By removing the requirement for a dimension 0 player and falling back to any player for type detection, vehicle spawning becomes reliable and dimension-agnostic.

Additionally:

  • The vehicle spawn logic was far too limiting. To determine a vehicle type, a player doesn't need to be in scope of the vehicle, yet the old logic enforced that constraint without justification.
  • The only case where awaiting a network owner makes sense is to apply vehicle properties immediately. Now, if no one is nearby, we skip waiting—properties will be synced automatically as soon as a player enters scope.

Implementation Details

  • Refactored SpawnVehicle to no longer rely on a closest player being in a specific dimension.
  • Fallback to the first available player only if vehicleType is not explicitly provided.
  • Added early rejection with a clear error if no players are online and no vehicleType is provided.
  • Skipped awaiting a net owner if none is nearby, improving responsiveness.
  • Added optional routingBucket filter to ESX.OneSync.GetClosestPlayer to support scoped searches.
  • Ensured that even when no one is in scope, vehicle spawning and eventual property syncing still work reliably.

PR Checklist

  • My commit messages and PR title follow the Conventional Commits standard.
  • My changes have been tested locally and function as expected.
  • My PR does not introduce any breaking changes.
  • I have provided a clear explanation of what my PR does, including the reasoning behind the changes and any relevant context.

Simplified the logic for determining vehicleType by selecting the first available player instead of iterating through all players. I will fix ESX.GetExtendedPlayers to filter out stale player objects.
@rodrigofplourenco rodrigofplourenco self-assigned this Jul 12, 2025

@rodrigofplourenco rodrigofplourenco left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this locally using a custom dev resource to simulate various scenarios.

Everything behaves as expected:

  • Vehicle spawning no longer depends on players being in dimension 0
  • Fallback to first available player works when no vehicleType is passed
  • Spawning in custom routingBuckets works without ownership issues
  • Vehicles spawn even if no one is nearby; properties sync correctly once someone enters scope
  • Proper early rejection when no players are online and no vehicleType is provided
  • Manual override of vehicleType also works as expected (automobile, etc.)

Reviewed the commit history and logic changes: all consistent with the PR goal. No regressions or unexpected behavior found so far.

The only thing left to confirm is routingBucket fallback behavior with multiple players. I wasn’t able to test that part alone, so we should get at least one more person to validate it in a multiplayer setup before merging.

Otherwise, this looks solid.

@FBFezz FBFezz self-requested a review July 13, 2025 10:53

@FBFezz FBFezz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@github-project-automation github-project-automation Bot moved this from 🆕 To be Discussed to Ready for Next Update in ESX Roadmap Jul 13, 2025
@FBFezz FBFezz merged commit b623c38 into esx-framework:dev Jul 13, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready for Next Update

Development

Successfully merging this pull request may close these issues.

4 participants