diff --git a/ReallifeGamemode.Server/Events/Connect.cs b/ReallifeGamemode.Server/Events/Connect.cs index 83924b14..becbb3b9 100644 --- a/ReallifeGamemode.Server/Events/Connect.cs +++ b/ReallifeGamemode.Server/Events/Connect.cs @@ -23,7 +23,6 @@ namespace ReallifeGamemode.Server.Events [ServerEvent(Event.PlayerConnected)] public void OnPlayerConnected(Player player) { - player.TriggerEvent("SERVER:LoadAnimations"); player.TriggerEvent("CLIENT:StopSound"); //player.SetSharedData("vehicleAdminSpeed2", 1.0); player.SetData("isLoggedIn", false); diff --git a/ReallifeGamemode.Server/Util/AnimationSync.cs b/ReallifeGamemode.Server/Util/AnimationSync.cs index ea4cceda..7ff3d3ad 100644 --- a/ReallifeGamemode.Server/Util/AnimationSync.cs +++ b/ReallifeGamemode.Server/Util/AnimationSync.cs @@ -8,7 +8,7 @@ namespace ReallifeGamemode.Server.Util { public static class AnimationSync { - public static void SyncAnimation(this Player player, string animationName) + public static void SyncAnimation(this Player player, dynamic animationName) { if (!player.HasData("Animation")) player.SetData("Animation", String.Empty); @@ -22,7 +22,18 @@ namespace ReallifeGamemode.Server.Util player.SetSharedData("AnimationData", newAnimation); } - public static bool HasAnimation(this Player player, string animationName) + /// Check if Player has any Animation playing. + /// + /// + public static bool HasAnimation(this Player player) + { + return player.HasData("Animation"); + } + + /// Check if Player has a specific Animation playing. + /// + /// Name of requested animation + public static bool HasAnimation(this Player player, dynamic animationName) { return player.HasData("Animation") && (player.GetData("AnimationData") == animationName); } @@ -44,5 +55,24 @@ namespace ReallifeGamemode.Server.Util { target.SyncAnimation(transitionTo); } + + [ServerEvent(Event.PlayerWeaponSwitch)] + public void OnPlayerWeaponSwitch(Player player, WeaponHash oldWeapon, WeaponHash newWeapon) + { + if (!player.HasAnimation()) return; + NAPI.Player.SetPlayerCurrentWeapon(player, WeaponHash.Unarmed); + } + + [ServerEvent(Event.PlayerConnected)] + public void OnPlayerConnected(Player player) + { + player.TriggerEvent("SERVER:LoadAnimations"); + } + + [ServerEvent(Event.PlayerDeath)] + public void OnPlayerDeath(Player player, Player killer, uint reason) + { + player.ClearAnimation(); + } } }