Added mouth animation when speaking

This commit is contained in:
Nick I. A 2022-08-14 23:35:36 +02:00
parent 0c71d4dbaa
commit d30e1f6bb3
5 changed files with 51 additions and 7 deletions

View File

@ -272,6 +272,10 @@ namespace RageCoop.Client
Main.QueueAction(() =>
{
SyncedPed player = EntityPool.GetPedByID(packet.ID);
player.IsSpeaking = true;
player.LastSpeakingTime = Main.Ticked;
Sync.Voice.AddVoiceData(packet.Buffer, packet.Recorded);
});
}

View File

@ -201,7 +201,7 @@ namespace RageCoop.Client
}
public static void SendVoiceMessage(byte[] buffer, int recorded)
{
SendSync(new Packets.Voice() { Buffer = buffer, Recorded = recorded }, ConnectionChannel.Voice, NetDeliveryMethod.ReliableOrdered);
SendSync(new Packets.Voice() { ID = Main.LocalPlayerID, Buffer = buffer, Recorded = recorded }, ConnectionChannel.Voice, NetDeliveryMethod.ReliableOrdered);
}
}
}

View File

@ -1,15 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GTA;
using GTA;
using GTA.Native;
using System.Threading.Tasks;
namespace RageCoop.Client
{
public partial class SyncedPed
{
private void DisplaySpeaking(bool speaking)
{
if (MainPed == null || !MainPed.Exists() || !MainPed.IsHuman)
return;
if (speaking)
{
Function.Call(Hash.PLAY_FACIAL_ANIM, MainPed.Handle, "mic_chatter", "mp_facial");
return;
}
switch (MainPed.Gender)
{
case Gender.Male:
Function.Call(Hash.PLAY_FACIAL_ANIM, MainPed.Handle, "mood_normal_1", "facials@gen_male@variations@normal");
break;
case Gender.Female:
Function.Call(Hash.PLAY_FACIAL_ANIM, MainPed.Handle, "mood_normal_1", "facials@gen_female@variations@normal");
break;
default:
Function.Call(Hash.PLAY_FACIAL_ANIM, MainPed.Handle, "mood_normal_1", "facials@mime@variations@normal");
break;
}
}
private void DisplayInCover()
{

View File

@ -7,6 +7,7 @@ using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
namespace RageCoop.Client
{
@ -80,6 +81,8 @@ namespace RageCoop.Client
internal float Heading { get; set; }
internal ulong LastSpeakingTime { get; set; } = 0;
internal bool IsSpeaking { get; set; } = false;
#region -- VARIABLES --
public byte Speed { get; set; }
@ -214,6 +217,21 @@ namespace RageCoop.Client
DisplayOnFoot();
}
if (IsSpeaking)
{
if (Main.Ticked - LastSpeakingTime < 10)
{
DisplaySpeaking(true);
}
else
{
DisplaySpeaking(false);
IsSpeaking = false;
LastSpeakingTime = 0;
}
}
LastUpdated=Main.Ticked;
}

View File

@ -6,12 +6,14 @@ namespace RageCoop.Core
{
internal class Voice : Packet
{
public int ID { get; set; }
public byte[] Buffer { get; set; }
public int Recorded { get; set; }
public override PacketType Type => PacketType.Voice;
public override byte[] Serialize()
{
var data = new List<byte>();
data.AddInt(ID);
data.AddArray(Buffer);
data.AddInt(Recorded);
return data.ToArray();
@ -19,6 +21,7 @@ namespace RageCoop.Core
public override void Deserialize(byte[] array)
{
var reader = new BitReader(array);
ID = reader.ReadInt32();
Buffer = reader.ReadByteArray();
Recorded = reader.ReadInt32();
}