rock-mod
Version:
Rock-Mod is a powerful framework designed for creating and managing mods for Grand Theft Auto (GTA) games.
124 lines (123 loc) • 4.57 kB
JavaScript
import { RageWorldObject } from "../worldObject/RageWorldObject";
import { Vector3D } from "../../../../shared/common/utils";
export class RageEntity extends RageWorldObject {
get model() {
return this.mpEntity.model;
}
get rotation() {
var _a, _b;
return (_b = (_a = this._getNativeRotation()) !== null && _a !== void 0 ? _a : this._getEntityRotationProperty()) !== null && _b !== void 0 ? _b : new Vector3D(0, 0, this.heading);
}
constructor(options) {
super(options);
}
get heading() {
return this.mpEntity.getHeading();
}
setHeading(heading) {
this.mpEntity.setHeading(heading);
}
setModel(value) {
this.mpEntity.model = mp.game.joaat(value);
}
setRotation(value) {
this.mpEntity.rotation = new mp.Vector3(value);
if (this._hasValidHandle()) {
mp.game.entity.setRotation(this.handle, value.x, value.y, value.z, 2, true);
}
}
get forwardVector() {
const vector = this.mpEntity.getForwardVector();
return new Vector3D(vector.x, vector.y, vector.z);
}
freezePosition(freeze) {
// FREEZE_ENTITY_POSITION via raw native: the RAGEMP wrapper does not consistently
// toggle the engine-level freeze for client-spawned entities, leaving them frozen.
mp.game.invoke("0x428CA6DBD1094446", this.handle, freeze);
}
setCollision(collision, keepPhysics) {
// SET_ENTITY_COLLISION via raw native for the same reason as freezePosition above.
mp.game.invoke("0x1A9205C1B9EE827F", this.handle, collision, keepPhysics);
}
setInvincible(invincible) {
this.mpEntity.setInvincible(invincible);
}
setVisible(visible) {
this.mpEntity.setVisible(visible, false);
}
setAlpha(alpha) {
this.mpEntity.setAlpha(alpha);
}
get alpha() {
return this.mpEntity.alpha;
}
getOffsetFromInWorldCoords(offsetX, offsetY, offsetZ) {
const { x, y, z } = this.mpEntity.getOffsetFromInWorldCoords(offsetX, offsetY, offsetZ);
return new Vector3D(x, y, z);
}
resetAlpha() {
this.mpEntity.resetAlpha();
}
getBoneIndexByName(boneName) {
return this.mpEntity.getBoneIndexByName(boneName);
}
getWorldPositionOfBone(boneIndex) {
const { x, y, z } = this.mpEntity.getWorldPositionOfBone(boneIndex);
return new Vector3D(x, y, z);
}
getVariable(name) {
return this.mpEntity.getVariable(name);
}
getSyncedMeta(key) {
const value = this.mpEntity.getVariable(key);
return value === null ? undefined : value;
}
hasSyncedMeta(key) {
return this.mpEntity.getVariable(key) !== null;
}
getSyncedMetaKeys() {
// RageMP не экспонирует список ключей синхронно — возвращаем пустой массив.
return [];
}
attachToEntity(target, boneIndex, offset, rotation, p9, useSoftPinning, collision, isPed, vertexIndex, fixedRot) {
mp.game.entity.attachToEntity(this.handle, target.handle, boneIndex, offset.x, offset.y, offset.z, rotation.x, rotation.y, rotation.z, p9, useSoftPinning, collision, isPed, vertexIndex, fixedRot);
}
detach(useDetachVelocity, collision) {
mp.game.entity.detach(this.handle, useDetachVelocity, collision);
}
getSpeed() {
return mp.game.entity.getSpeed(this.handle);
}
isPlayingAnim(dictionary, name, taskFlag) {
return mp.game.entity.isPlayingAnim(this.handle, dictionary, name, taskFlag);
}
_getNativeRotation() {
if (!this._hasValidHandle())
return null;
try {
const rotation = mp.game.entity.getRotation(this.handle, 2);
if (!this._isVectorLike(rotation))
return null;
return new Vector3D(rotation.x, rotation.y, rotation.z);
}
catch (_a) {
return null;
}
}
_getEntityRotationProperty() {
const rotation = this.mpEntity.rotation;
if (!this._isVectorLike(rotation))
return null;
return new Vector3D(rotation.x, rotation.y, rotation.z);
}
_hasValidHandle() {
return typeof this.handle === "number" && this.handle > 0;
}
_isVectorLike(value) {
return (typeof value === "object" &&
value !== null &&
typeof value.x === "number" &&
typeof value.y === "number" &&
typeof value.z === "number");
}
}