UNPKG

@nativewrappers/redm

Version:

Native wrappers and utilities for use with RedM.

106 lines (105 loc) 3.16 kB
var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); import { Vector3 } from "../common/utils/Vector"; class BaseEntity { static { __name(this, "BaseEntity"); } handle; constructor(entHandle) { this.handle = entHandle; } /** * Replaces the current handle for the entity used on, this hsould be used sparringly, mainly * in situations where you're going to reuse an entity over and over and don't want to make a * new entity every time. * * **WARNING**: This does no checks, if you provide it an invalid entity it will use it * * ```ts * const REUSABLE_ENTITY = new Entity(entityHandle); * * onNet("entityHandler", (entNetId: number) => { * // if no net entity we should ignore * if (!NetworkDoesEntityExistWithNetworkId(entNetId)) return; * * // Reuse our entity so we don't have to initialize a new one * REUSABLE_ENTITY.replaceHandle(NetworkGetEntityFromNetworkId(entNetId)); * // Do something with REUSABLE_ENTITY entity * }) ``` */ replaceHandle(newHandle) { this.handle = newHandle; } /** * @returns the network for the specified entity, this doesn't check if the entity is networked, you should use {@link IsNetworked} */ get NetworkId() { return NetworkGetNetworkIdFromEntity(this.handle); } /** * @returns `true` if the current entity is networked, false otherwise */ get IsNetworked() { return NetworkGetEntityIsNetworked(this.handle); } /** * @returns Returns true if the entity handle is not 0 and exists in the game engine */ get Exists() { return this.handle !== 0 && DoesEntityExist(this.handle); } /** * @returns Returns true if the entity is dead */ get IsDead() { return IsEntityDead(this.handle); } /** * @returns The entitys current handle. */ get Handle() { return this.handle; } /** * @param amount the health to set the health to, setting to `0` will kill the entity, if using on a {@link Ped} you should check the MaxHealth before setting. */ set Health(amount) { SetEntityHealth(this.handle, amount, 0); } /** * @returns the amount of health the current {@link BaseEntity} has */ get Health() { return GetEntityHealth(this.handle); } /** * @returns the heading of the current {@link BaseEntity} */ get Heading() { return GetEntityHeading(this.handle); } /** * @param heading sets the entitys heading to the specified heading, this can be in the range of 0..360 */ set Heading(heading) { SetEntityHeading(this.handle, heading); } /** * @returns the position of the current Entity */ get Position() { return Vector3.fromArray(GetEntityCoords(this.handle, true, true)); } /** * You should (almost) always try to load the collisions before setting the entitys position if going a long distance. * @param pos sets the position for the current ped */ set Position(pos) { SetEntityCoords(this.handle, pos.x, pos.y, pos.z, false, false, false, false); } } export { BaseEntity };