ja
This commit is contained in:
@@ -1,38 +1,23 @@
|
||||
export default function animationSync() {
|
||||
import { setInterval } from "timers";
|
||||
|
||||
export default function animationSync() {
|
||||
mp.events.add("SERVER:LoadAnimations", () => {
|
||||
animationSync.register("Cuffed", "mp_arresting", "idle", true, true, 18);
|
||||
animationSync.register("ArrestCop", "mp_arrest_paired", "cop_p2_back_right", false, false, 18);
|
||||
animationSync.register("ArrestCrook", "mp_arrest_paired", "crook_p2_back_right", false, false, 0);
|
||||
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 animationSync =
|
||||
const pairData = [
|
||||
{ from: "getArrest", transitionTo: "Cuffed" },
|
||||
];
|
||||
|
||||
const animationSyncData =
|
||||
{
|
||||
animations: [],
|
||||
|
||||
playAnim: function (entity, _id) {
|
||||
if (this.animations.hasOwnProperty(_id)) {
|
||||
let currentAnim = this.animations[_id];
|
||||
let { id, name, animDict, animName, playOnStream, loop, flag } = currentAnim;
|
||||
loadAnimDict(animDict, function () {
|
||||
mp.players.exists(entity) && 0 !== entity.handle && entity.taskPlayAnim(animDict, animName, 1, 0, -1, parseInt(flag), 0, !1, !1, !1)
|
||||
});
|
||||
entity.animationData = { name: name, playOnStream: playOnStream };
|
||||
}
|
||||
},
|
||||
stopAnim: function (entity, index) {
|
||||
if (!entity.animationData)
|
||||
return;
|
||||
|
||||
var currAnim = this.animations[index];
|
||||
if (currAnim) {
|
||||
let { id, name, animDict, animName, playOnStream, loop, flag } = currAnim;
|
||||
|
||||
entity.stopAnimTask(animDict, animName, 3);
|
||||
entity.animationData = null;
|
||||
}
|
||||
},
|
||||
|
||||
register: function (name, animDict, animName, playOnStream, loop, flag) {
|
||||
register: function (name, animDict, animName, duration, loop, flag) {
|
||||
let id = mp.game.joaat(name);
|
||||
|
||||
if (!this.animations.hasOwnProperty(id)) {
|
||||
@@ -42,7 +27,7 @@
|
||||
name: name,
|
||||
animDict: animDict,
|
||||
animName: animName,
|
||||
playOnStream: playOnStream,
|
||||
duration: duration,
|
||||
loop: loop,
|
||||
flag: flag
|
||||
};
|
||||
@@ -52,28 +37,63 @@
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
mp.events.add("entityStreamIn", (entity) => {
|
||||
if (entity.type === "player" && entity.animationData) {
|
||||
if (!entity.animationData.playOnStream)
|
||||
return;
|
||||
animationSync.playAnim(entity, entity.animationData.name);
|
||||
animationSync.playAnim(entity, mp.game.joaat(entity.animationData.name));
|
||||
}
|
||||
});
|
||||
*/
|
||||
|
||||
setInterval(() => {
|
||||
mp.players.forEachInStreamRange(
|
||||
(player) => {
|
||||
if (!player.animationData)
|
||||
return;
|
||||
|
||||
let index = mp.game.joaat(player.animationData.name);
|
||||
let currentAnim = animationSyncData.animations[index];
|
||||
let { id, name, animDict, animName, playOnStream, loop, flag } = currentAnim;
|
||||
|
||||
if (player.animationData.loop && !player.isPlayingAnim(animDict, animName, 3)) {
|
||||
loadAnimDict(animDict, function () {
|
||||
mp.players.exists(player) && 0 !== player.handle && player.taskPlayAnim(animDict, animName, 8, 1, -1, parseInt(flag), 0, !1, !1, !1)
|
||||
});
|
||||
}
|
||||
});
|
||||
}, 100);
|
||||
|
||||
mp.events.addDataHandler("AnimationData", (entity, string) => {
|
||||
let index = mp.game.joaat(string);
|
||||
animationSync.stopAnim(entity, index);
|
||||
|
||||
let animData = animationSync.animations[index];
|
||||
|
||||
if (!animData)
|
||||
if (string == null) {
|
||||
entity.clearTasksImmediately();
|
||||
entity.animationData = null;
|
||||
return;
|
||||
}
|
||||
|
||||
let { id, name, animDict, animName, playOnStream, loop, flag } = animData;
|
||||
entity.animationData = { name: name, playOnStream: playOnStream };
|
||||
animationSync.playAnim(entity, id)
|
||||
mp.gui.chat.push("finish.");
|
||||
mp.game.wait(100);
|
||||
while (true) {
|
||||
let index = mp.game.joaat(string);
|
||||
let animData = animationSyncData.animations[index];
|
||||
|
||||
if (!animData)
|
||||
break;
|
||||
|
||||
let { id, name, animDict, animName, duration, loop, flag } = animData;
|
||||
entity.animationData = { name: name, loop: loop };
|
||||
|
||||
loadAnimDict(animDict, function () {
|
||||
mp.players.exists(entity) && 0 !== entity.handle && entity.taskPlayAnim(animDict, animName, 1, 0, -1, parseInt(flag), 0, !1, !1, !1)
|
||||
});
|
||||
mp.game.wait(duration);
|
||||
|
||||
let pair = pairData.find(pair => pair.from == name);
|
||||
if (!pair)
|
||||
break;
|
||||
|
||||
string = pair.transitionTo;
|
||||
mp.gui.chat.push("transition to " + string);
|
||||
}
|
||||
});
|
||||
|
||||
function loadAnimDict(animDict, callback) {
|
||||
|
||||
@@ -35,14 +35,14 @@ namespace ReallifeGamemode.Server.Commands
|
||||
#region Todo
|
||||
|
||||
[Command("syncanim", "~m~Benutzung: ~s~/syncanim [animName]")]
|
||||
public void CmdSncAnim(Player player, string animName)
|
||||
public void CmdSncAnim(Player player, string animName = null)
|
||||
{
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
player.PlaySyncAnimation(animName);
|
||||
player.SyncAnimation(animName);
|
||||
}
|
||||
|
||||
[Command("anim", "~m~Benutzung: ~s~/anim [animDict] [animName]")]
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace ReallifeGamemode.Server.Util
|
||||
{
|
||||
public static class AnimationSync
|
||||
{
|
||||
public static void PlaySyncAnimation(this Player player, string animationName)
|
||||
public static void SyncAnimation(this Player player, string animationName)
|
||||
{
|
||||
if (!player.HasData("Animation"))
|
||||
player.SetData("Animation", String.Empty);
|
||||
|
||||
Reference in New Issue
Block a user