[HELP] Simple animation hotkey

Hey guys,

So I am pretty new to development and I am looking for some help with a simple script. With the help of the How to create a basic script from Scammer ([How-To] Create a basic script), I have been able to begin customizing and creating my very own scripts. Currently, I am having some issues creating a hotkey for an animation. Due to my extremely basic understanding of lua, I aim to use other scripts (that give the permission to do so) as templates. Specifically here, I am using the fingerpoint script from @Geekness (How to Add Finger Pointing?) in order to create a hotkey for a military salute. I simply canā€™t seem to get it working and I have a couple ideas why, but after continuous trial and error, I was hoping someone could point me in the right direction!

Please keep in mind that as I am an amateur when it comes to scripting, it probably looks very sloppy, but I am only looking to improve so whatever help will be taken :slight_smile:

Here is what I have so far:

local mp_player_intcelebrationmale@salute = false
local keyPressed = false

local function startSalute()
local ped = GetPlayerPed(-1)
RequestAnimDict(ā€œanim@mp_player_intcelebrationmale@saluteā€)
while not HasAnimDictLoaded(ā€œanim@mp_player_intcelebrationmale@saluteā€) do
Wait(0)
end
SetPedCurrentWeaponVisible(ped, 0, 1, 1, 1)
SetPedConfigFlag(ped, 36, 1)
Citizen.InvokeNative(0x2D537BA194896636, ped, ā€œsaluteā€, 0.5, 0, ā€œanim@mp_player_intcelebrationmale@saluteā€, 24)
RemoveAnimDict(ā€œanim@mp_player_intcelebrationmale@saluteā€)
end

local function stopSalute()
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, 20) and not mp_player_intcelebrationmale@salute and IsPedOnFoot(PlayerPedId()) then
            Wait(100)
            if IsControlPressed(0, 20) then
                keyPressed = true
                startSalute()
                mp_player_intcelebrationmale@salute = true
            else
                keyPressed = true
                while IsControlPressed(0, 20) do
                    Wait(50)
                end
            end
        elseif (IsControlPressed(0, 20) and mp_player_intcelebrationmale@salute) or (not IsPedOnFoot(PlayerPedId()) and mp_player_intcelebrationmale@salute) then
            keyPressed = false
            mp_player_intcelebrationmale@salute = false
            stopSalute()
        end
    end

    if keyPressed then
        if not IsControlPressed(0, 20) then
            keyPressed = false
        end
    end
    if Citizen.InvokeNative(0x921CE12C489C4C41, PlayerPedId()) and not mp_player_intcelebrationmale@salute then
        stopSalute()
    end
    if Citizen.InvokeNative(0x921CE12C489C4C41, PlayerPedId()) then
        if not IsPedOnFoot(PlayerPedId()) then
            stopSalute()
        end
    end
end

end)

1 Like