From 5cea81de72057d6c64fa391d3a14b1205843c53d Mon Sep 17 00:00:00 2001 From: kookroach Date: Wed, 7 Apr 2021 03:17:02 +0200 Subject: [PATCH] Finish Cuff using AnimationSync + Added Command /cuff for LSPD and FIB (Wanteds can also be cuffed using the Interaction key). + Added Command /syncanim for Supporter * Player can now use CTRL + H to hup (/hup still usable) * Cuffs break after two minutes. TODO: - Players in Animation cannot enter Vehicle as driver neither can drive them. - Cuffed players will not loose their cuffs after reconnect. --- ReallifeGamemode.Client/util/animationSync.ts | 7 ++ .../util/attachmentMngr.ts | 2 +- ReallifeGamemode.Client/util/weapondamage.ts | 1 + .../Commands/AdminCommands.cs | 27 ------- .../Commands/FactionCommands.cs | 75 +++++++++++++------ .../Commands/UserCommands.cs | 1 - ReallifeGamemode.Server/Events/Key.cs | 32 +++++++- .../Extensions/ClientExtension.cs | 5 ++ .../Managers/PositionManager.cs | 2 + 9 files changed, 97 insertions(+), 55 deletions(-) diff --git a/ReallifeGamemode.Client/util/animationSync.ts b/ReallifeGamemode.Client/util/animationSync.ts index 53abce1f..f0e36c15 100644 --- a/ReallifeGamemode.Client/util/animationSync.ts +++ b/ReallifeGamemode.Client/util/animationSync.ts @@ -96,6 +96,13 @@ mp.players.exists(entity) && 0 !== entity.handle && entity.taskPlayAnim(animDict, animName, 1, 0, duration, parseInt(flag), 0, !1, !1, !1) }); + let b = setInterval(function () { + mp.events.callRemote("CLIENT:ClearAnimationData", entity); + if (name == "Cuffed" || name == "cuffed") + mp.events.call("renderTextOnScreen", "Handschellen gebrochen."); + clearInterval(b); + }, 120000); + if (!loop) { let a = setInterval(function () { mp.events.callRemote("CLIENT:ClearAnimationData", entity); diff --git a/ReallifeGamemode.Client/util/attachmentMngr.ts b/ReallifeGamemode.Client/util/attachmentMngr.ts index ec5bc2bb..a19df0ba 100644 --- a/ReallifeGamemode.Client/util/attachmentMngr.ts +++ b/ReallifeGamemode.Client/util/attachmentMngr.ts @@ -8,7 +8,7 @@ export default function attachmentManager(game: IGame) { attachmentMngr.register("weapondeal", "ex_prop_crate_ammo_bc", "chassis_dummy", new mp.Vector3(0.08, -0.9, -0.2), new mp.Vector3(0, 0, 0)); attachmentMngr.register("weapondeal1", "ex_office_swag_guns02", "chassis_dummy", new mp.Vector3(0, 0.8, 0), new mp.Vector3(0, 0, 0)); attachmentMngr.register("weapondeal2", "w_sg_pumpshotgun", "chassis_dummy", new mp.Vector3(0.4, 1.6, 0.62), new mp.Vector3(90, 0, 180)); - attachmentMngr.register("handcuffs", "p_cs_cuffs_02_s", 28422, new mp.Vector3(0, 0, 0), new mp.Vector3(0, 0, 0)); + attachmentMngr.register("handcuffs", "p_cs_cuffs_02_s", 28422, new mp.Vector3(0, 0, 0), new mp.Vector3(0, 90, 0)); }); const attachmentMngr = diff --git a/ReallifeGamemode.Client/util/weapondamage.ts b/ReallifeGamemode.Client/util/weapondamage.ts index 9f192070..eae20da7 100644 --- a/ReallifeGamemode.Client/util/weapondamage.ts +++ b/ReallifeGamemode.Client/util/weapondamage.ts @@ -10,6 +10,7 @@ mp.events.add("render", () => { if (blockInput) { mp.game.controls.disableControlAction(32, 142, true); + mp.game.controls.disableControlAction(32, 140, true); mp.game.controls.disableControlAction(32, 263, true); } }); diff --git a/ReallifeGamemode.Server/Commands/AdminCommands.cs b/ReallifeGamemode.Server/Commands/AdminCommands.cs index fa836fa3..e4ae58b3 100644 --- a/ReallifeGamemode.Server/Commands/AdminCommands.cs +++ b/ReallifeGamemode.Server/Commands/AdminCommands.cs @@ -34,33 +34,6 @@ namespace ReallifeGamemode.Server.Commands { #region Todo - [Command("cuff", "~m~Benutzung: ~s~/cuff [ID]")] - public void CmdCuffTest(Player player, string nameOrId) - { - if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true) - { - ChatService.NotAuthorized(player); - return; - } - Player target = PlayerService.GetPlayerByNameOrId(nameOrId); - if (target.Id == player.Id) - return; - - target.SetInFrontOf(player); - target.Heading = player.Heading; - - if (!target.HasAnimation("Cuffed")) - { - player.SyncAnimation("doArrest"); - target.SyncAnimation(new List() { "getArrest", "Cuffed" }); - } - else - { - player.SyncAnimation("doUncuff"); - target.SyncAnimation("getUncuff"); - } - } - [Command("syncanim", "~m~Benutzung: ~s~/syncanim [animName]")] public void CmdSyncAnim(Player player, string animName = null) { diff --git a/ReallifeGamemode.Server/Commands/FactionCommands.cs b/ReallifeGamemode.Server/Commands/FactionCommands.cs index ac032bbb..da4d3316 100644 --- a/ReallifeGamemode.Server/Commands/FactionCommands.cs +++ b/ReallifeGamemode.Server/Commands/FactionCommands.cs @@ -11,6 +11,7 @@ using ReallifeGamemode.Server.Factions.Medic; using ReallifeGamemode.Server.Managers; using ReallifeGamemode.Server.Services; using ReallifeGamemode.Server.Types; +using ReallifeGamemode.Server.Util; using ReallifeGamemode.Services; /** @@ -57,7 +58,7 @@ namespace ReallifeGamemode.Server.Commands string rank = string.Empty; - if(f?.Name == "Ballas" || f?.Name == "Grove") + if (f?.Name == "Ballas" || f?.Name == "Grove") { rank = player.GetUser().GetFactionRank().RankName; } @@ -109,7 +110,7 @@ namespace ReallifeGamemode.Server.Commands string factionName = string.Empty; - if(f?.StateOwned ?? false) + if (f?.StateOwned ?? false) { factionName = u.GetFactionRank().RankName; } @@ -127,7 +128,6 @@ namespace ReallifeGamemode.Server.Commands #endregion Chat Commands - #region NewsReporter commands [Command("news", "~m~Benutzung: ~s~/news [Nachricht]", GreedyArg = true)] @@ -139,12 +139,12 @@ namespace ReallifeGamemode.Server.Commands ChatService.NotAuthorized(player); return; } - if (player.GetUser().Faction.Id == 9 ) + if (player.GetUser().Faction.Id == 9) { message = Regex.Replace(message, "(~[a-zA-Z]~)|(!{(.*)})", ""); string broadcastMessage = "!{ff9531}** News Reporter" + " " + player.Name + ": " + message + " **"; - ChatService.Broadcast(broadcastMessage); + ChatService.Broadcast(broadcastMessage); } else { @@ -152,11 +152,8 @@ namespace ReallifeGamemode.Server.Commands } } - - - - #endregion NewsReporter commands + #region Leader Commands [Command("giverank", "~m~Benutzung: ~s~/giverank [Name] [Rang]", GreedyArg = true)] @@ -212,7 +209,7 @@ namespace ReallifeGamemode.Server.Commands message = Regex.Replace(message, "(~[a-zA-Z]~)|(!{(.*)})", ""); string factionName = string.Empty; - if(user.FactionLeader) + if (user.FactionLeader) { factionName = player.GetUser().Faction.Name; } @@ -329,7 +326,7 @@ namespace ReallifeGamemode.Server.Commands deadPlayerUser.Handmoney = 0; deadPlayerUser.BankAccount.Balance -= bankMoney; } - + player.PlayAnimation("amb@medic@standing@kneel@enter", "enter", 0); deadPlayer.TriggerEvent("onPlayerRevived"); @@ -363,7 +360,7 @@ namespace ReallifeGamemode.Server.Commands return; } - if(player.Position.DistanceTo(target.Position) > 5) + if (player.Position.DistanceTo(target.Position) > 5) { ChatService.ErrorMessage(player, "Der Patient ist zu weit entfernt"); return; @@ -398,16 +395,54 @@ namespace ReallifeGamemode.Server.Commands return; } - ChatService.SendMessage(target,"~g~" + player.Name + " ~s~möchte dich für ~g~$" + price + " ~s~heilen. Drücke ~g~J~s~ zum Erlauben oder ~r~N ~s~zum Verbieten"); - player.SendNotification("Du hast " + target.Name + " einen Heal angeboten",false); + ChatService.SendMessage(target, "~g~" + player.Name + " ~s~möchte dich für ~g~$" + price + " ~s~heilen. Drücke ~g~J~s~ zum Erlauben oder ~r~N ~s~zum Verbieten"); + player.SendNotification("Du hast " + target.Name + " einen Heal angeboten", false); target.SetData("healDecision", true); - Medic.HealDecisions.Add(new Medic.HealDecision {dMedic = player, dTarget = target, dPrice = price}); + Medic.HealDecisions.Add(new Medic.HealDecision { dMedic = player, dTarget = target, dPrice = price }); } #endregion Sanitäter Commands #region Staatsfraktionen (LSPD / FBI) Commands + [Command("cuff", "~m~Benutzung: ~s~/cuff")] + public void CmdFactionCuff(Player player) + { + User user = player.GetUser(); + if (user == null || (user.FactionId != 1 && user.FactionId != 3)) + { + ChatService.NotAuthorized(player); + return; + } + + if (!player.IsDuty()) + { + ChatService.ErrorMessage(player, "Du bist nicht im Dienst"); + return; + } + + Player nearestCuffPlayer = PositionManager.cuffPoints.Find(s => s.Position.DistanceTo(player.Position) <= 1.6 && user.GetData("duty")); + + if (nearestCuffPlayer is null) + return; + + nearestCuffPlayer.SetInFrontOf(player); + nearestCuffPlayer.Heading = player.Heading; + + if (!nearestCuffPlayer.HasAnimation("Cuffed")) + { + player.SyncAnimation("doArrest"); + nearestCuffPlayer.SyncAnimation(new List() { "getArrest", "Cuffed" }); + player.AddAttachment("handcuffs", false); + } + else + { + player.AddAttachment("handcuffs", true); + player.SyncAnimation("doUncuff"); + nearestCuffPlayer.SyncAnimation("getUncuff"); + } + } + [Command("wanted", "~m~Benutzung: ~s~/wa(nted) [Spieler] [Anzahl] [Grund]", Alias = "wa", GreedyArg = true)] public void CmdFactionWanted(Player player, string nameOrId, int amount, string reason) { @@ -480,7 +515,7 @@ namespace ReallifeGamemode.Server.Commands } ChatService.SendMessage(target, "!{#8181E9}Deine Akte wurde von " + player.Name + " gelöscht. Grund: " + reason); ChatService.BroadcastFaction("!{#8181E9}HQ: Die Akte von " + target.Name + " wurde von " + player.Name + " gelöscht. Grund: " + reason + ".", new List() { 1, 3 }); - + target.TriggerEvent("jailTime", 0); targetUser.Wanteds = 0; @@ -491,11 +526,12 @@ namespace ReallifeGamemode.Server.Commands } #endregion Staatsfraktionen (LSPD / FBI) Commands + #region Weazel News + [Command("eventchat", "~m~Benutzung: ~s~/eventchat [Typ = ~g~on~s~, ~g~off~s~]", GreedyArg = true)] public void CmdFactionNREventchat(Player player, string onoff) { - switch (onoff.ToLower()) { case "on": @@ -513,14 +549,9 @@ namespace ReallifeGamemode.Server.Commands }); player.SendNotification("Der Eventchat ist nun aus."); break; - } - - } - #endregion Weazel News } - } diff --git a/ReallifeGamemode.Server/Commands/UserCommands.cs b/ReallifeGamemode.Server/Commands/UserCommands.cs index 227e80ab..6880fd52 100644 --- a/ReallifeGamemode.Server/Commands/UserCommands.cs +++ b/ReallifeGamemode.Server/Commands/UserCommands.cs @@ -111,7 +111,6 @@ namespace ReallifeGamemode.Server.Commands return; player.SyncAnimation("hup"); - ChatService.SendInRange(player.Position, 20, $"~m~{player.Name} stellt sich..."); } [Command("event", "~m~Benutzung: ~s~/event [Nachricht]", GreedyArg = true)] diff --git a/ReallifeGamemode.Server/Events/Key.cs b/ReallifeGamemode.Server/Events/Key.cs index 47807d69..f03b95ea 100644 --- a/ReallifeGamemode.Server/Events/Key.cs +++ b/ReallifeGamemode.Server/Events/Key.cs @@ -218,6 +218,7 @@ namespace ReallifeGamemode.Server.Events FriseurPoint nearestFriseurPoint = PositionManager.friseurPoints.Find(s => s.Position.DistanceTo(player.Position) <= 1.5 && (!user.GetData("duty"))); ItemshopPoint nearestItemShopPoint = PositionManager.itemshopPoints.Find(s => s.Position.DistanceTo(player.Position) <= 1.5); JobPoint nearestJobPoint = PositionManager.JobPoints.Find(s => s.Position.DistanceTo(player.Position) <= 1.6); + Player nearestCuffPlayer = PositionManager.cuffPoints.Find(s => s.Position.DistanceTo(player.Position) <= 1.6 && user.GetData("duty")); if (user?.FactionId != null) { @@ -507,6 +508,24 @@ namespace ReallifeGamemode.Server.Events } player.TriggerEvent("showJailMenu", JsonConvert.SerializeObject(criminals.ToArray())); } + if (nearestCuffPlayer != null) + { + nearestCuffPlayer.SetInFrontOf(player); + nearestCuffPlayer.Heading = player.Heading; + + if (!nearestCuffPlayer.HasAnimation("Cuffed")) + { + player.SyncAnimation("doArrest"); + nearestCuffPlayer.SyncAnimation(new List() { "getArrest", "Cuffed" }); + player.AddAttachment("handcuffs", false); + } + else + { + player.AddAttachment("handcuffs", true); + player.SyncAnimation("doUncuff"); + nearestCuffPlayer.SyncAnimation("getUncuff"); + } + } } if (nearestElevatorPoint != null) { @@ -969,14 +988,19 @@ namespace ReallifeGamemode.Server.Events [RemoteEvent("keyPress:ControllH")] public void KeyPressControllH(Player player) { - if (player.HasAnimation("hup")) { player.ClearAnimation(); player.AddAttachment("handcuffs", true); return; } + if (player.HasAnimation("hup")) + { + PositionManager.cuffPoints.Remove(player); + player.ClearAnimation(); + return; + } if (player.HasAnimation()) return; - player.AddAttachment("handcuffs", false); - player.SyncAnimation("hup"); - ChatService.SendInRange(player.Position, 20, $"~m~{player.Name} stellt sich..."); + + if (player.GetUser().Wanteds > 0) + PositionManager.cuffPoints.Add(player); } #endregion User Key diff --git a/ReallifeGamemode.Server/Extensions/ClientExtension.cs b/ReallifeGamemode.Server/Extensions/ClientExtension.cs index 96b81700..4ea122fd 100644 --- a/ReallifeGamemode.Server/Extensions/ClientExtension.cs +++ b/ReallifeGamemode.Server/Extensions/ClientExtension.cs @@ -321,5 +321,10 @@ namespace ReallifeGamemode.Server.Extensions { player.TriggerEvent("SERVER:SetInFrontPosition", entity); } + + public static void SetCuffable(this Player player, bool isCuffable) + { + player.SetSharedData("Cuffable", isCuffable); + } } } diff --git a/ReallifeGamemode.Server/Managers/PositionManager.cs b/ReallifeGamemode.Server/Managers/PositionManager.cs index ebe2b755..5534a189 100644 --- a/ReallifeGamemode.Server/Managers/PositionManager.cs +++ b/ReallifeGamemode.Server/Managers/PositionManager.cs @@ -26,6 +26,8 @@ namespace ReallifeGamemode.Server.Managers public static List JobPoints = new List(); + public static List cuffPoints = new List(); + public static void LoadPositionManager() { #region DutyPoints