diff --git a/bindings/src/client/entities/Object.js b/bindings/src/client/entities/Object.js index 11d8863..e33e10f 100644 --- a/bindings/src/client/entities/Object.js +++ b/bindings/src/client/entities/Object.js @@ -246,6 +246,9 @@ export class _NetworkObject extends _Object { if (shouldCancel()) return; this.#handle = natives.createObject(model, this.alt.pos.x, this.alt.pos.y, this.alt.pos.z, false, false, false); + if (!this.#handle) { + throw new Error('Failed to create object using native:', model); + } natives.setEntityCoordsNoOffset(this.#handle, this.alt.pos.x, this.alt.pos.y, this.alt.pos.z, false, false, false); store.add(this, undefined, this.#handle, undefined); diff --git a/bindings/src/client/entities/Player.js b/bindings/src/client/entities/Player.js index 4d278ac..5533145 100644 --- a/bindings/src/client/entities/Player.js +++ b/bindings/src/client/entities/Player.js @@ -3,7 +3,7 @@ import * as natives from 'natives'; import mp from '../../shared/mp.js'; import {ClientPool} from '../pools/ClientPool.js'; import {_Entity} from './Entity.js'; -import {altSeatToMp, getOverlayColorType, internalName, toMp} from '../../shared/utils'; +import {altSeatToClientMp, getOverlayColorType, internalName, toMp} from '../../shared/utils'; import {EntityGetterView} from '../../shared/pools/EntityGetterView'; import {emitServerInternal} from '../clientUtils'; import {BaseObjectType} from '../../shared/BaseObjectType'; @@ -1068,37 +1068,6 @@ function getSeat() { } } -if (mp._main) { - let lastVehicle = mp.players.local.vehicle; - let lastSeat = getSeat(); - setInterval(() => { - const newVehicle = mp.players.local.vehicle; - if (newVehicle !== lastVehicle) { - console.log('Changed vehicle from ' + lastVehicle?.id + ' to ' + newVehicle?.id); - mp.notifyTrace('player', 'player changed vehicle from', lastVehicle, 'to', newVehicle); - if (lastVehicle) { - mp.events.dispatchLocal('playerLeaveVehicle', lastVehicle?.alt?.valid ? lastVehicle : null, lastSeat); - } - - if (newVehicle) { - const newSeat = getSeat(); - mp.events.dispatchLocal('playerStartEnterVehicle', newVehicle, newSeat); - mp.events.dispatchLocal('playerEnterVehicle', newVehicle, newSeat); - lastSeat = newSeat; - } - - lastVehicle = newVehicle; - } else if (lastVehicle) { - const newSeat = getSeat(); - if (newSeat !== lastSeat) { - console.log('Changed vehicle seat from ' + lastSeat + ' to ' + newSeat); - mp.events.dispatchLocal('playerEnterVehicle', newVehicle, newSeat); - lastSeat = newSeat; - } - } - }, 500); -} - alt.on('netOwnerChange', (ent, newOwner, oldOwner) => { mp.events.dispatchLocal('entityControllerChange', ent, toMp(newOwner)); }); @@ -1127,3 +1096,21 @@ alt.on('playerStartTalking', (player) => { alt.on('playerStopTalking', (player) => { mp.events.dispatchLocal('playerStopTalking', player.mp); }); + + +alt.on('enteringVehicle', (vehicle, seat) => { + mp.events.dispatchLocal('playerStartEnterVehicle', vehicle?.mp, altSeatToClientMp(seat)); +}); + +alt.on('enteredVehicle', (vehicle, seat) => { + mp.events.dispatchLocal('playerEnterVehicle', vehicle?.mp, altSeatToClientMp(seat)); +}); + +alt.on('changedVehicleSeat', (vehicle, oldSeat, seat) => { + mp.events.dispatchLocal('playerEnterVehicle', vehicle?.mp, altSeatToClientMp(seat)); +}); + +alt.on('leftVehicle', (vehicle, seat) => { + // mp.events.dispatchLocal('playerStartExitVehicle', vehicle?.mp, altSeatToClientMp(seat) - 1); + mp.events.dispatchLocal('playerLeaveVehicle', vehicle?.mp, altSeatToClientMp(seat)); +}); diff --git a/bindings/src/client/entities/Vehicle.js b/bindings/src/client/entities/Vehicle.js index d570c09..fe7b20f 100644 --- a/bindings/src/client/entities/Vehicle.js +++ b/bindings/src/client/entities/Vehicle.js @@ -335,7 +335,7 @@ export class _Vehicle extends _Entity { return this.setTaskGotoPlaneMinHeightAboveTerrain; } - getPedInSeat(seatIndex, p2) { + getPedInSeat(seatIndex, p2 = false) { return natives.getPedInVehicleSeat(this.handle, seatIndex, p2); } diff --git a/bindings/src/shared/utils.js b/bindings/src/shared/utils.js index 8a5f9f3..0afc83d 100644 --- a/bindings/src/shared/utils.js +++ b/bindings/src/shared/utils.js @@ -135,6 +135,10 @@ export const altSeatToMp = (altSeat) => { return altSeat - 1; }; +export const altSeatToClientMp = (altSeat) => { + return altSeat - 2; +}; + export const mpSeatToAlt = (mpSeat) => { return mpSeat + 1; }; diff --git a/package.json b/package.json index 92eb51b..c2a4cef 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ragemp-altv-bridge", - "version": "1.0.2", + "version": "1.0.3", "description": "RAGE Multiplayer alt:V Bridge. This package provides a bridge between RAGE Multiplayer and alt:V. It allows you to use RAGEMP code in alt:V.", "keywords": [ "ragemp",