114 lines
4.0 KiB
TypeScript
114 lines
4.0 KiB
TypeScript
export default function animationSync() {
|
|
let blockInput = false;
|
|
|
|
mp.events.add("SERVER:LoadAnimations", () => {
|
|
animationSyncData.register("Cuffed", "mp_arresting", "idle", -1, true, 50);
|
|
animationSyncData.register("doArrest", "mp_arrest_paired", "cop_p2_back_right", 3000, false, 0);
|
|
animationSyncData.register("getArrest", "mp_arrest_paired", "crook_p2_back_right", 3760, false, 0);
|
|
animationSyncData.register("doUncuff", "mp_arresting", "a_uncuff", 5500, false, 0);
|
|
animationSyncData.register("getUncuff", "mp_arresting", "b_uncuff", 5500, false, 0);
|
|
});
|
|
|
|
const pairData = [
|
|
{ from: "getArrest", transitionTo: "Cuffed" },
|
|
|
|
];
|
|
|
|
const animationSyncData =
|
|
{
|
|
animations: [],
|
|
|
|
register: function (name, animDict, animName, duration, loop, flag) {
|
|
let id = mp.game.joaat(name);
|
|
|
|
if (!this.animations.hasOwnProperty(id)) {
|
|
this.animations[id] =
|
|
{
|
|
id: id,
|
|
name: name,
|
|
animDict: animDict,
|
|
animName: animName,
|
|
duration: duration,
|
|
loop: loop,
|
|
flag: flag
|
|
};
|
|
} else {
|
|
mp.game.graphics.notify("Animation Sync Error: ~r~Duplicate Entry");
|
|
}
|
|
}
|
|
};
|
|
|
|
/*
|
|
mp.events.add("entityStreamIn", (entity) => {
|
|
if (entity.type === "player" && entity.animationData) {
|
|
if (!entity.animationData.playOnStream)
|
|
return;
|
|
animationSync.playAnim(entity, mp.game.joaat(entity.animationData.name));
|
|
}
|
|
});
|
|
*/
|
|
|
|
setInterval(() => {
|
|
mp.players.forEachInStreamRange(
|
|
(player) => {
|
|
if (!player.getVariable("AnimationData"))
|
|
return;
|
|
|
|
let index = mp.game.joaat(player.getVariable("AnimationData"));
|
|
let currentAnim = animationSyncData.animations[index];
|
|
let { id, name, animDict, animName, duration, loop, flag } = currentAnim;
|
|
|
|
if (loop && !player.isPlayingAnim(animDict, animName, 3)) {
|
|
loadAnimDict(animDict, function () {
|
|
mp.players.exists(player) && 0 !== player.handle && player.taskPlayAnim(animDict, animName, 8, 1, duration, parseInt(flag), 0, !1, !1, !1)
|
|
});
|
|
if (player == mp.players.local) { //block player from using LMB to attack
|
|
blockInput = true;
|
|
}
|
|
}
|
|
});
|
|
}, 100);
|
|
|
|
mp.events.addDataHandler("AnimationData", (entity: PlayerMp, string) => {
|
|
entity.clearTasksImmediately();
|
|
blockInput = false;
|
|
if (string == null) {
|
|
return;
|
|
}
|
|
|
|
let index = mp.game.joaat(string);
|
|
|
|
if (!animationSyncData.animations.hasOwnProperty(index)) return;
|
|
|
|
let animData = animationSyncData.animations[index];
|
|
|
|
let { id, name, animDict, animName, duration, loop, flag } = animData;
|
|
|
|
loadAnimDict(animDict, function () {
|
|
mp.players.exists(entity) && 0 !== entity.handle && entity.taskPlayAnim(animDict, animName, 8, 1, duration, parseInt(flag), 0, !1, !1, !1)
|
|
});
|
|
|
|
let pair = pairData.find(pair => pair.from == string);
|
|
if (!pair)
|
|
return;
|
|
|
|
let a = setInterval(function () {
|
|
mp.events.callRemote("CLIENT:AnimPairTransition", entity, pair.transitionTo);
|
|
clearInterval(a);
|
|
}, duration);
|
|
});
|
|
|
|
mp.events.add("render", () => {
|
|
if (blockInput) {
|
|
mp.game.controls.disableControlAction(32, 24, true);
|
|
}
|
|
});
|
|
|
|
function loadAnimDict(animDict, callback) {
|
|
if (mp.game.streaming.hasAnimDictLoaded(animDict)) return void callback();
|
|
mp.game.streaming.requestAnimDict(animDict);
|
|
let c = setInterval(function () {
|
|
mp.game.streaming.hasAnimDictLoaded(animDict) && (clearInterval(c), callback())
|
|
}, 100)
|
|
}
|
|
} |