86 lines
2.4 KiB
C#
86 lines
2.4 KiB
C#
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 SyncAnimation(this Player player, dynamic animationName)
|
|
{
|
|
if (!player.HasData("Animation"))
|
|
player.SetData("Animation", String.Empty);
|
|
|
|
string currentAnimation = player.GetData<string>("Animation");
|
|
string newAnimation = animationName;
|
|
|
|
if (currentAnimation.Equals(newAnimation))
|
|
return;
|
|
|
|
player.SetSharedData("AnimationData", newAnimation);
|
|
player.SetData<string>("Animation", newAnimation);
|
|
}
|
|
|
|
/// <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>("Animation") == animationName);
|
|
}
|
|
|
|
public static void ClearAnimation(this Player player)
|
|
{
|
|
if (!player.HasData("Animation"))
|
|
return;
|
|
|
|
player.ResetData("Animation");
|
|
player.ResetSharedData("AnimationData");
|
|
}
|
|
}
|
|
|
|
public class AnimationSyncEvents : Script
|
|
{
|
|
[RemoteEvent("CLIENT:AnimPairTransition")]
|
|
public void AnimPairTransition(Player player, Player target, string transitionTo)
|
|
{
|
|
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)
|
|
{
|
|
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();
|
|
}
|
|
}
|
|
}
|