Jump to content

Recommended Posts

Posted

Hi can someone of the PRO resource creators make a Finger-Point script using the "anim@mp_point" ? i need it for my RP server.

I have also a script from FiveM that you can translate or use it for the resource.

Thanks :D ,

That's the FiveM script :

local mp_pointing = false
local keyPressed = false

local function startPointing()
    local ped = GetPlayerPed(-1)
    RequestAnimDict("anim@mp_point")
    while not HasAnimDictLoaded("anim@mp_point") do
        Wait(0)
    end
    SetPedCurrentWeaponVisible(ped, 0, 1, 1, 1)
    SetPedConfigFlag(ped, 36, 1)
    Citizen.InvokeNative(0x2D537BA194896636, ped, "task_mp_pointing", 0.5, 0, "anim@mp_point", 24)
    RemoveAnimDict("anim@mp_point")
end

local function stopPointing()
    local ped = GetPlayerPed(-1)
    Citizen.InvokeNative(0xD01015C7316AE176, ped, "Stop")
    if not IsPedInjured(ped) then
        ClearPedSecondaryTask(ped)
    end
    if not IsPedInAnyVehicle(ped, 1) then
        SetPedCurrentWeaponVisible(ped, 1, 1, 1, 1)
    end
    SetPedConfigFlag(ped, 36, 0)
    ClearPedSecondaryTask(PlayerPedId())
end

local once = true
local oldval = false
local oldvalped = false

Citizen.CreateThread(function()
    while true do
        Wait(0)

        if once then
            once = false
        end

        if not keyPressed then
            if IsControlPressed(0, 29) and not mp_pointing and IsPedOnFoot(PlayerPedId()) then
                Wait(200)
                if not IsControlPressed(0, 29) then
                    keyPressed = true
                    startPointing()
                    mp_pointing = true
                else
                    keyPressed = true
                    while IsControlPressed(0, 29) do
                        Wait(50)
                    end
                end
            elseif (IsControlPressed(0, 29) and mp_pointing) or (not IsPedOnFoot(PlayerPedId()) and mp_pointing) then
                keyPressed = true
                mp_pointing = false
                stopPointing()
            end
        end

        if keyPressed then
            if not IsControlPressed(0, 29) then
                keyPressed = false
            end
        end
        if Citizen.InvokeNative(0x921CE12C489C4C41, PlayerPedId()) and not mp_pointing then
            stopPointing()
        end
        if Citizen.InvokeNative(0x921CE12C489C4C41, PlayerPedId()) then
            if not IsPedOnFoot(PlayerPedId()) then
                stopPointing()
            else
                local ped = GetPlayerPed(-1)
                local camPitch = GetGameplayCamRelativePitch()
                if camPitch < -70.0 then
                    camPitch = -70.0
                elseif camPitch > 42.0 then
                    camPitch = 42.0
                end
                camPitch = (camPitch + 70.0) / 112.0

                local camHeading = GetGameplayCamRelativeHeading()
                local cosCamHeading = Cos(camHeading)
                local sinCamHeading = Sin(camHeading)
                if camHeading < -180.0 then
                    camHeading = -180.0
                elseif camHeading > 180.0 then
                    camHeading = 180.0
                end
                camHeading = (camHeading + 180.0) / 360.0

                local blocked = 0
                local nn = 0

                local coords = GetOffsetFromEntityInWorldCoords(ped, (cosCamHeading * -0.2) - (sinCamHeading * (0.4 * camHeading + 0.3)), (sinCamHeading * -0.2) + (cosCamHeading * (0.4 * camHeading + 0.3)), 0.6)
                local ray = Cast_3dRayPointToPoint(coords.x, coords.y, coords.z - 0.2, coords.x, coords.y, coords.z + 0.2, 0.4, 95, ped, 7);
                nn,blocked,coords,coords = GetRaycastResult(ray)

                Citizen.InvokeNative(0xD5BB4025AE449A4E, ped, "Pitch", camPitch)
                Citizen.InvokeNative(0xD5BB4025AE449A4E, ped, "Heading", camHeading * -1.0 + 1.0)
                Citizen.InvokeNative(0xB0A6CFD2C69C1088, ped, "isBlocked", blocked)
                Citizen.InvokeNative(0xB0A6CFD2C69C1088, ped, "isFirstPerson", Citizen.InvokeNative(0xEE778F8C7E1142E2, Citizen.InvokeNative(0x19CAFA3C87F7C2FF)) == 4)

            end
        end
    end
end)

 

  • 1 year later...
  • 5 years later...
Posted (edited)
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();

 

Edited by Truen

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...