odyssey-v_seat-selector/client/index.ts

56 lines
2.0 KiB
TypeScript
Raw Permalink Normal View History

2024-01-16 07:46:51 +00:00
import { handleOpen } from './SeatSelector.js';
import { SEAT_SELECTOR_EVENTS } from '@AthenaPlugins/odyssey-seat-selector/shared/events.js';
import { KEY_BINDS } from '@AthenaShared/enums/keyBinds.js';
import * as KEYBOARD_MAP from '@AthenaShared/information/keyboardMap.js';
import * as AthenaClient from '@AthenaClient/api/index.js';
import * as alt from 'alt-client';
import * as native from 'natives';
AthenaClient.systems.hotkeys.add({
key: KEY_BINDS.SELECT_SEAT ?? KEYBOARD_MAP.default.indexOf('G'),
description: 'Select a seat',
identifier: 'seat-selector',
keyDown: () => {
handleOpen();
},
restrictions: {
isOnFoot: true,
},
});
AthenaClient.webview.on(SEAT_SELECTOR_EVENTS.ENTER_VEHICLE, (vehicle: number, index: number) => {
native.setPedConfigFlag(alt.Player.local.scriptID, 184, true);
native.taskEnterVehicle(alt.Player.local.scriptID, vehicle, 5000, index, 2.0, 1, null, 0);
});
AthenaClient.systems.hotkeys.add({
key: KEY_BINDS.VEHICLE_FUNCS ?? KEYBOARD_MAP.default.indexOf('F'),
description: 'Enter vehicle as driver',
identifier: 'enter-vehicle-as-driver',
keyDown: () => {
if (alt.Player.local.vehicle !== null) {
if (native.getEntitySpeed(alt.Player.local.vehicle) > 0.0) {
native.taskLeaveVehicle(alt.Player.local.scriptID, alt.Player.local.vehicle.scriptID, 4160);
return;
}
native.taskLeaveVehicle(alt.Player.local.scriptID, alt.Player.local.vehicle.scriptID, 0);
return;
}
let vehicle = alt.Utils.getClosestVehicle({ pos: alt.LocalPlayer.local.pos, range: 5 });
if (vehicle === null) {
return;
}
if (!native.isVehicleSeatFree(vehicle, -1, true)) {
return;
}
native.taskEnterVehicle(alt.Player.local.scriptID, vehicle, 5000, -1, 2.0, 1, null, 0);
},
});
alt.on('leftVehicle', () => {
native.setPedConfigFlag(alt.Player.local.scriptID, 184, false);
});