fix(es_extended/server/modules/onesync): decouple player proximity from veh spawning#1666
Merged
Conversation
…awn based on routing bucket
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
left a comment
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR refactors
ESX.OneSync.SpawnVehicleto decouple vehicle spawning from the presence or proximity of any specific player, and introduces a new optionalroutingBucketparameter toESX.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:
vehicleTypeis not provided, the server falls back to the first available player (if any) to determine it. Regardless of dimension or distance.vehicleTypeis provided, spawning fails early with a clear error.Motivation
Issue #1646
This change resolves a long-standing issue where
/carand 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:
Implementation Details
SpawnVehicleto no longer rely on a closest player being in a specific dimension.vehicleTypeis not explicitly provided.vehicleTypeis provided.routingBucketfilter toESX.OneSync.GetClosestPlayerto support scoped searches.PR Checklist