Skip to content

Commit

Permalink
Merge pull request #36 from altmp/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Jengas authored Sep 3, 2024
2 parents 036e843 + c335b9e commit 00c1011
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 15 deletions.
60 changes: 46 additions & 14 deletions bindings/src/server/entities/Vehicle.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as alt from 'alt-server';
import {SyncedMetaProxy} from '../../shared/meta.js';
import mp from '../../shared/mp.js';
import {deg2rad, hashIfNeeded, mpSeatToAlt, rad2deg, TemporaryContainer} from '../../shared/utils.js';
import {deg2rad, hashIfNeeded, altSeatToMp, rad2deg, TemporaryContainer} from '../../shared/utils.js';
import {_Entity} from './Entity.js';
import {ServerPool} from '../pools/ServerPool';
import {EntityGetterView} from '../../shared/pools/EntityGetterView';
Expand Down Expand Up @@ -254,22 +254,13 @@ export class _Vehicle extends _Entity {
}

getOccupant(id) {
if (mpSeatToAlt(id) === 1) return this.alt.driver?.mp;
// TODO: implement in core

return this.alt.passengers?.[mpSeatToAlt(id)]?.mp;
return this.__occupantsMap?.get(id);
}

getOccupants() {
// TODO: implement in core
const occupants = [];
const driver = this.alt.driver;
if (driver) occupants.push(driver.mp);

const passengers = Object.values(this.alt.passengers);
if (passengers?.length) occupants.push(...passengers.map(p => p.mp));

return occupants;
return this.__occupantsMap !== undefined
? Array.from(this.__occupantsMap.values())
: [];
}

// TODO: getPaint
Expand Down Expand Up @@ -401,3 +392,44 @@ alt.on('vehicleSiren', (vehicle, player, state) => {
alt.on('vehicleDestroy', (vehicle) => {
mp.events.dispatchLocal('vehicleDeath', vehicle.mp);
});

alt.on('playerEnteredVehicle', (player, vehicle, seat) => {
let occupants = vehicle.mp.__occupantsMap;
if (!occupants) {
occupants = new Map();
vehicle.mp.__occupantsMap = occupants;
}

occupants.set(altSeatToMp(seat), player);
});

alt.on('playerLeftVehicle', (player, vehicle, seat) => {
let occupants = vehicle.mp.__occupantsMap;
if (!occupants) {
occupants = new Map();
vehicle.mp.__occupantsMap = occupants;
}

occupants.forEach((p, s) => {
if (p === player) {
occupants.delete(s);
}
});
});

alt.on('playerChangedVehicleSeat', (player, vehicle, oldSeat, newSeat) => {
let occupants = vehicle.mp.__occupantsMap;
if (!occupants) {
occupants = new Map();
vehicle.mp.__occupantsMap = occupants;
}

occupants.delete(altSeatToMp(oldSeat));
occupants.set(altSeatToMp(newSeat), player);
});

alt.on('removeEntity', (entity) => {
if (entity instanceof alt.Vehicle) {
delete entity.mp.__occupantsMap;
}
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ragemp-altv-bridge",
"version": "1.0.5",
"version": "1.0.6",
"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",
Expand Down

0 comments on commit 00c1011

Please sign in to comment.