Animation Sync events

This commit is contained in:
2021-04-06 15:30:28 +02:00
parent d1470564e3
commit bda2273f8f
2 changed files with 32 additions and 3 deletions

View File

@@ -23,7 +23,6 @@ namespace ReallifeGamemode.Server.Events
[ServerEvent(Event.PlayerConnected)] [ServerEvent(Event.PlayerConnected)]
public void OnPlayerConnected(Player player) public void OnPlayerConnected(Player player)
{ {
player.TriggerEvent("SERVER:LoadAnimations");
player.TriggerEvent("CLIENT:StopSound"); player.TriggerEvent("CLIENT:StopSound");
//player.SetSharedData("vehicleAdminSpeed2", 1.0); //player.SetSharedData("vehicleAdminSpeed2", 1.0);
player.SetData("isLoggedIn", false); player.SetData("isLoggedIn", false);

View File

@@ -8,7 +8,7 @@ namespace ReallifeGamemode.Server.Util
{ {
public static class AnimationSync 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")) if (!player.HasData("Animation"))
player.SetData("Animation", String.Empty); player.SetData("Animation", String.Empty);
@@ -22,7 +22,18 @@ namespace ReallifeGamemode.Server.Util
player.SetSharedData("AnimationData", newAnimation); player.SetSharedData("AnimationData", newAnimation);
} }
public static bool HasAnimation(this Player player, string animationName) /// <summary>Check if Player has any Animation playing.
/// </summary>
/// <param name="player"></param>
public static bool HasAnimation(this Player player)
{
return player.HasData("Animation");
}
/// <summary>Check if Player has a specific Animation playing.
/// </summary>
/// <param name="animationName">Name of requested animation</param>
public static bool HasAnimation(this Player player, dynamic animationName)
{ {
return player.HasData("Animation") && (player.GetData<string>("AnimationData") == animationName); return player.HasData("Animation") && (player.GetData<string>("AnimationData") == animationName);
} }
@@ -44,5 +55,24 @@ namespace ReallifeGamemode.Server.Util
{ {
target.SyncAnimation(transitionTo); 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();
}
} }
} }