Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:Stuyk/altv-athena
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuyk committed Apr 8, 2023
2 parents 37fd189 + 6beb5a6 commit b149a44
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { LocaleController } from '@AthenaShared/locale/locale';
import { VehicleState } from '@AthenaShared/interfaces/vehicleState';
import IVehicleTuning from '@AthenaShared/interfaces/vehicleTuning';
import IVehicleMod from '@AthenaShared/interfaces/vehicleMod';
import VehicleExtra from '@AthenaShared/interfaces/vehicleExtra';

Athena.systems.messenger.commands.register(
'tempvehicle',
Expand Down Expand Up @@ -289,6 +290,82 @@ Athena.systems.messenger.commands.register(
},
);

Athena.systems.messenger.commands.register(
'activateExtra',
'/activateExtra [id]',
['admin'],
(player: alt.Player, id: string) => {
const vehicle = player.vehicle ? player.vehicle : Athena.utility.closest.getClosestVehicle(player.pos);

if (!vehicle) {
Athena.player.emit.message(player, 'No spawned vehicle.');
return;
}

if (Athena.utility.vector.distance(player.pos, vehicle.pos) > 4 && !player.vehicle) {
Athena.player.emit.message(player, 'No vehicle in range.');
return;
}

if (isNaN(parseInt(id))) {
Athena.player.emit.message(player, `Dirt level passed was not a number.`);
return;
}

Athena.vehicle.tuning.setExtra(vehicle, [{ id: parseInt(id), state: true }]);
Athena.vehicle.controls.updateLastUsed(vehicle);
Athena.vehicle.controls.update(vehicle);

const extraData: Array<VehicleExtra> = Athena.vehicle.tuning.getExtras(vehicle);

Athena.document.vehicle.set(vehicle, 'extras', extraData);

const hash = typeof vehicle.model === 'number' ? vehicle.model : alt.hash(vehicle.model);

let vehInfo = Athena.utility.hashLookup.vehicle.hash(hash);

Athena.player.emit.message(player, `Extra ${id} of ${vehInfo.displayName} was activated.`);
},
);

Athena.systems.messenger.commands.register(
'deactivateExtra',
'/deactivateExtra [id]',
['admin'],
(player: alt.Player, id: string) => {
const vehicle = player.vehicle ? player.vehicle : Athena.utility.closest.getClosestVehicle(player.pos);

if (!vehicle) {
Athena.player.emit.message(player, 'No spawned vehicle.');
return;
}

if (Athena.utility.vector.distance(player.pos, vehicle.pos) > 4 && !player.vehicle) {
Athena.player.emit.message(player, 'No vehicle in range.');
return;
}

if (isNaN(parseInt(id))) {
Athena.player.emit.message(player, `Dirt level passed was not a number.`);
return;
}

Athena.vehicle.tuning.setExtra(vehicle, [{ id: parseInt(id), state: false }]);
Athena.vehicle.controls.updateLastUsed(vehicle);
Athena.vehicle.controls.update(vehicle);

const extraData: Array<VehicleExtra> = Athena.vehicle.tuning.getExtras(vehicle);

Athena.document.vehicle.set(vehicle, 'extras', extraData);

const hash = typeof vehicle.model === 'number' ? vehicle.model : alt.hash(vehicle.model);

let vehInfo = Athena.utility.hashLookup.vehicle.hash(hash);

Athena.player.emit.message(player, `Extra ${id} of ${vehInfo.displayName} was deactivated.`);
},
);

