UNPKG

rock-mod

Version:

Rock-Mod is a powerful framework designed for creating and managing mods for Grand Theft Auto (GTA) games.

67 lines (66 loc) 1.94 kB
import { RageEntitiesManager } from "../entity/RageEntitiesManager"; import { RagePlayer } from "./RagePlayer"; export class RagePlayersManager extends RageEntitiesManager { constructor() { super({ baseObjectsType: "player", }); } getByName(name) { const player = this.findByName(name); if (!player) { throw new Error(`Player with name ${name} not found`); } return player; } findByName(name) { for (const player of this.iterator.all()) { if (player.name === name) { return player; } } return null; } findByRemoteId(remoteId) { const mpPlayer = mp.players.atRemoteId(remoteId); if (!mpPlayer) { return null; } return this.findByID(mpPlayer.id); } getByRemoteId(remoteId) { const player = this.findByRemoteId(remoteId); if (!player) { throw new Error(`Player with remoteId ${remoteId} not found`); } return player; } findLocalPlayer() { return this.findByID(mp.players.local.id); } getLocalPlayer() { const localPlayer = this.findLocalPlayer(); if (!localPlayer) { throw new Error(`Local player with id ${mp.players.local.id} not found`); } return localPlayer; } syncWithMpPool() { for (const mpPlayer of mp.players.toArray()) { this.registerById(mpPlayer.id); } } registerById(id) { const existingPlayer = this.findByID(id); if (existingPlayer) { return existingPlayer; } const mpPlayer = mp.players.at(id); mpPlayer.isExists = () => mp.players.exists(mpPlayer); const player = new RagePlayer({ mpEntity: mpPlayer, }); this.registerBaseObject(player); return player; } }