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", () => {
|
mp.events.add("SERVER:LoadAnimations", () => {
|
||||||
animationSync.register("Cuffed", "mp_arresting", "idle", true, true, 18);
|
animationSyncData.register("Cuffed", "mp_arresting", "idle", -1, true, 50);
|
||||||
animationSync.register("ArrestCop", "mp_arrest_paired", "cop_p2_back_right", false, false, 18);
|
animationSyncData.register("doArrest", "mp_arrest_paired", "cop_p2_back_right", 3000, false, 0);
|
||||||
animationSync.register("ArrestCrook", "mp_arrest_paired", "crook_p2_back_right", false, 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: [],
|
animations: [],
|
||||||
|
|
||||||
playAnim: function (entity, _id) {
|
register: function (name, animDict, animName, duration, loop, flag) {
|
||||||
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) {
|
|
||||||
let id = mp.game.joaat(name);
|
let id = mp.game.joaat(name);
|
||||||
|
|
||||||
if (!this.animations.hasOwnProperty(id)) {
|
if (!this.animations.hasOwnProperty(id)) {
|
||||||
@@ -42,7 +27,7 @@
|
|||||||
name: name,
|
name: name,
|
||||||
animDict: animDict,
|
animDict: animDict,
|
||||||
animName: animName,
|
animName: animName,
|
||||||
playOnStream: playOnStream,
|
duration: duration,
|
||||||
loop: loop,
|
loop: loop,
|
||||||
flag: flag
|
flag: flag
|
||||||
};
|
};
|
||||||
@@ -52,28 +37,63 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
mp.events.add("entityStreamIn", (entity) => {
|
mp.events.add("entityStreamIn", (entity) => {
|
||||||
if (entity.type === "player" && entity.animationData) {
|
if (entity.type === "player" && entity.animationData) {
|
||||||
if (!entity.animationData.playOnStream)
|
if (!entity.animationData.playOnStream)
|
||||||
return;
|
return;
|
||||||
animationSync.playAnim(entity, entity.animationData.name);
|
animationSync.playAnim(entity, mp.game.joaat(entity.animationData.name));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
mp.events.addDataHandler("AnimationData", (entity, string) => {
|
setInterval(() => {
|
||||||
let index = mp.game.joaat(string);
|
mp.players.forEachInStreamRange(
|
||||||
animationSync.stopAnim(entity, index);
|
(player) => {
|
||||||
|
if (!player.animationData)
|
||||||
let animData = animationSync.animations[index];
|
|
||||||
|
|
||||||
if (!animData)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
let { id, name, animDict, animName, playOnStream, loop, flag } = animData;
|
let index = mp.game.joaat(player.animationData.name);
|
||||||
entity.animationData = { name: name, playOnStream: playOnStream };
|
let currentAnim = animationSyncData.animations[index];
|
||||||
animationSync.playAnim(entity, id)
|
let { id, name, animDict, animName, playOnStream, loop, flag } = currentAnim;
|
||||||
mp.gui.chat.push("finish.");
|
|
||||||
mp.game.wait(100);
|
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) => {
|
||||||
|
if (string == null) {
|
||||||
|
entity.clearTasksImmediately();
|
||||||
|
entity.animationData = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
function loadAnimDict(animDict, callback) {
|
||||||
|
|||||||
@@ -35,14 +35,14 @@ namespace ReallifeGamemode.Server.Commands
|
|||||||
#region Todo
|
#region Todo
|
||||||
|
|
||||||
[Command("syncanim", "~m~Benutzung: ~s~/syncanim [animName]")]
|
[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)
|
if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true)
|
||||||
{
|
{
|
||||||
ChatService.NotAuthorized(player);
|
ChatService.NotAuthorized(player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
player.PlaySyncAnimation(animName);
|
player.SyncAnimation(animName);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("anim", "~m~Benutzung: ~s~/anim [animDict] [animName]")]
|
[Command("anim", "~m~Benutzung: ~s~/anim [animDict] [animName]")]
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace ReallifeGamemode.Server.Util
|
|||||||
{
|
{
|
||||||
public static class AnimationSync
|
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"))
|
if (!player.HasData("Animation"))
|
||||||
player.SetData("Animation", String.Empty);
|
player.SetData("Animation", String.Empty);
|
||||||
|
|||||||
Reference in New Issue
Block a user