From 8f225699c6ca7cc3554fdf202b68b5da947c7d3f Mon Sep 17 00:00:00 2001 From: kookroach Date: Mon, 5 Apr 2021 23:40:11 +0200 Subject: [PATCH] Add AnimationSync --- ReallifeGamemode.Client/index.ts | 13 +- ReallifeGamemode.Client/util/animationSync.ts | 85 ++++++++++++ .../Commands/AdminCommands.cs | 126 ++++++++++-------- ReallifeGamemode.Server/Util/AnimationSync.cs | 34 +++++ 4 files changed, 196 insertions(+), 62 deletions(-) create mode 100644 ReallifeGamemode.Client/util/animationSync.ts create mode 100644 ReallifeGamemode.Server/Util/AnimationSync.cs diff --git a/ReallifeGamemode.Client/index.ts b/ReallifeGamemode.Client/index.ts index 70a08959..6dd166b9 100644 --- a/ReallifeGamemode.Client/index.ts +++ b/ReallifeGamemode.Client/index.ts @@ -7,14 +7,13 @@ import { IGame } from './game'; import RageGame from './core/rage-mp/game'; - var inMenu: boolean = false; let globalData: IGlobalData = { InTuning: false, HideGui: false, InChat: false, - LoggedIn: false, + LoggedIn: false, get InMenu(): boolean { return inMenu; @@ -224,7 +223,6 @@ refuseCollector(); import PedCreator from './Ped/PedCreator'; PedCreator(); - import attachmentManager from './util/attachmentMngr'; attachmentManager(game); @@ -235,14 +233,12 @@ import bankMenuHandle from './Interaction/bankmenu'; import InputHelper from './inputhelper'; bankMenuHandle(globalData); - import ahelp from './Gui/ahelp'; ahelp(globalData); import Introduction from './Gui/introduction'; Introduction(globalData); - import userhelp from './Gui/userhelp'; userhelp(globalData); @@ -252,6 +248,9 @@ drivingschool(globalData); import gangwarHandle from './util/Gangwar'; gangwarHandle(globalData); +import animationSync from './util/animationSync'; +animationSync(); + require('./Gui/policedepartment'); require('./Gui/helptext'); @@ -262,6 +261,4 @@ interface VehicleData { export { VehicleData -} - - +} \ No newline at end of file diff --git a/ReallifeGamemode.Client/util/animationSync.ts b/ReallifeGamemode.Client/util/animationSync.ts new file mode 100644 index 00000000..3f76cb63 --- /dev/null +++ b/ReallifeGamemode.Client/util/animationSync.ts @@ -0,0 +1,85 @@ +export default function animationSync() { + mp.events.add("SERVER:LoadAnimations", () => { + animationSync.register("Cuffed", "mp_arresting", "idle", true, true, 0); + animationSync.register("ArrestCop", "mp_arrest_paired", "cop_p2_back_right", false, false, 0); + animationSync.register("ArrestCrook", "mp_arrest_paired", "crook_p2_back_right", false, false, 0); + }); + + const animationSync = + { + 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), 1, !1, !1, !1) + }); + entity.animationData = { name: name, playOnStream: playOnStream }; + } + }, + stopAnim: function (entity: PlayerMp) { + if (!entity.animationData) + return; + + var currAnim = this.animations.find(anim => anim.name == entity.animationData.name); + 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); + + if (!this.animations.hasOwnProperty(id)) { + this.animations[id] = + { + id: id, + name: name, + animDict: animDict, + animName: animName, + playOnStream: playOnStream, + 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, entity.animationData.name); + } + }); + + mp.events.addDataHandler("AnimationData", (entity: PlayerMp, string) => { + let data = string ? string : ""; + + animationSync.stopAnim(entity); + + let animData = animationSync.animations.find(anim => anim.name == data); + if (!animData) + return; + + let { id, name, animDict, animName, playOnStream, loop, flag } = animData; + entity.animationData = { name: name, playOnStream: playOnStream }; + animationSync.playAnim(entity, id) + }); + + 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) + } +} \ No newline at end of file diff --git a/ReallifeGamemode.Server/Commands/AdminCommands.cs b/ReallifeGamemode.Server/Commands/AdminCommands.cs index 551d092d..76e6afc5 100644 --- a/ReallifeGamemode.Server/Commands/AdminCommands.cs +++ b/ReallifeGamemode.Server/Commands/AdminCommands.cs @@ -34,6 +34,17 @@ namespace ReallifeGamemode.Server.Commands { #region Todo + [Command("syncanim", "~m~Benutzung: ~s~/anim [animName]")] + public void CmdSncAnim(Player player, string animName) + { + if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true) + { + ChatService.NotAuthorized(player); + return; + } + player.PlaySyncAnimation(animName); + } + [Command("anim", "~m~Benutzung: ~s~/anim [animDict] [animName]")] public void CmdAnim(Player player, string animDict, string animName) { @@ -43,11 +54,8 @@ namespace ReallifeGamemode.Server.Commands return; } NAPI.Player.PlayPlayerAnimation(player, (int)(AnimationFlags.Loop | AnimationFlags.AllowPlayerControl | AnimationFlags.Cancellable), animDict, animName); - } - - [Command("eat", "~m~Benutzung: ~s~/eat [Item]")] public void CmdAdminEat(Player player, string item) { @@ -144,36 +152,38 @@ namespace ReallifeGamemode.Server.Commands #region ahelp - /* [Command("ahelp", "~m~Benutzung: ~s~/ahelp")] - public void CmdAdminHelp(Player player) - { - if (!player.GetUser()?.IsAdmin(AdminLevel.MAPPING) ?? true) - { - ChatService.NotAuthorized(player); - return; - } - else - { - switch (player.GetUser().AdminLevel) - { - case AdminLevel.MAPPING: - ChatService.SendMessage(player, "~b~ " + "/team, /tc, /position"); - break; + /* [Command("ahelp", "~m~Benutzung: ~s~/ahelp")] + public void CmdAdminHelp(Player player) + { + if (!player.GetUser()?.IsAdmin(AdminLevel.MAPPING) ?? true) + { + ChatService.NotAuthorized(player); + return; + } + else + { + switch (player.GetUser().AdminLevel) + { + case AdminLevel.MAPPING: + ChatService.SendMessage(player, "~b~ " + "/team, /tc, /position"); + break; + + case AdminLevel.SUPPORTER: + player.TriggerEvent("showShelp"); + break; + + case AdminLevel.ADMIN: + player.TriggerEvent("showAhelp"); + break; + } + } + } + */ - case AdminLevel.SUPPORTER: - player.TriggerEvent("showShelp"); - break; - - case AdminLevel.ADMIN: - player.TriggerEvent("showAhelp"); - break; - } - } - } - */ #endregion ahelp #region Mapping / Entwicklung + [Command("team", "~m~Benutzung: ~s~/team")] public void CmdAdminTeam(Player player) { @@ -234,7 +244,7 @@ namespace ReallifeGamemode.Server.Commands switch (typ.ToLower()) { case "ip": - if(player.HasData("togip")) + if (player.HasData("togip")) { player.ResetData("togip"); player.SendNotification("~g~[Info]~w~ Ip´s werden nun ausgeblendet."); @@ -258,6 +268,7 @@ namespace ReallifeGamemode.Server.Commands player.SendNotification("~g~[Info]~w~ Deathlogs werden nun angezeigt."); } break; + case "lc": if (player.HasData("toglc")) { @@ -299,6 +310,7 @@ namespace ReallifeGamemode.Server.Commands } user.SetBlipAndNametagColor(); } + [Command("aduty", "~m~Benutzung: ~s~/aduty")] public void CmdAdminAduty(Player player) { @@ -314,11 +326,10 @@ namespace ReallifeGamemode.Server.Commands ChatService.Broadcast("~g~[SUPPORT] " + player.Name + " hat sich zum Support angemeldet"); player.TriggerEvent("toggleADutyMode", true); - } else { - if(player.GetData("SAdminduty")) + if (player.GetData("SAdminduty")) { CmdAdminTSupport(player); } @@ -338,7 +349,7 @@ namespace ReallifeGamemode.Server.Commands ChatService.NotAuthorized(player); return; } - + message = Regex.Replace(message, "(~[a-zA-Z]~)|(!{(.*)})", ""); message = Regex.Replace(message, "#([0-9A-Fa-f]{6})", m => "!{" + m.Groups[0].Value + "}"); @@ -467,8 +478,6 @@ namespace ReallifeGamemode.Server.Commands target.Kick(); ChatService.BroadcastAdmin("~y~SKICK: ~w~" + targetPlayername + " wurde von " + player.GetUser().AdminLevel.GetName() + " " + adminPlayername + " gekickt: " + reason, AdminLevel.SUPPORTER); - - } [Command("clearchat", "~m~Benutzung: ~s~/clearchat")] @@ -780,12 +789,10 @@ namespace ReallifeGamemode.Server.Commands string adminPlayername = NAPI.Player.GetPlayerName(player); ChatService.SendMessage(target, "~r~KICKINFO: ~w~Du wurdest von " + adminPlayername + " vom Server gekickt: " + reason); - + target.Kick(); ChatService.Broadcast("~y~INFO: ~w~" + targetPlayername + " wurde von " + player.GetUser().AdminLevel.GetName() + " " + adminPlayername + " gekickt: " + reason); - - } [Command("warn", "~m~Benutzung: ~s~/warn [Player] [Grund]", GreedyArg = true)] @@ -810,8 +817,8 @@ namespace ReallifeGamemode.Server.Commands using (var dbContext = new DatabaseContext()) { User userwarn = player.GetUser(dbContext); - - userwarn.warn ++; + + userwarn.warn++; dbContext.SaveChanges(); if (userwarn.warn >= 3) { @@ -949,6 +956,7 @@ namespace ReallifeGamemode.Server.Commands else player.Position = new Vector3(p.X, p.Y, p.Z); } } + [Command("destroyped", "~m~Benutzung: ~s~/destroyped [PedNr]")] public void CmdAdminAddPPed(Player player, int PedNr) { @@ -960,6 +968,7 @@ namespace ReallifeGamemode.Server.Commands player.TriggerEvent("CLIENT:DestroyPed", PedNr); //NAPI.Ped.CreatePed(PedHash.Bankman, new Vector3(player.Position.X, player.Position.Y, player.Position.Z), player.Heading, dimension); } + [Command("addpped", "~m~Benutzung: ~s~/addpped [PedNr] [model] [dimension] [Dynamic] [Freezed] [Collision(0-3)] [Weapon] [AttackProof] [Fire/Explosion-Proof] [DrownProof]")] public void CmdAdminAddPPed(Player player, Array PedNr, string model, uint dimension = 0, bool dynamic = false, bool freeze = false, int collision = 0, string weapon = "none", bool attackproof = false, bool fireexplosionproof = false, bool drownproof = false) { @@ -971,6 +980,7 @@ namespace ReallifeGamemode.Server.Commands player.TriggerEvent("CLIENT:AddPed", PedNr, model, player.Position.X, player.Position.Y, player.Position.Z, player.Heading, dimension, dynamic, freeze, collision, weapon, attackproof, fireexplosionproof, drownproof); //NAPI.Ped.CreatePed(PedHash.Bankman, new Vector3(player.Position.X, player.Position.Y, player.Position.Z), player.Heading, dimension); } + [Command("addmped", "~m~Benutzung: ~s~/addmped [model] [dimension]")] public void CmdAdminAddMPed(Player player, int model, uint dimension = 0) { @@ -982,6 +992,7 @@ namespace ReallifeGamemode.Server.Commands player.TriggerEvent("CLIENT:AddPedModel", model, player.Position.X, player.Position.Y, player.Position.Z, player.Heading, dimension); //NAPI.Ped.CreatePed(PedHash.Bankman, new Vector3(player.Position.X, player.Position.Y, player.Position.Z), player.Heading, dimension); } + [Command("addgped", "~m~Benutzung: ~s~/addgped")] public void CmdAdminAddGPed(Player player, int model, uint dimension = 0) { @@ -995,6 +1006,7 @@ namespace ReallifeGamemode.Server.Commands //Peter.freezePosition(true); } + [Command("addgpedmore", "~m~Benutzung: ~s~/addgpedMore")] public void CmdAdminAddGPedMore(Player player, int model, uint dimension = 0) { @@ -1256,7 +1268,7 @@ namespace ReallifeGamemode.Server.Commands foreach (Vehicle v in vehiclesInRange) { ServerVehicle serverVehicle = VehicleManager.GetServerVehicleFromVehicle(v); - if(serverVehicle == null) + if (serverVehicle == null) { VehicleManager.DeleteVehicle(v); v.Trailer?.Delete(); @@ -1462,7 +1474,7 @@ namespace ReallifeGamemode.Server.Commands } ChatService.SendMessage(target, "!{#8181E9}Deine Akte wurde vom Admin " + player.Name + " gelöscht. Grund: " + reason); ChatService.BroadcastFaction("!{#8181E9}HQ: Die Akte von " + target.Name + " wurde vom Admin " + player.Name + " gelöscht. Grund: " + reason + ".", new List() { 1, 3 }); - + target.TriggerEvent("jailTime", 0); targetUser.Wanteds = 0; @@ -1687,6 +1699,7 @@ namespace ReallifeGamemode.Server.Commands #endregion Admin #region ALevel1337 + /*NUR ZUM TESTEN [Command("fakedeath", "~m~Benutzung:~s~ /fakedeath")] public void CmdAdmFakeDeath(Player player) @@ -1718,7 +1731,7 @@ namespace ReallifeGamemode.Server.Commands ChatService.NotAuthorized(player); return; } - player.SetSharedData("blipColor", blipId); + player.SetSharedData("blipColor", blipId); } [Command("setsvar", "~m~Benutzung:~s~ /setsvar [ID] [WERT]")] @@ -1996,7 +2009,7 @@ namespace ReallifeGamemode.Server.Commands { if (!managedPlayer.IsLoggedIn()) return; managedPlayer.GetUser(dbContext).Wage += wage; - + ChatService.SendMessage(managedPlayer, "~b~Admin " + player.Name + " hat im Radius von " + radius + " den Verdienst um $" + wage + " erhöht."); dbContext.SaveChanges(); } @@ -2130,12 +2143,14 @@ namespace ReallifeGamemode.Server.Commands player.SendChatMessage("Modifier steht auf" + modifier); player.TriggerEvent("SERVER:WeaponModifier2", player, modifier, 1); } + [Command("wepmmod", "~m~Benutzung: ~s~/wepmmod [Variable]")] public void CmdWeaponMeeleModifier(Player player, float modifier) { player.SendChatMessage("MeeleModifier steht auf" + modifier); player.TriggerEvent("SERVER:WeaponModifier2", player, 1, modifier); } + [Command("gotocp", "~m~Benutzung: ~s~/gotocp")] public void CmdAdminGotocp(Player admin) { @@ -2379,7 +2394,7 @@ namespace ReallifeGamemode.Server.Commands NAPI.Player.SpawnPlayer(managedPlayer, managedPlayer.Position); managedPlayer.Health = 100; - Medic.delReviveTask(managedPlayer); + Medic.delReviveTask(managedPlayer); } ChatService.SendMessage(player, "~b~Du hast " + playerRevided + " Spieler wiederbelebt."); @@ -2452,10 +2467,10 @@ namespace ReallifeGamemode.Server.Commands { ChatService.PlayerNotFound(player); return; - } + } - using (var dbContext = new DatabaseContext()) - { + using (var dbContext = new DatabaseContext()) + { Faction f = dbContext.Factions.FirstOrDefault(x => x.Id == faction); if (f == null) { @@ -2663,6 +2678,7 @@ namespace ReallifeGamemode.Server.Commands player.SetIntoVehicle(vehicle, 0); } break; + case "noobvehicle": if (player.IsInVehicle) { @@ -3056,6 +3072,7 @@ namespace ReallifeGamemode.Server.Commands player.TriggerEvent("manageFactionRanks", json); } } + [Command("setdoor", "~m~Benutzung: ~s~/setdoor [open/shut] [Tür] [Boolean:Permanet] [Boolean:Lose]")] public void CmdAdminSetDoorOpen(Player player, string status, int door, bool permanent = false, bool lose = true) { @@ -3080,6 +3097,7 @@ namespace ReallifeGamemode.Server.Commands } } } + [Command("aplaysound", "~m~Benutzung: ~s~/aplaysound [Dateiname] [mp3/wav] [volume 0.0 - 100.0]", Alias = "aps")] public void CmdAdminPlaySound(Player player, string sound, string typ, double volume = 100) { @@ -3090,6 +3108,7 @@ namespace ReallifeGamemode.Server.Commands } player.TriggerEvent("CLIENT:PlaySound", sound, typ, volume); } + [Command("astopsound", "~m~Benutzung: ~s~/astopsound", Alias = "ass")] public void CmdAdminStopSound(Player player) { @@ -3100,6 +3119,7 @@ namespace ReallifeGamemode.Server.Commands } player.TriggerEvent("CLIENT:StopSound"); } + [Command("aspeed", "~m~Benutzung: ~s~/aspeed [Modifier1] [Modifier2]")] //TODO: Überarbeiten ?? SetPlayerVelocity ?? public void CmdAdminAspeed(Player player, int modifier, int modifier2 = 1) { @@ -3521,13 +3541,13 @@ namespace ReallifeGamemode.Server.Commands public void CmdAdminCheckStats(Player player, string nameOrId) { User user = player.GetUser(); - if(!user.IsAdmin(AdminLevel.SUPPORTER)) + if (!user.IsAdmin(AdminLevel.SUPPORTER)) { ChatService.NotAuthorized(player); } Player target = PlayerService.GetPlayerByNameOrId(nameOrId); - if(target == null || !target.IsLoggedIn()) + if (target == null || !target.IsLoggedIn()) { ChatService.PlayerNotFound(player); return; @@ -3543,7 +3563,6 @@ namespace ReallifeGamemode.Server.Commands ChatService.SendMessage(player, $"Stats von {target.Name} - HandMoney: {handmoney.ToMoneyString()}, BankMoney: {bankmoney.ToMoneyString()}, DriverLicense: {driverLicense.ToString()}, BikeLicense: {bikeLicense.ToString()}, FlyingLicense: {flyingLicense.ToString()}, WeaponLicense: {weaponLicense.ToString()}"); } - #endregion ALevel1337 #region ALevel1338 @@ -3662,9 +3681,8 @@ namespace ReallifeGamemode.Server.Commands { return; } - if(player.HasData("Adminduty") && player.GetData("Adminduty")) - player.TriggerEvent("ADMIN:NoClip"); + if (player.HasData("Adminduty") && player.GetData("Adminduty")) + player.TriggerEvent("ADMIN:NoClip"); } - } } diff --git a/ReallifeGamemode.Server/Util/AnimationSync.cs b/ReallifeGamemode.Server/Util/AnimationSync.cs new file mode 100644 index 00000000..6977da7b --- /dev/null +++ b/ReallifeGamemode.Server/Util/AnimationSync.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using GTANetworkAPI; + +namespace ReallifeGamemode.Server.Util +{ + public static class AnimationSync + { + public static void PlaySyncAnimation(this Player player, string animationName) + { + if (!player.HasData("Animation")) + player.SetData("Animation", String.Empty); + + string currentAnimation = player.GetData("Animation"); + string newAnimation = animationName; + + if (currentAnimation.Equals(newAnimation)) + return; + + player.SetSharedData("AnimationData", newAnimation); + } + + public static void ClearAnimation(this Player player) + { + if (!player.HasData("Animation")) + return; + + player.ResetData("Animation"); + player.ResetSharedData("AnimationData"); + } + } +}