TaskPlayAnimation bug works on lua but not on js

General guideline is: if you ‘need help’, do not post here. Post in the right support section instead.

WARNING: THIS IS NOT A HELP SECTION

If you post here without knowing what you’re doing you’ll most likely get suspended. You should probably instead post in:


For a good bug report you should probably include:

  1. Client (production/canary) and FXServer version:
  • Client is on production version 4558
  • FXServer “FXServer-master SERVER v1.0.0.4574 win32”
  1. What you expected to happen
  • An Animation to start playing
  1. What actually happens
  • Nothing
  1. Category of bug (eg. client, server, weapons, peds, native)
  • native, peds
  1. Reproducible steps, preferably with example script(s)
  • I have given a reproduction script and the expected behavior is to be able to call the TaskPlayAnim from js but nothing happens. The code is identical I don’t see any differences.
  • animation-bug.7z (738 Bytes)

If anybody can answer me why this is happening and is it a problem from me or FiveM. Ty for your help and wish you all the best

This is not a bug. You forgot to add await for wait function to actually wait for promise to be resolved.
Use await wait(100) and not just wait(100).

1 Like

I fixed it up

const wait = (ms) => {
     return new Promise((resolve, reject) => {
          setTimeout(resolve, ms)
     })
}

const animDict = async (dict) => {
     RequestAnimDict(dict)
     while (!HasAnimDictLoaded(dict)) {
          await wait(10)
     }
}

const animation = async () => {
     console.log('Animation from js')
     await animDict('mp_character_creation@lineup@male_a')
     await wait(100)
     TaskPlayAnim(PlayerPedId(), 'mp_character_creation@lineup@male_a', 'intro', 1.0, 1.0, 5900, 0, 1, 0, 0, 0)
     await wait(5700)
     await animDict('mp_character_creation@customise@male_a')
     await wait(100)
     TaskPlayAnim(PlayerPedId(), 'mp_character_creation@customise@male_a', 'loop', 1.0, 1.0, -1, 0, 1, 0, 0, 0)
}

RegisterCommand('animjs', animation, false)

but it’s still the same but the same code in Lua works fine if you can find any other mistakes it will be appreciated

Another note the server-side RPC Native of TaskPlayAnim is the same nothing happens when you call it from JS but it works when its called from Lua

You passed invalid argument. In your case, you’re passing 1 (integer) as playbackRate which is float. If you pass 0 it will work. Read argument types carefully.

This should however not lead to 1 as int, but 1.0001 or so as float:

function _fv(flt) {
	return (flt === 0.0) ? flt : (flt + 0.0000001);
}
global.TaskPlayAnim = function (ped, animDictionary, animationName, blendInSpeed, blendOutSpeed, duration, flag, playbackRate, lockX, lockY, lockZ) {
	return _in(0xea47fe37, 0x19165b94, ped, _ts(animDictionary), _ts(animationName), _fv(blendInSpeed), _fv(blendOutSpeed), duration, flag, _fv(playbackRate), lockX, lockY, lockZ);
};

Yeah, playbackRate as 1.0 literally means play anim at the it’s end.

Yeah, but that’s not related to types. :stuck_out_tongue:

… oh, I see.

TaskPlayAnim(PlayerPedId(), "mp_character_creation@customise@male_a", "loop", 1.0, 1.0, -1, 0, 1, 0, 0, 0)

Here’s their Lua code and Lua doesn’t do an implied float conversion for float types, so the bug is rather that this works in Lua, not that this doesn’t work in JS.

function Global.TaskPlayAnim(ped, animDictionary, animationName, blendInSpeed, blendOutSpeed, duration, flag, playbackRate, lockX, lockY, lockZ)
	return _in(0xEA47FE3719165B94, ped, _ts(animDictionary), _ts(animationName), blendInSpeed, blendOutSpeed, duration, flag, playbackRate, lockX, lockY, lockZ)
end

Alright, I got it the playbackRate is to choose from when the animation should start in 0.0 is the start time and 1.0 is the end and because I was giving it 1 it was starting at the end and it works in Lua because in the compiler for the Lua natives hasn’t got a float conversion but the JS has it. To you for help me understand it and being here for me. Wish you all the best keep up the good work.