Skip to content

Playing a Viral Dance ​

The pack ships no way to play a dance, so this is the page that makes it useful. Everything here goes in your resource, not in the pack.

The whole thing, working ​

lua
local function loadDict(dict, timeoutMs)
    if HasAnimDictLoaded(dict) then return true end
    if not DoesAnimDictExist(dict) then
        print(('^1[dance] no such dictionary: %s^7'):format(dict))
        return false
    end

    RequestAnimDict(dict)
    local deadline = GetGameTimer() + (timeoutMs or 5000)
    while not HasAnimDictLoaded(dict) do
        if GetGameTimer() > deadline then
            print(('^1[dance] dictionary never loaded: %s^7'):format(dict))
            return false
        end
        Wait(0)
    end
    return true
end

local function playDance(dict, clip, flags)
    local ped = PlayerPedId()
    if not loadDict(dict) then return false end
    TaskPlayAnim(ped, dict, clip, 4.0, -4.0, -1, flags or 1, 0.0, false, 0, false, 0, false)
    return true
end

-- Pink Pony Club, male version, on loop
playDance('redmorrow@emote_forestjeanwink_cmf', 'pink_pony_club', 1)

The dictionary and clip for every dance are in the dance list.

The thirteen arguments ​

RDR3's TaskPlayAnim takes thirteen parameters, and its flag values are not GTA V's. A snippet copied from a FiveM resource fails silently — no error, no animation.

#ArgumentWhat to pass
1pedPlayerPedId()
2dictThe dictionary name
3clipThe clip name — always identical to the id in this pack
4blendInDelta4.0 is a normal ease. 8.0 is snappy, 1000.0 is instant
5blendOutDelta-4.0
6duration-1 — no time limit, so a looping clip runs until stopped
7flags1 for loop. See below
8playbackRate0.0 starts at the beginning of the clip
9–13the restfalse, 0, false, 0, false

Flags ​

RDR3 eScriptedAnimFlags. These are not the GTA V values, so a flag word copied from FiveM documentation will not mean what it says there.

ValueEffect
0Play once, return to idle
1Loop — what all 23 ship as
2Hold the last frame
8Upper body only
16Secondary task slot
8 + 16 = 24Upper body, plays through once
1 + 8 + 16 = 25Upper body on loop — the player keeps walking
lua
local FLAGS = {
    once      = 0,
    loop      = 1,
    hold      = 2,
    walk      = 24,
    walk_loop = 25,
}

Leave the physics flags alone

128 (AF_OVERRIDE_PHYSICS) and 32768 (AF_USE_MOVER_EXTRACTION) are for clips that are supposed to move the character. No dance in this pack has root motion — every one stays on its spot — so neither flag has anything to do here, and passing them is a good way to make a character slide or float.

Upper-body play is a trade. Flags 25 let a character keep walking, but roughly half the choreography in these routines is in the legs. A dance that reads well upper-body-only is one whose character is mostly in the arms — check each one on screen before you offer it that way.

Picking the male or female version ​

Every dance is two dictionaries with the same clip name inside:

Maleredmorrow@emote_sodapop_cmf
Femaleredmorrow@emote_sodapop_cmf@f
Clip, in bothdiet_pepsi

So the selection is one string:

lua
local function dictFor(entry, ped)
    local b = entry.bodies
    if not b then return entry.dict end
    local want = IsPedMale(ped) and b.male or b.female
    -- fall back rather than play nothing
    return want or b.male or b.female or entry.dict
end

The fallback chain matters. IsPedMale is reliable on the standard multiplayer and story peds and unreliable on addon models. A ped whose sex the game reports wrongly should get a dance rather than none.

If your server already knows the character's sex, use that instead of the native:

lua
local function dictFor(entry, isFemaleCharacter)
    return isFemaleCharacter and entry.bodies.female or entry.bodies.male
end

For a handful of known addon peds, a lookup table is simpler than guessing:

lua
local BODY_BY_MODEL = {
    [GetHashKey('my_addon_dancer')] = 'female',
}

Playing the wrong version is not an error and will not crash anything. It looks slightly off through the shoulders and hips.

The silent failure ​

RequestAnimDict is asynchronous. Calling TaskPlayAnim on the same frame does nothing at all — no error in the console, no animation on screen, nothing to debug.

Always wait, and always bound the wait

A typo'd dictionary name never loads, so an unbounded while not HasAnimDictLoaded(dict) do Wait(0) end hangs that thread for the rest of the session. The loadDict helper at the top of this page has the timeout and the DoesAnimDictExist guard; use something shaped like it.

This is the cause of nearly every "it does nothing" report on a pack like this.

Stopping ​

lua
StopAnimTask(PlayerPedId(), dict, clip, 2.0)   -- blends out over 2.0
ClearPedTasks(PlayerPedId())                   -- hard stop, snaps
ClearPedSecondaryTask(PlayerPedId())           -- upper-body clips only

StopAnimTask is the one to use after a full-body dance — ClearPedTasks snaps the character out of it. The fourth argument is the blend-out speed and must be greater than 0.

If you played with the secondary-slot flags (24 or 25), ClearPedSecondaryTask drops the dance without disturbing whatever else the ped was doing.

Is it still running? ​

lua
if IsEntityPlayingAnim(PlayerPedId(), dict, clip, 3) then
    -- already dancing
end

The 3 is the "any" lookup type. Useful for a toggle, and for not restarting a loop that is already going.

Releasing the dictionary ​

lua
RemoveAnimDict(dict)

Safe once playback has started. Worth doing in onResourceStop, or after a dance ends, so the engine can evict it.

A worked example ​

A toggle command in your own resource. RedM has no RegisterKeyMapping, so a keybind uses RegisterRawKeymap with a Windows virtual-key code:

lua
local DANCES = {}  -- your copy of the clips.txt table
local current

local function stop()
    if not current then return end
    StopAnimTask(PlayerPedId(), current.dict, current.clip, 2.0)
    current = nil
end

RegisterCommand('dance', function(_, args)
    local id = args[1]
    if not id or id == 'stop' then return stop() end

    local entry
    for _, c in ipairs(DANCES) do
        if c.id == id then entry = c break end
    end
    if not entry then return end

    CreateThread(function()
        local dict = dictFor(entry, PlayerPedId())
        if not playDance(dict, entry.clip, 1) then return end
        current = { dict = dict, clip = entry.clip }
    end)
end, false)

RegisterRawKeymap('dance_stop', stop, 0x58, true)  -- 0x58 = X

Avoid 0x75 for a keybind

That is F6, which RDR2 uses for photo mode.

Where the DANCES table comes from is covered on The clips.txt file.

Documentation for RedMorrow. Scripts are licensed per server — redistribution is not permitted.