Skip to content

Commit

Permalink
Merge pull request #171 from d2kk/main
Browse files Browse the repository at this point in the history
Refactor animation functions to include optional parameters
  • Loading branch information
Booster1212 authored Oct 11, 2024
2 parents 38bb760 + 1b288f7 commit 59d5e75
Showing 1 changed file with 40 additions and 14 deletions.
54 changes: 40 additions & 14 deletions src/main/server/player/animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,63 @@ export function useAnimation(player: alt.Player) {
player.clearTasks();
}

function playInfinite(dict: string, name: string, flags: number) {
function playInfinite(
dict: string,
name: string,
flags: number,
blendInDuration: number = 8.0,
blendOutDuration: number = 8.0,
playBackRate: number = 1.0,
) {
if (!player || !player.valid) {
return;
}

player.playAnimation(dict, name, 8.0, 8.0, -1, flags, 1.0, false, false, false);
player.playAnimation(
dict,
name,
blendInDuration,
blendOutDuration,
-1,
flags,
playBackRate,
false,
false,
false,
);
}

async function playFinite(
dict: string,
name: string,
flags: number,
timeoutInMs: number,
doNotClear = false
blendInDuration: number = 8.0,
blendOutDuration: number = 8.0,
durationInMs: number = 1000,
playBackRate: number = 1.0,
doNotClear: boolean = false,
): Promise<void> {
if (!player || !player.valid) {
return;
}

if (timeoutInMs <= 0) {
timeoutInMs = 100;
}
player.playAnimation(
dict,
name,
blendInDuration,
blendOutDuration,
durationInMs,
flags,
playBackRate,
false,
false,
false,
);

player.playAnimation(dict, name, 8.0, 8.0, -1, flags, 1.0, false, false, false);
await alt.Utils.wait(timeoutInMs);

if (doNotClear) {
return;
if (!doNotClear) {
await alt.Utils.wait(durationInMs);
clear();
}

clear();
}

return {
Expand Down

0 comments on commit 59d5e75

Please sign in to comment.