Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The runningAnim function is designed to play a specific animation for a player's ped (character) in FiveM. Here's a detailed breakdown of what the function does:
The function takes four parameters: animDict (the name of the animation dictionary), animName (the name of the animation within the dictionary), duration (the duration of the animation in milliseconds), and upperbodyOnly (a boolean indicating whether the animation should only affect the upper body of the ped).
It starts by creating a new promise, animPromise, which will be used to handle the asynchronous nature of loading and playing the animation.
The function then checks if animDict and animName are strings. If not, it rejects the promise with an error message and returns.
It checks if the animation dictionary exists. If not, it rejects the promise with an error message and returns.
It sets the animation flags based on the upperbodyOnly parameter. If upperbodyOnly is true, the flags are set to 16, otherwise, they are set to 0. If the duration is -1 (indicating the animation should loop indefinitely), the flags are set to 49.
It gets the player's ped and the current game time.
It enters a loop where it requests the animation dictionary and waits until it's loaded. If the dictionary isn't loaded within 5 seconds, it rejects the promise with an error message and returns.
Once the animation dictionary is loaded, it plays the animation on the player's ped using TaskPlayAnim.
It waits for a short time to allow the animation to start, then gets the duration of the animation using GetAnimDuration.
If the animation duration is 0 (indicating the animation doesn't exist), it rejects the promise with an error message and returns.
It calculates the full duration of the animation in milliseconds and sets the wait time to the minimum of the provided duration and the full duration.
It waits for the duration of the animation, then removes the animation dictionary.
Finally, it resolves the promise with the current time, indicating when the animation concluded.