class PlayerPointing {
private isPointing: boolean = false;
private keyPressed: boolean = false;
private player: PlayerMp = mp.players.local;
constructor() {
this.init();
}
private init() {
mp.keys.bind(72, false, this.handleKeyPress.bind(this));
mp.events.add('render', this.update.bind(this));
}
private async startPointing() {
try {
const dict = 'anim@mp_point';
mp.game.streaming.requestAnimDict(dict);
while (!mp.game.streaming.hasAnimDictLoaded(dict)) {
await mp.game.waitAsync(0);
}
// Hide weapon
mp.game.invoke('0x7FEAD38B326B9F74', this.player.handle, false);
this.player.setConfigFlag(36, true);
mp.game.invoke('0x2D537BA194896636', this.player.handle, "task_mp_pointing", 0.5, 0, dict, 24);
mp.game.streaming.removeAnimDict(dict);
} catch (error) {
console.log('Start pointing error:', error);
}
}
private stopPointing() {
try {
mp.game.invoke('0xD01015C7316AE176', this.player.handle, "Stop");
if (!this.player.isInAnyVehicle(true)) {
// Show weapon
mp.game.invoke('0x7FEAD38B326B9F74', this.player.handle, true);
}
this.player.setConfigFlag(36, false);
this.player.clearTasks();
} catch (error) {
console.log('Stop pointing error:', error);
}
}
private handleKeyPress() {
if (!this.keyPressed) {
if (!this.isPointing && this.player.isOnFoot()) {
this.keyPressed = true;
this.isPointing = true;
this.startPointing();
} else if (this.isPointing || !this.player.isOnFoot()) {
this.keyPressed = true;
this.isPointing = false;
this.stopPointing();
}
}
}
private update() {
if (this.keyPressed && !mp.keys.isDown(72)) {
this.keyPressed = false;
}
if (mp.game.invoke('0x921CE12C489C4C41', this.player.handle) && !this.isPointing) {
this.stopPointing();
}
if (mp.game.invoke('0x921CE12C489C4C41', this.player.handle) && this.player.isOnFoot()) {
const camPitch = mp.game.cam.getGameplayRelativePitch();
const camHeading = mp.game.cam.getGameplayCamRelativeHeading();
let adjustedPitch = Math.max(-70.0, Math.min(42.0, camPitch));
adjustedPitch = (adjustedPitch + 70.0) / 112.0;
let adjustedHeading = Math.max(-180.0, Math.min(180.0, camHeading));
adjustedHeading = (adjustedHeading + 180.0) / 360.0;
const coords = this.player.getOffsetFromInWorldCoords(
Math.cos(camHeading) * -0.2 - Math.sin(camHeading) * (0.4 * adjustedHeading + 0.3),
Math.sin(camHeading) * -0.2 + Math.cos(camHeading) * (0.4 * adjustedHeading + 0.3),
0.6
);
const ray = mp.raycasting.testPointToPoint(
new mp.Vector3(coords.x, coords.y, coords.z - 0.2),
new mp.Vector3(coords.x, coords.y, coords.z + 0.2),
this.player.handle,
7
);
mp.game.invoke('0xD5BB4025AE449A4E', this.player.handle, "Pitch", adjustedPitch);
mp.game.invoke('0xD5BB4025AE449A4E', this.player.handle, "Heading", adjustedHeading * -1.0 + 1.0);
mp.game.invoke('0xB0A6CFD2C69C1088', this.player.handle, "isBlocked", ray ? 1 : 0);
}
}
}
export default new PlayerPointing();