From b4fb23078bfd0aff617047dbe915627c885f3652 Mon Sep 17 00:00:00 2001 From: kookroach Date: Tue, 6 Apr 2021 17:34:34 +0200 Subject: [PATCH] /cuff positioning test --- ReallifeGamemode.Client/util/animationSync.ts | 32 ++++++++++++++++--- .../Commands/AdminCommands.cs | 6 ++-- ReallifeGamemode.Server/Events/PlayerEvent.cs | 16 ++++++++++ .../Extensions/ClientExtension.cs | 12 +++++-- ReallifeGamemode.Server/Util/AnimationSync.cs | 6 ++++ 5 files changed, 61 insertions(+), 11 deletions(-) create mode 100644 ReallifeGamemode.Server/Events/PlayerEvent.cs diff --git a/ReallifeGamemode.Client/util/animationSync.ts b/ReallifeGamemode.Client/util/animationSync.ts index e29e5e7d..d7b21703 100644 --- a/ReallifeGamemode.Client/util/animationSync.ts +++ b/ReallifeGamemode.Client/util/animationSync.ts @@ -51,8 +51,9 @@ setInterval(() => { mp.players.forEachInStreamRange( (player) => { - if (!player.getVariable("AnimationData")) + if (!player.getVariable("AnimationData")) { return; + } let index = mp.game.joaat(player.getVariable("AnimationData")); let currentAnim = animationSyncData.animations[index]; @@ -62,16 +63,20 @@ 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 + if (player == mp.players.local) { blockInput = true; } + } else if (!loop) { + if (player == mp.players.local) { + blockInput = false; + mp.events.callRemote("CLIENT:ClearAnimationData", player); + } } }); }, 100); mp.events.addDataHandler("AnimationData", (entity: PlayerMp, string) => { entity.clearTasksImmediately(); - blockInput = false; if (string == null) { return; } @@ -88,12 +93,15 @@ mp.players.exists(entity) && 0 !== entity.handle && entity.taskPlayAnim(animDict, animName, 8, 1, duration, parseInt(flag), 0, !1, !1, !1) }); + blockInput = true; + let pair = pairData.find(pair => pair.from == string); if (!pair) return; - blockInput = true; let a = setInterval(function () { - mp.events.callRemote("CLIENT:AnimPairTransition", entity, pair.transitionTo); + if (entity == mp.players.local) { + mp.events.callRemote("CLIENT:AnimPairTransition", entity, pair.transitionTo); + } clearInterval(a); }, duration); }); @@ -101,6 +109,7 @@ mp.events.add("render", () => { if (blockInput) { mp.game.controls.disableControlAction(32, 24, true); + mp.game.controls.disableControlAction(32, 22, true); } }); @@ -111,4 +120,17 @@ mp.game.streaming.hasAnimDictLoaded(animDict) && (clearInterval(c), callback()) }, 100) } + + mp.events.add("SERVER:GetInFrontPosition", () => { + let player = mp.players.local; + let result = xyInFrontOfPos(player.position, player.heading, 0.5); + mp.events.callRemote("CLIENT:SET_InFrontOfPos", result); + }); + + function xyInFrontOfPos(pos, heading, dist): Vector3Mp { + heading *= Math.PI / 180 + pos.x += (dist * Math.sin(-heading)) + pos.y += (dist * Math.cos(-heading)) + return pos; + } } \ No newline at end of file diff --git a/ReallifeGamemode.Server/Commands/AdminCommands.cs b/ReallifeGamemode.Server/Commands/AdminCommands.cs index 4f5bc0a9..b121085a 100644 --- a/ReallifeGamemode.Server/Commands/AdminCommands.cs +++ b/ReallifeGamemode.Server/Commands/AdminCommands.cs @@ -46,10 +46,8 @@ namespace ReallifeGamemode.Server.Commands if (target.Id == player.Id) return; - float rad = player.Heading * MathF.PI / 180; - Vector3 forwardV3 = new Vector3(player.Position.X + (1.2 * MathF.Sin(rad)), player.Position.Y + (1.2 * MathF.Cos(rad)), player.Position.Z); - - target.Position = forwardV3; + target.Position = player.GetInFrontOfPosition(); + target.Heading = player.Heading; if (!target.HasAnimation("Cuffed")) { diff --git a/ReallifeGamemode.Server/Events/PlayerEvent.cs b/ReallifeGamemode.Server/Events/PlayerEvent.cs new file mode 100644 index 00000000..e159bab5 --- /dev/null +++ b/ReallifeGamemode.Server/Events/PlayerEvent.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; +using GTANetworkAPI; + +namespace ReallifeGamemode.Server.Events +{ + internal class PlayerEvent : Script + { + [RemoteEvent("CLIENT:SET_InFrontOfPos")] + public void SetFrontOfPos(Player player, Vector3 pos) + { + player.SetSharedData("InFrontOf", pos); + } + } +} diff --git a/ReallifeGamemode.Server/Extensions/ClientExtension.cs b/ReallifeGamemode.Server/Extensions/ClientExtension.cs index ebdee723..bea9af66 100644 --- a/ReallifeGamemode.Server/Extensions/ClientExtension.cs +++ b/ReallifeGamemode.Server/Extensions/ClientExtension.cs @@ -77,10 +77,12 @@ namespace ReallifeGamemode.Server.Extensions var user = player.GetUser(); return user.GetData("duty", false); } + public static bool IsAdminDuty(this Player player) { return player.HasData("Adminduty") ? player.GetData("Adminduty") : false; } + public static Vector3 GetPositionFromPlayer(Player player, float distance, int offset = 0) { var pos = player.Position; @@ -268,11 +270,11 @@ namespace ReallifeGamemode.Server.Extensions } else if (user.FactionId != null) { - if(user.FactionId > 3 || (user.FactionId >= 1 && user.FactionId <= 3 && duty)) + if (user.FactionId > 3 || (user.FactionId >= 1 && user.FactionId <= 3 && duty)) { nameTagColor = user.FactionId.Value; } - + switch (user.FactionId) { case 1 when duty: @@ -314,5 +316,11 @@ namespace ReallifeGamemode.Server.Extensions user.Player.SetSharedData("nameTagColor", nameTagColor); user.Player.SetSharedData("blipColor", blipColor); } + + public static Vector3 GetInFrontOfPosition(this Player player) + { + player.TriggerEvent("SERVER:GetInFrontPosition"); + return player.GetSharedData("InFrontOf"); + } } } diff --git a/ReallifeGamemode.Server/Util/AnimationSync.cs b/ReallifeGamemode.Server/Util/AnimationSync.cs index 7ff3d3ad..6d1b47c4 100644 --- a/ReallifeGamemode.Server/Util/AnimationSync.cs +++ b/ReallifeGamemode.Server/Util/AnimationSync.cs @@ -56,6 +56,12 @@ namespace ReallifeGamemode.Server.Util target.SyncAnimation(transitionTo); } + [RemoteEvent("CLIENT:ClearAnimationData")] + public void ClearAnimationData(Player player, Player target) + { + target.ClearAnimation(); + } + [ServerEvent(Event.PlayerWeaponSwitch)] public void OnPlayerWeaponSwitch(Player player, WeaponHash oldWeapon, WeaponHash newWeapon) {