Skip to content
TheChatArchiveThe Chat Archive
gpt-4-0314· OpenAIAi2 WildChat-4.8M (AI2)

fivem lua is there a way to play an animation for only a certain amount of frames?

  1. User

    fivem lua is there a way to play an animation for only a certain amount of frames?

  2. Assistant

    Yes, you can play an animation for a specific number of frames using FiveM's Citizen.CreateThread function and the TaskPlayAnim native function.

    Here's a sample code to play an animation for a certain number of frames:

    local function playAnimation(ped, animDict, animName, durationInFrames)
        RequestAnimDict(animDict)
        while not HasAnimDictLoaded(animDict) do
            Citizen.Wait(0)
        end
    
        -- Calculate duration in milliseconds
        local duration = (1000 / 60) * durationInFrames -- 60 is the base frame rate
    
        TaskPlayAnim(ped, animDict, animName, 8.0, -8.0, duration, 0, 0, 0, 0, 0)
        RemoveAnimDict(animDict)
    end
    
    -- Usage example
    local ped = PlayerPedId()
    local animDict = "random@shop_tattoo"
    local animName = "insult_high"
    local framesToPlay = 100
    
    Citizen.CreateThread(function()
        playAnimation(ped, animDict, animName, framesToPlay)
    end)
    

    In this example, the playAnimation function takes a ped, an animation dictionary, an animation name, and the desired duration in frames. The function calculates the duration in milliseconds and then plays the animation using TaskPlayAnim. Don't forget to change the animDict, animName, and framesToPlay variables to suit your needs.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.

fivem lua is there a way to play an animation for only a… · The Chat Archive