diff --git a/packages/core/src/controllers/netstats/index.ts b/packages/core/src/controllers/netstats/index.ts index 612237f..6f9d0ef 100644 --- a/packages/core/src/controllers/netstats/index.ts +++ b/packages/core/src/controllers/netstats/index.ts @@ -8,36 +8,34 @@ export class NetStats { static getNetworkStats(): string { return f.GetNetworkStats(); } - static getPlayerNetworkStats

(player: P): string { + static getPlayerNetworkStats(player: Player): string { return f.GetPlayerNetworkStats(player.id); } - static getBytesReceived

(player: P): number { + static getBytesReceived(player: Player): number { return f.NetStats_BytesReceived(player.id); } - static getBytesSent

(player: P): number { + static getBytesSent(player: Player): number { return f.NetStats_BytesSent(player.id); } - static getConnectionStatus

( - player: P - ): ConnectionStatusEnum { + static getConnectionStatus(player: Player): ConnectionStatusEnum { return f.NetStats_ConnectionStatus(player.id); } - static getConnectedTime

(player: P): number { + static getConnectedTime(player: Player): number { return f.NetStats_GetConnectedTime(player.id); } - static getIpPort

(player: P): string { + static getIpPort(player: Player): string { return f.NetStats_GetIpPort(player.id); } - static getMessagesReceived

(player: P): number { + static getMessagesReceived(player: Player): number { return f.NetStats_MessagesReceived(player.id); } - static getMessagesRecvPerSecond

(player: P): number { + static getMessagesRecvPerSecond(player: Player): number { return f.NetStats_MessagesRecvPerSecond(player.id); } - static getMessagesSent

(player: P): number { + static getMessagesSent(player: Player): number { return f.NetStats_MessagesSent(player.id); } - static getPacketLossPercent

(player: P): number { + static getPacketLossPercent(player: Player): number { return f.NetStats_PacketLossPercent(player.id); } } diff --git a/packages/core/src/controllers/vehicle/entity.ts b/packages/core/src/controllers/vehicle/entity.ts index 0bdce62..d9e5546 100644 --- a/packages/core/src/controllers/vehicle/entity.ts +++ b/packages/core/src/controllers/vehicle/entity.ts @@ -2,7 +2,7 @@ import type { CarModTypeEnum, VehicleModelInfoEnum } from "core/enums"; import { LimitsEnum } from "core/enums"; import type { TPos } from "core/types"; import type { IVehicle } from "core/interfaces"; -import type { Player } from "../player"; +import { Player } from "../player"; import { isValidPaintJob, isValidVehComponent } from "core/utils/vehicleUtils"; import * as v from "core/wrapper/native/functions"; @@ -143,19 +143,19 @@ export class Vehicle { if (this.id === -1) return 0; return v.SetVehicleHealth(this.id, health); } - isPlayerIn

(player: P): boolean { + isPlayerIn(player: Player): boolean { if (this.id === -1) return false; return v.IsPlayerInVehicle(player.id, this.id); } - putPlayerIn

(player: P, seatid: number): number { + putPlayerIn(player: Player, seatId: number): number { if (this.id === -1) return 0; - if (seatid < 0) return 0; - if (seatid > 4) { + if (seatId < 0) return 0; + if (seatId > 4) { logger.warn( "[Vehicle]: If the seat is invalid or is taken, will cause a crash when they EXIT the vehicle." ); } - return v.PutPlayerInVehicle(player.id, this.id, seatid); + return v.PutPlayerInVehicle(player.id, this.id, seatId); } getZAngle(): number { if (this.id === -1) return 0; @@ -216,14 +216,14 @@ export class Vehicle { return v.GetVehicleModel(this.id); } static getModelInfo( - vehiclemodel: number, - infotype: VehicleModelInfoEnum + vehicleModel: number, + infoType: VehicleModelInfoEnum ): TPos { - return v.GetVehicleModelInfo(vehiclemodel, infotype); + return v.GetVehicleModelInfo(vehicleModel, infoType); } - getModelInfo(infotype: VehicleModelInfoEnum): void | TPos { + getModelInfo(infoType: VehicleModelInfoEnum): void | TPos { if (this.id === -1) return; - return Vehicle.getModelInfo(this.getModel(), infotype); + return Vehicle.getModelInfo(this.getModel(), infoType); } getRotationQuat() { if (this.id === -1) return; @@ -234,38 +234,38 @@ export class Vehicle { if (this.id === -1) return 0; return v.SetVehicleToRespawn(this.id); } - isStreamedIn

(forplayer: P): boolean { + isStreamedIn(forPlayer: Player): boolean { if (this.id === -1) return false; - return v.IsVehicleStreamedIn(this.id, forplayer.id); + return v.IsVehicleStreamedIn(this.id, forPlayer.id); } setParamsCarDoors( driver: boolean, passenger: boolean, - backleft: boolean, - backright: boolean + backLeft: boolean, + backRight: boolean ): number { if (this.id === -1) return 0; return v.SetVehicleParamsCarDoors( this.id, driver, passenger, - backleft, - backright + backLeft, + backRight ); } setParamsCarWindows( driver: boolean, passenger: boolean, - backleft: boolean, - backright: boolean + backLeft: boolean, + backRight: boolean ) { if (this.id === -1) return 0; return v.SetVehicleParamsCarWindows( this.id, driver, passenger, - backleft, - backright + backLeft, + backRight ); } getParamsCarDoors() { @@ -307,17 +307,17 @@ export class Vehicle { if (this.id === -1) return -2; return v.GetVehicleParamsSirenState(this.id); } - setParamsForPlayer

( - player: P, + setParamsForPlayer( + player: Player, objective: boolean, - doorslocked: boolean + doorsLocked: boolean ): number { if (this.id === -1) return 0; return v.SetVehicleParamsForPlayer( this.id, player.id, objective, - doorslocked + doorsLocked ); } isTrailerAttached(): boolean { @@ -331,7 +331,7 @@ export class Vehicle { v.ChangeVehiclePaintjob(this.id, paintjobId); return 1; } - attachTrailer(trailer: V): number { + attachTrailer(trailer: Vehicle): number { if (this.id === -1) return 0; return v.AttachTrailerToVehicle(trailer.id, this.id); } @@ -339,9 +339,11 @@ export class Vehicle { if (this.id === -1) return; if (this.isTrailerAttached()) v.DetachTrailerFromVehicle(this.id); } - getTrailer(vehicles: Array): V | undefined { + getTrailer() { if (this.id === -1) return; - return vehicles.find((_v) => _v.id === v.GetVehicleTrailer(this.id)); + return Vehicle.getInstances().find( + (_v) => _v.id === v.GetVehicleTrailer(this.id) + ); } isValid(): boolean { return v.IsValidVehicle(this.id); @@ -370,13 +372,13 @@ export class Vehicle { return w.GetVehicleSirenState(this.id); } static getModelsUsed = w.GetVehicleModelsUsed; - getDriver

(players: Map): P | undefined { + getDriver() { if (this.id === -1) return; - return players.get(w.GetVehicleDriver(this.id)); + return Player.players.get(w.GetVehicleDriver(this.id)); } - getLastDriver

(players: Map): P | undefined { + getLastDriver() { if (this.id === -1) return; - return players.get(w.GetVehicleLastDriver(this.id)); + return Player.players.get(w.GetVehicleLastDriver(this.id)); } static getModelCount = w.GetVehicleModelCount; isSirenEnabled(): boolean { diff --git a/packages/core/src/types/index.ts b/packages/core/src/types/index.ts index d0e2020..8b41747 100644 --- a/packages/core/src/types/index.ts +++ b/packages/core/src/types/index.ts @@ -1,3 +1,4 @@ +import type { Player } from "core/controllers/player/entity"; import type { IDynamicCircle, IDynamicCylinder, @@ -8,9 +9,9 @@ import type { } from "core/interfaces"; export type TEventName = string | string[]; -export type TEventFunc = ( +export type TEventFunc = ( this: EventInstance, - player: P, + player: Player, ...args: string[] ) => boolean | number | void | Promise; diff --git a/packages/core/src/utils/helperUtils.ts b/packages/core/src/utils/helperUtils.ts index a5055b6..6f8f573 100644 --- a/packages/core/src/utils/helperUtils.ts +++ b/packages/core/src/utils/helperUtils.ts @@ -1,5 +1,5 @@ import { I18n } from "core/controllers/i18n"; -import type { Player } from "../controllers/player/entity"; +import { Player } from "../controllers/player/entity"; import { LimitsEnum } from "../enums"; import type { IDialog } from "../interfaces"; import { rgba } from "./colorUtils"; @@ -30,11 +30,10 @@ export const SendClientMessage = ( }; export const SendClientMessageToAll = ( - fn: Array, color: string | number, msg: string ): number => { - fn.forEach((player) => SendClientMessage(player, color, msg)); + Player.getInstances().forEach((p) => SendClientMessage(p, color, msg)); return 1; }; @@ -54,11 +53,12 @@ export const SendPlayerMessageToPlayer = ( }; export const SendPlayerMessageToAll = ( - fn: Array, senderId: number, message: string ): number => { - fn.forEach((player) => SendPlayerMessageToPlayer(player, senderId, message)); + Player.getInstances().forEach((p) => { + SendPlayerMessageToPlayer(p, senderId, message); + }); return 1; }; diff --git a/packages/core/src/wrapper/native/functions/index.ts b/packages/core/src/wrapper/native/functions/index.ts index fed0fd2..026daaf 100644 --- a/packages/core/src/wrapper/native/functions/index.ts +++ b/packages/core/src/wrapper/native/functions/index.ts @@ -2122,9 +2122,9 @@ export const SetPlayerChatBubble = ( export const PutPlayerInVehicle = ( playerId: number, vehicleId: number, - seatid: number + seatId: number ): number => { - return callNative("PutPlayerInVehicle", "iii", playerId, vehicleId, seatid); + return callNative("PutPlayerInVehicle", "iii", playerId, vehicleId, seatId); }; export const GetPlayerVehicleID = (playerId: number): number => { @@ -2277,6 +2277,10 @@ export const SetPlayerWorldBounds = ( ); }; +export const ClearPlayerWorldBounds = (playerId: number) => { + return Boolean(callNative("ClearPlayerWorldBounds", "i", playerId)); +}; + export const SetPlayerMarkerForPlayer = ( playerId: number, showplayerid: number, @@ -2991,13 +2995,13 @@ export const UpdateVehicleDamageStatus = ( export const GetVehicleModelInfo = ( vehiclemodel: number, - infotype: VehicleModelInfoEnum + infoType: VehicleModelInfoEnum ) => { const values: number[] = callNative( "GetVehicleModelInfo", "iiFFF", vehiclemodel, - infotype + infoType ); if (values.length < 3) { throw new Error("ModelID " + vehiclemodel + " not found"); diff --git a/packages/core/src/wrapper/streamer/actor/entity.ts b/packages/core/src/wrapper/streamer/actor/entity.ts index 831ba70..29bf062 100644 --- a/packages/core/src/wrapper/streamer/actor/entity.ts +++ b/packages/core/src/wrapper/streamer/actor/entity.ts @@ -102,9 +102,9 @@ export class DynamicActor { isValid(): boolean { return s.IsValidDynamicActor(this.id); } - isStreamedIn

(forplayer: P): boolean { + isStreamedIn(forPlayer: Player): boolean { if (this.id === -1) return false; - return s.IsDynamicActorStreamedIn(this.id, forplayer.id); + return s.IsDynamicActorStreamedIn(this.id, forPlayer.id); } getVirtualWorld(): void | number { if (this.id === -1) @@ -199,21 +199,15 @@ export class DynamicActor { ); return s.SetDynamicActorInvulnerable(this.id, invulnerable); } - getPlayerTarget

( - player: P, - actors: Map - ): void | A { + getPlayerTarget(player: Player) { if (this.id === -1) return undefined; const actorId = s.GetPlayerTargetDynamicActor(player.id); - return actors.get(actorId); + return DynamicActor.actors.get(actorId); } - getPlayerCameraTarget

( - player: P, - actors: Map - ): void | A { + getPlayerCameraTarget(player: Player) { if (this.id === -1) return undefined; const actorId = s.GetPlayerCameraTargetDynActor(player.id); - return actors.get(actorId); + return DynamicActor.actors.get(actorId); } getSkin(): void | number { if (this.id === -1) diff --git a/packages/core/src/wrapper/streamer/area/entity.ts b/packages/core/src/wrapper/streamer/area/entity.ts index 70c9185..88f33cd 100644 --- a/packages/core/src/wrapper/streamer/area/entity.ts +++ b/packages/core/src/wrapper/streamer/area/entity.ts @@ -263,11 +263,11 @@ export class DynamicArea { if (this.type !== "polygon") return undefined; return s.GetDynamicPolygonNumberPoints(this.id); } - isPlayerIn

(player: P, recheck = false): boolean { + isPlayerIn(player: Player, recheck = false): boolean { if (this.id === -1) return false; return s.IsPlayerInDynamicArea(player.id, this.id, recheck); } - static isPlayerInAny

(player: P, recheck = false): boolean { + static isPlayerInAny(player: Player, recheck = false): boolean { return s.IsPlayerInAnyDynamicArea(player.id, recheck); } isAnyPlayerIn(recheck = false): boolean { @@ -277,15 +277,12 @@ export class DynamicArea { static isAnyPlayerInAny(recheck = false): boolean { return s.IsAnyPlayerInAnyDynamicArea(recheck); } - static getPlayerAreas

( - player: P, - areas: Map - ): Array { + static getPlayerAreas(player: Player): Array { if (!DynamicArea.getPlayerAreasNumber(player)) return []; const ids = s.GetPlayerDynamicAreas(player.id); - return ids.map((a) => areas.get(a)); + return ids.map((a) => DynamicArea.areas.get(a)); } - static getPlayerAreasNumber

(player: P) { + static getPlayerAreasNumber(player: Player) { return s.GetPlayerNumberDynamicAreas(player.id); } isPointIn(x: number, y: number, z: number): boolean { @@ -316,31 +313,27 @@ export class DynamicArea { ): boolean { return s.IsLineInAnyDynamicArea(x1, y1, z1, x2, y2, z2); } - static getForPoint( - x: number, - y: number, - z: number, - areas: Map - ): Array { + static getForPoint(x: number, y: number, z: number) { if (!DynamicArea.getNumberForPoint(x, y, z)) return []; const ids = s.GetDynamicAreasForPoint(x, y, z); - return ids.map((a) => areas.get(a)); + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + return ids.map((a) => DynamicArea.getInstance(a)!); } static getNumberForPoint(x: number, y: number, z: number): number { return s.GetNumberDynamicAreasForPoint(x, y, z); } - static getForLine( + static getForLine( x1: number, y1: number, z1: number, x2: number, y2: number, - z2: number, - areas: Map - ): Array { + z2: number + ) { if (!DynamicArea.getNumberForLine(x1, y1, z1, x2, y2, z2)) return []; const ids = s.GetDynamicAreasForLine(x1, y1, z1, x2, y2, z2); - return ids.map((a) => areas.get(a)); + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + return ids.map((a) => DynamicArea.areas.get(a)!); } static getNumberForLine( x1: number, @@ -352,8 +345,8 @@ export class DynamicArea { ): number { return s.GetNumberDynamicAreasForLine(x1, y1, z1, x2, y2, z2); } - attachToObject( - obj: O, + attachToObject( + obj: DynamicObject, offsetX = 0.0, offsetY = 0.0, offsetZ = 0.0 @@ -372,8 +365,8 @@ export class DynamicArea { offsetZ ); } - attachToPlayer

( - player: P, + attachToPlayer( + player: Player, offsetX = 0.0, offsetY = 0.0, offsetZ = 0.0 @@ -390,8 +383,8 @@ export class DynamicArea { offsetZ ); } - attachToVehicle( - vehicle: V, + attachToVehicle( + vehicle: Vehicle, offsetX = 0.0, offsetY = 0.0, offsetZ = 0.0 diff --git a/packages/core/src/wrapper/streamer/checkpoint/entity.ts b/packages/core/src/wrapper/streamer/checkpoint/entity.ts index 378d966..1cca80e 100644 --- a/packages/core/src/wrapper/streamer/checkpoint/entity.ts +++ b/packages/core/src/wrapper/streamer/checkpoint/entity.ts @@ -109,7 +109,7 @@ export class DynamicCheckpoint { isValid(): boolean { return IsValidDynamicCP(this.id); } - togglePlayer

(player: P, toggle: boolean): void | this { + togglePlayer(player: Player, toggle: boolean): void | this { if (this.id === -1) return logger.warn( "[StreamerCheckpoint]: Unable to toggle the player before create" @@ -117,18 +117,17 @@ export class DynamicCheckpoint { TogglePlayerDynamicCP(player.id, this.id, toggle); return this; } - static togglePlayerAll

(player: P, toggle: boolean): number { + static togglePlayerAll(player: Player, toggle: boolean): number { return TogglePlayerAllDynamicCPs(player.id, toggle); } - isPlayerIn

(player: P): boolean { + isPlayerIn(player: Player): boolean { if (this.id === -1) return false; return IsPlayerInDynamicCP(player.id, this.id); } - static getPlayerVisible

( - player: P, - checkpoints: Map - ): C | undefined { - return checkpoints.get(GetPlayerVisibleDynamicCP(player.id)); + static getPlayerVisible(player: Player) { + return DynamicCheckpoint.checkpoints.get( + GetPlayerVisibleDynamicCP(player.id) + ); } toggleCallbacks(toggle = true): void | number { if (this.id === -1) diff --git a/packages/core/src/wrapper/streamer/object/entity.ts b/packages/core/src/wrapper/streamer/object/entity.ts index cea7ef9..28ddb02 100644 --- a/packages/core/src/wrapper/streamer/object/entity.ts +++ b/packages/core/src/wrapper/streamer/object/entity.ts @@ -176,7 +176,7 @@ export class DynamicObject { return s.IsDynamicObjectMoving(this.id); } - attachCamera

(player: P): void | number { + attachCamera(player: Player): void | number { if (this.id === -1 || player.id === -1) return logger.warn( "[StreamerObject]: Cannot attachCamera before both are created" @@ -184,8 +184,8 @@ export class DynamicObject { return s.AttachCameraToDynamicObject(player.id, this.id); } - attachToObject( - attachto: O, + attachToObject( + attachTo: DynamicObject, offsetX: number, offsetY: number, offsetZ: number, @@ -194,13 +194,13 @@ export class DynamicObject { rz: number, syncRotation = true ): void | number { - if (this.id === -1 || attachto.id === -1) + if (this.id === -1 || attachTo.id === -1) return logger.warn( "[StreamerObject]: Cannot attachToObject before both are created" ); return s.AttachDynamicObjectToObject( this.id, - attachto.id, + attachTo.id, offsetX, offsetY, offsetZ, @@ -211,8 +211,8 @@ export class DynamicObject { ); } - attachToPlayer

( - player: P, + attachToPlayer( + player: Player, offsetX: number, offsetY: number, offsetZ: number, @@ -236,8 +236,8 @@ export class DynamicObject { ); } - attachToVehicle( - vehicle: V, + attachToVehicle( + vehicle: Vehicle, offsetX: number, offsetY: number, offsetZ: number, @@ -261,7 +261,7 @@ export class DynamicObject { ); } - edit

(player: P): void | number { + edit(player: Player): void | number { if (this.id === -1) return logger.warn("[StreamerObject]: Unable to edit before create"); player.endObjectEditing(); @@ -367,13 +367,10 @@ export class DynamicObject { ); } - getPlayerCameraTarget

( - player: P, - objMap: Map - ): void | O { + getPlayerCameraTarget(player: Player) { const dynId = s.GetPlayerCameraTargetDynObject(player.id); if (dynId === InvalidEnum.OBJECT_ID) return; - return objMap.get(dynId); + return DynamicObject.objects.get(dynId); } toggleCallbacks(toggle = true): void | number { if (this.id === -1) diff --git a/packages/core/src/wrapper/streamer/raceCP/entity.ts b/packages/core/src/wrapper/streamer/raceCP/entity.ts index b657374..200681f 100644 --- a/packages/core/src/wrapper/streamer/raceCP/entity.ts +++ b/packages/core/src/wrapper/streamer/raceCP/entity.ts @@ -113,7 +113,7 @@ export class DynamicRaceCP { isValid(): boolean { return IsValidDynamicCP(this.id); } - togglePlayer

(player: P, toggle: boolean): void | this { + togglePlayer(player: Player, toggle: boolean): void | this { if (this.id === -1) return logger.warn( "[StreamerRaceCP]: Unable to toggle the player before create" @@ -121,18 +121,17 @@ export class DynamicRaceCP { TogglePlayerDynamicRaceCP(player.id, this.id, toggle); return this; } - static togglePlayerAll

(player: P, toggle: boolean): number { + static togglePlayerAll(player: Player, toggle: boolean): number { return TogglePlayerAllDynamicRaceCPs(player.id, toggle); } - isPlayerIn

(player: P): boolean { + isPlayerIn(player: Player): boolean { if (this.id === -1) return false; return IsPlayerInDynamicRaceCP(player.id, this.id); } - static getPlayerVisible

( - player: P, - checkpoints: Map - ): C | undefined { - return checkpoints.get(GetPlayerVisibleDynamicRaceCP(player.id)); + static getPlayerVisible(player: Player) { + return DynamicRaceCP.checkpoints.get( + GetPlayerVisibleDynamicRaceCP(player.id) + ); } toggleCallbacks(toggle = true): void | number { if (this.id === -1)