// import { command } from '@AthenaServer/decorators/commands';
// import { PERMISSIONS } from '@AthenaShared/flags/permissionFlags';
// import { LOCALE_KEYS } from '@AthenaShared/locale/languages/keys';
Expand Down
8 changes: 4 additions & 4 deletions src/core/server/controllers/staticPed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,21 @@ export function addToPlayer(player: alt.Player, pedData: IPed): string {
*
* #### Example
* ```ts
* Athena.controllers.staticPed.playAnimation('the-id-you-specified', playAnimation('test', [
* Athena.controllers.staticPed.playAnimation('the-id-you-specified', playAnimation('test',
* {
* dict: 'mp_ped_interaction',
* name: 'hugs_guy_a',
* duration: 2000,
* flags: 0,
* },
* ]);
* );
* ```
*
*
* @param {string} uid A unique string
* @param {Animation[]} animation
* @param {Animation} animation
*/
export function playAnimation(uid: string, animation: Animation[]) {
export function playAnimation(uid: string, animation: Animation) {
alt.emitAllClients(SYSTEM_EVENTS.PLAY_ANIMATION_FOR_PED, uid, animation);
}

Expand Down
4 changes: 4 additions & 0 deletions src/core/server/vehicle/spawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ export function persistent(document: OwnedVehicle): alt.Vehicle | undefined {
Athena.vehicle.tuning.applyTuning(vehicle, document.tuning);
}

if (document.extras) {
Athena.vehicle.tuning.setExtra(vehicle, document.extras);
}

if (document.damage) {
Athena.vehicle.damage.apply(vehicle, document.damage);
}
Expand Down
47 changes: 46 additions & 1 deletion src/core/server/vehicle/tuning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as Athena from '@AthenaServer/api';

import VehicleTuning from '@AthenaShared/interfaces/vehicleTuning';
import { VehicleState } from '@AthenaShared/interfaces/vehicleState';
import VehicleExtra from '@AthenaShared/interfaces/vehicleExtra';
import IVehicleMod from '@AthenaShared/interfaces/vehicleMod';

/**
Expand All @@ -23,6 +24,46 @@ export function applyState(vehicle: alt.Vehicle, state: Partial<VehicleState> |
});
}

/**
* Get all mods of the specified vehicle.
*
*
* @param {alt.Vehicle} vehicle An alt:V Vehicle Entity
* @return {Array<VehicleExtra>}
*/
export function getExtras(vehicle: alt.Vehicle): Array<VehicleExtra> {
if (Overrides.getExtras) {
return Overrides.getExtras(vehicle);
}

let extraData: Array<VehicleExtra> = [];

for (let id = 0; id < 15; ++id) {
let state: boolean = !vehicle.getExtra(id);
extraData.push({ id, state });
}

return extraData;
}

/**
* Applies specified properties to a vehicle in bulk.
* These match the alt:V API, and can be pulled from a database.
*
*
* @param {alt.Vehicle} vehicle An alt:V Vehicle Entity
* @param {Array<VehicleExtra>} extras
*/
export function setExtra(vehicle: alt.Vehicle, extras: Array<VehicleExtra>) {
if (Overrides.setExtra) {
return Overrides.setExtra(vehicle, extras);
}

for (let extra of extras) {
vehicle.setExtra(extra.id, extra.state);
}
}

/**
* Apply tuning to the specified vehicle.
*
Expand Down Expand Up @@ -55,7 +96,7 @@ export function applyTuning(vehicle: alt.Vehicle, tuning: VehicleTuning | Partia
*
*
* @param {alt.Vehicle} vehicle An alt:V Vehicle Entity
* @param {VehicleTuning } tuning
* @returns {VehicleTuning}
*/
export function getTuning(vehicle: alt.Vehicle): VehicleTuning {
if (Overrides.getTuning) {
Expand Down Expand Up @@ -135,6 +176,8 @@ export function getMods(vehicle: alt.Vehicle): Array<IVehicleMod> {

interface VehicleTuningFuncs {
applyState: typeof applyState;
setExtra: typeof setExtra;
getExtras: typeof getExtras;
applyTuning: typeof applyTuning;
getTuning: typeof getTuning;
applyMods: typeof applyMods;
Expand All @@ -144,6 +187,8 @@ interface VehicleTuningFuncs {
const Overrides: Partial<VehicleTuningFuncs> = {};

export function override(functionName: 'applyState', callback: typeof applyState);
export function override(functionName: 'setExtra', callback: typeof setExtra);
export function override(functionName: 'getExtras', callback: typeof getExtras);
export function override(functionName: 'applyTuning', callback: typeof applyTuning);
export function override(functionName: 'getTuning', callback: typeof getTuning);
export function override(functionName: 'applyMods', callback: typeof applyMods);
Expand Down
10 changes: 10 additions & 0 deletions src/core/shared/interfaces/vehicleExtra.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Used to describe a vehicle extra, and the state it should have.
*
*
* @interface VehicleExtra
*/
export default interface VehicleExtra {
id: number;
state: boolean;
}
9 changes: 9 additions & 0 deletions src/core/shared/interfaces/vehicleOwned.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BaseVehicle } from './vehicleBase';
import VehicleExtra from './vehicleExtra';
import { VehicleState } from './vehicleState';
import VehicleTuning from './vehicleTuning';

Expand Down Expand Up @@ -85,4 +86,12 @@ export interface OwnedVehicle extends BaseVehicle {
*
*/
damage?: VehicleDamage;

/**
* Damage to store / apply on a vehicle
*
* @type {VehicleDamage}
*
*/
extras?: Array<VehicleExtra>;
}

0 comments on commit b149a44

Please sign in to comment.