Skip to content
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

feature(server/vehicle) Add support for getting OxVehicle even when vehicle not tracked #213

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Alexr03
Copy link
Contributor

@Alexr03 Alexr03 commented Nov 14, 2024

#212

This PR introduces some changes regarding OxVehicle and how we can get an instance of it.
As of right now to get an instance of OxVehicle the vehicle must be spawned in by either using:

  • Ox.CreateVehicle
  • Ox.SpawnVehicle

Or by getting an instance of it after being spawned by using the Ox.GetVehicle* functions.

However there are instances where we to create a vehicle entry and get the OxVehicle from it, E.G. a car shop showing a notification of the plate that was assigned to your new vehicle after purchase, but you don't want to spawn it immediately, this is current not possible as if you do not spawn it when creating the entry you will not get an instance of OxVehicle.

Theres also instances where we'd want to get an instance of OxVehicle by using its vin, this is so we can call functions such as setOwner etc for when a vehicle transfer happens. But this is only possible if the vehicle is being tracked by ox_core. Sure we could run an update query manually, but if we can do everything with classes, why not let ox_core handle it.

This change will allow OxVehicle class to be created without the need of an Entity by making it an nullable field and an internal ID taking its place for the member lookups.

This will add support for being able to use Ox.GetVehicleFromVin which will first get the vehicle if its already being tracked, otherwise it will query the database for the vehicle and create & cache the OxVehicle created from it.

Changes:

  • [Fix] /dv command not using 2 as default radius when not in vehicle.
  • [Fix] Ox.CreateVehicle Not creating an entry in the DB when coords are not provided.
  • [Fix] Ox.CreateVehicle Not returning an instance of OxVehicle when coords not provided.
  • [Fix] vehicle.respawn Not working providing coords & rotation.
  • [Change] Use internalId for OxVehicle tracking
  • [Change] OxVehicle.entity is now nullable and not required.
  • [Change] Add stored to the output of VehicleRow

If this PR is okay to be merged in I will work on updating the docs to reflect the changes.

@thelindat
Copy link
Member

Just fyi, it's preferable to keep unrelated changes separated into different PRs, especially since I squash them when merging.

Rather than another "internalId" field, why not use a semi-random string as the "id" ("temp_........")? We could also just track vehicles by plate, and use entityCreating/entityCreated event to change vehicle plates for collisions.

@Alexr03
Copy link
Contributor Author

Alexr03 commented Nov 24, 2024

Just fyi, it's preferable to keep unrelated changes separated into different PRs, especially since I squash them when merging.

Understood o7


I used an internalId as the tracking id, as the id currently is the the database id for the vehicle. Its probably best to keep this as it is rather than changing its type?

For tracking by plate, what do you mean by

use entityCreating/entityCreated event to change vehicle plates for collisions.

Is this for something like, a vehicle is already spawned in and tracked by ox_core, then another vehicle is spawned by another script, we pick that up by the entityCreated event and if its a plate thats already been tracked, just change the plate and track that instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants