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
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.
| # | Argument | What to pass |
|---|---|---|
| 1 | ped | PlayerPedId() |
| 2 | dict | The dictionary name |
| 3 | clip | The clip name — always identical to the id in this pack |
| 4 | blendInDelta | 4.0 is a normal ease. 8.0 is snappy, 1000.0 is instant |
| 5 | blendOutDelta | -4.0 |
| 6 | duration | -1 — no time limit, so a looping clip runs until stopped |
| 7 | flags | 1 for loop. See below |
| 8 | playbackRate | 0.0 starts at the beginning of the clip |
| 9–13 | the rest | false, 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.
| Value | Effect |
|---|---|
0 | Play once, return to idle |
1 | Loop — what all 23 ship as |
2 | Hold the last frame |
8 | Upper body only |
16 | Secondary task slot |
8 + 16 = 24 | Upper body, plays through once |
1 + 8 + 16 = 25 | Upper body on loop — the player keeps walking |
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:
| Male | redmorrow@emote_sodapop_cmf |
| Female | redmorrow@emote_sodapop_cmf@f |
| Clip, in both | diet_pepsi |
So the selection is one string:
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
endThe 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:
local function dictFor(entry, isFemaleCharacter)
return isFemaleCharacter and entry.bodies.female or entry.bodies.male
endFor a handful of known addon peds, a lookup table is simpler than guessing:
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
StopAnimTask(PlayerPedId(), dict, clip, 2.0) -- blends out over 2.0
ClearPedTasks(PlayerPedId()) -- hard stop, snaps
ClearPedSecondaryTask(PlayerPedId()) -- upper-body clips onlyStopAnimTask 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?
if IsEntityPlayingAnim(PlayerPedId(), dict, clip, 3) then
-- already dancing
endThe 3 is the "any" lookup type. Useful for a toggle, and for not restarting a loop that is already going.
Releasing the dictionary
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:
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 = XAvoid 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.