-
-
Notifications
You must be signed in to change notification settings - Fork 750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(es_extended/server/classes/vehicle): add vehicle class #1555
Merged
Conversation
This file contains 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
feat(es_extended): add promise support for vehicle spawn functions
…omPlate logic into vehicle class
…icle-spawning fix(es_extended/server/onesync): better vehicle spawning method
It takes a while until the vehicle plate is actually set. To combat this, we will store the plate in the entity statebag instead.
… reflecting changes in veh obj
…ate plate validation to vehicle class
…age/impound on delete
…cleData where appropriate Avoids confusion.
Closed
Mycroft-Studios
approved these changes
Dec 29, 2024
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 introduces a robust vehicle class to the ESX framework, offering developers a standardized way to manage owned vehicle entities in FiveM.
Motivation
The primary motivation for this addition is to address the challenges of managing owned vehicles reliably in a multiplayer environment. Specifically, this class enables developers to:
Determine if an owned vehicle is spawned or not: With this class, it's straightforward to check whether a specific vehicle is currently active in the world or has been despawned.
Ensure vehicle validity: By leveraging entity statebags, the system ensures that each tracked vehicle is indeed the one that was created, avoiding issues caused by network ID reassignment (a common occurrence when entities are deleted and new ones are created).
Implementation Details
Entity Statebags
Each vehicle is assigned the owner's identifier and plate in its statebag at the time of creation. This ensures that, regardless of entity lifecycle events, the vehicle can still be uniquely and reliably identified. The plate stored in the statebag acts as an additional tool for validation, as it is a crucial identifier for vehicles. Using the statebag for the plate, instead of relying on fetching the vehicle plate through natives, avoids potential race conditions. Native RPCs take time to propagate changes to the entity, so if a script were to perform an operation on a vehicle class object immediately after creation, there could be a mismatch between the plate the class expects and the plate set on the entity in the game. This mismatch could cause the class to invalidate the entity incorrectly. Storing the plate in the statebag ensures consistency and immediate access to the correct data.
Automatic Validation
The
isValid
function plays a critical role in maintaining the integrity of the vehicle object. It checks the existence and validity of the associated entity in the world. The class automatically invokesisValid
on every action (e.g., getting the netId, setting the vehicle properties, or getting the entity handle). This guarantees that actions are always performed on up-to-date and valid entities.Usage Example
PR Checklist