#
Vehicle
An character document is a set of data that is bound to the player until they disconnect.
It automatically saves data to the MongoDB database when any set function is used.
#
Binding Data
You should bind character data after fetching call characters owned by an account.
When you bind vehicle data to a vehicle the following is synchronized:
- Position
- Rotation
- Model
- Mods
- Health
- Windows
- Wheels
- Extras
- Dimension
import { useRebar } from '@Server/index.js';
const Rebar = useRebar();
// ... some function
// Use database functions to fetch or create a vehicle
const someVehicleData = someDatabaseFetchOrCreateFunction();
// Bind vehicle data to the player after fetching
const document = Rebar.document.vehicle.useVehicleBinder(someVehicle).bind(someVehicleData);
#
Checking Validity
If you need to check if a vehicle has a document bound to them, you can use the following method.
if (!Rebar.document.vehicle.useVehicle(player).isValid()) {
// No vehicle document bound
return;
}
#
Getting Data
Data can be retrieved for the bound character like this.
import { useRebar } from '@Server/index.js';
const Rebar = useRebar();
//... some function
const document = Rebar.document.vehicle.useVehicle(player);
const data = document.get();
console.log(data.email);
#
Setting Data
Data can easily be appended or set in two different ways.
import { useRebar } from '@Server/index.js';
const Rebar = useRebar();
const document = Rebar.document.vehicle.useVehicle(player);
type CustomVehicle = { whatever: string };
//...some function
// Single field
document.set('banned', true);
// Multi-field
document.setBulk({ name: 'John_Doe' });
// Custom-field
document.setBulk<CustomVehicle>({ whatever: 'hi' });