Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:altmp/ragemp-altv-bridge into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Jengas committed May 19, 2024
2 parents 1e8d31b + c2ab96e commit cd456d1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 32 deletions.
3 changes: 3 additions & 0 deletions bindings/src/client/entities/Object.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
51 changes: 19 additions & 32 deletions bindings/src/client/entities/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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));
});
Expand Down Expand Up @@ -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));
});
4 changes: 4 additions & 0 deletions bindings/src/shared/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit cd456d1

Please sign in to comment.