Skip to content

Commit

Permalink
19 (#39)
Browse files Browse the repository at this point in the history
* feat: useProxy, useRaycast, useVehicle Additions, bug fixes

* feat: usePed

* docs: changelog

* feat: vehicleHashMap, neon sync
  • Loading branch information
Stuyk authored Jun 8, 2024
1 parent bdde2d4 commit 301c07a
Show file tree
Hide file tree
Showing 6 changed files with 914 additions and 1 deletion.
15 changes: 15 additions & 0 deletions docs/api/shared/utility.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,18 @@ const distLong = Utility.vector.distance(new alt.Vector3(0, 0, 0), new alt.Vecto
// Returns a position in front of a given player, vehicle, etc.
const posInFrontOf = Utility.vector.getVectorInFrontOfPlayer(somePlayerOrVehicle, 5);
```

### Vehicle Hash Map

When you need vehicle names from hash values or need a large list of vehicles. This is it.

```ts
// will return 'infernus'
const model = Utility.vehicleHashes.getNameFromHash(418536135);

// Adding vehicles like this needs to be done from webview, server, and shared to be accurate
Utility.vehicleHashes.addVehicle('infernus');

// Returns a string array of vehicle model names
const vehicleModels = Utility.vehicleHashes.getVehicles();
```
14 changes: 14 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ order: -5

# Changelog

## Version 19

### Code Changes

- Added reverse map for vehicle model hash to vehicle model name
- Added function to add named models to list at runtime as well
- Added neon synchronization to vehicle document sync

### Docs Changes

- Added vehicleHashes utility doc info

---

## Version 18

### Code Changes
Expand Down
20 changes: 20 additions & 0 deletions src/main/server/vehicle/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as alt from 'alt-server';
import { useRebar } from '../index.js';
import { Vehicle, WheelState } from '../../shared/types/vehicle.js';
import * as Utility from '@Shared/utility/index.js';

const Rebar = useRebar();
const db = Rebar.database.useDatabase();
Expand Down Expand Up @@ -54,6 +55,15 @@ export function useVehicle(vehicle: alt.Vehicle) {
}
}

// Synchronize neon
if (document.neonPlacement && document.neonColor) {
for (let key of Object.keys(document.neonPlacement)) {
vehicle.neon[key] = document.neonPlacement[key];
}

vehicle.neonColor = document.neonColor;
}

// Synchronize vehicle extras
if (document.extras) {
for (let key of Object.keys(document.extras)) {
Expand Down Expand Up @@ -450,10 +460,20 @@ export function useVehicle(vehicle: alt.Vehicle) {
apply(data);
}

/**
* Get the model name of the vehicle
*
* @return
*/
function getVehicleModelName() {
return Utility.vehicleHashes.getNameFromHash(vehicle.model);
}

return {
apply,
bind,
create,
getVehicleModelName,
hasOwner,
isBound,
keys: {
Expand Down
26 changes: 26 additions & 0 deletions src/main/shared/types/vehicle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,32 @@ export interface Vehicle {
*/
windows?: { [key: string]: number };

/**
* Neon color for the vehicle
*
* @type {alt.RGBA}
* @memberof Vehicle
*/
neonColor?: alt.RGBA;

/**
* Where the placement of the neon is
*
* @type {{
* front: boolean,
* back: boolean,
* left: boolean,
* right: boolean
* }}
* @memberof Vehicle
*/
neonPlacement?: {
front: boolean;
back: boolean;
left: boolean;
right: boolean;
};

stateProps?: {
/**
* Dirt level of the vehicle
Expand Down
3 changes: 2 additions & 1 deletion src/main/shared/utility/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export * as flag from './flags.js';
export * as math from './math.js';
export * as random from './random.js';
export * as time from './time.js';
export * as vector from './vector.js';
export * as uid from './uid.js';
export * as vector from './vector.js';
export * as vehicleHashes from './vehicleHashes.js';
Loading

0 comments on commit 301c07a

Please sign in to comment.