Move CurrentWeaponHash to full sync

This commit is contained in:
Sardelka 2022-08-08 17:29:15 +08:00
parent 83d79b0a17
commit 01524b1796
4 changed files with 24 additions and 12 deletions

View File

@ -337,7 +337,6 @@ namespace RageCoop.Client
c.Rotation = packet.Rotation;
c.Velocity = packet.Velocity;
c.Speed = packet.Speed;
c.CurrentWeaponHash = packet.CurrentWeaponHash;
c.IsAiming = flags.HasPedFlag(PedDataFlags.IsAiming);
c.IsReloading = flags.HasPedFlag(PedDataFlags.IsReloading);
c.IsJumping = flags.HasPedFlag(PedDataFlags.IsJumping);
@ -364,6 +363,7 @@ namespace RageCoop.Client
}
if (packet.Flags.HasPedFlag(PedDataFlags.IsFullSync))
{
c.CurrentWeaponHash = packet.CurrentWeaponHash;
c.Clothes=packet.Clothes;
c.WeaponComponents=packet.WeaponComponents;
c.WeaponTint=packet.WeaponTint;

View File

@ -41,7 +41,6 @@ namespace RageCoop.Client
Rotation = p.ReadRotation(),
Velocity = p.ReadVelocity(),
Speed = p.GetPedSpeed(),
CurrentWeaponHash = (uint)p.Weapons.Current.Hash,
Flags = p.GetPedFlags(),
Heading=p.Heading,
};
@ -62,6 +61,14 @@ namespace RageCoop.Client
c.LastSentStopWatch.Restart();
if (full)
{
if (packet.Flags.HasPedFlag(PedDataFlags.IsInVehicle))
{
packet.CurrentWeaponHash=(uint)p.VehicleWeapon;
}
else
{
packet.CurrentWeaponHash=(uint)p.Weapons.Current.Hash;
}
packet.Flags |= PedDataFlags.IsFullSync;
packet.Clothes=p.GetPedClothes();
packet.ModelHash=p.Model.Hash;

View File

@ -44,13 +44,11 @@ namespace RageCoop.Client
LastSynced=Main.Ticked;
}
#endregion
#region PLAYER -- ONLY
internal Blip PedBlip = null;
internal BlipColor BlipColor = (BlipColor)255;
internal BlipSprite BlipSprite = (BlipSprite)0;
internal float BlipScale = 1;
internal Player Player;
#endregion
/// <summary>
/// Indicates whether this ped is a player
@ -165,7 +163,6 @@ namespace RageCoop.Client
{
SetClothes();
}
CheckCurrentWeapon();
}
@ -341,6 +338,7 @@ namespace RageCoop.Client
private void DisplayOnFoot()
{
CheckCurrentWeapon();
if (IsInParachuteFreeFall)
{
MainPed.PositionNoOffset = Vector3.Lerp(MainPed.ReadPosition(), Position + Velocity, 0.5f);
@ -588,11 +586,11 @@ namespace RageCoop.Client
#region WEAPON
private void CheckCurrentWeapon()
{
if (!WeaponAsset.IsLoaded) { WeaponAsset.Request(); }
if (MainPed.Weapons.Current.Hash != (WeaponHash)CurrentWeaponHash || !WeaponComponents.Compare(_lastWeaponComponents))
{
if (WeaponAsset!=null) { WeaponAsset.MarkAsNoLongerNeeded(); }
WeaponAsset=new WeaponAsset(CurrentWeaponHash);
if (!WeaponAsset.IsLoaded) { WeaponAsset.Request(); }
MainPed.Weapons.RemoveAll();
_lastWeaponObj = Function.Call<int>(Hash.CREATE_WEAPON_OBJECT, CurrentWeaponHash, -1, Position.X, Position.Y, Position.Z, true, 0, 0);
@ -766,9 +764,13 @@ namespace RageCoop.Client
{
if (MainPed.IsOnTurretSeat())
{
Function.Call(Hash.SET_VEHICLE_TURRET_SPEED_THIS_FRAME, MainPed.CurrentVehicle, 100);
// Function.Call(Hash.SET_VEHICLE_TURRET_SPEED_THIS_FRAME, MainPed.CurrentVehicle, 100);
Function.Call(Hash.TASK_VEHICLE_AIM_AT_COORD, MainPed.Handle, AimCoords.X, AimCoords.Y, AimCoords.Z);
}
if (MainPed.VehicleWeapon!=(VehicleWeaponHash)CurrentWeaponHash)
{
MainPed.VehicleWeapon=(VehicleWeaponHash)CurrentWeaponHash;
}
/*
Function.Call(Hash.TASK_SWEEP_AIM_ENTITY,P, "random@paparazzi@pap_anims", "sweep_low", "sweep_med", "sweep_high", -1,V, 1.57f, 0.25f);
Function.Call(Hash.SET_PED_STEALTH_MOVEMENT, P,true, 0);

View File

@ -38,7 +38,6 @@ namespace RageCoop.Core
public Vector3 AimCoords { get; set; }
public uint CurrentWeaponHash { get; set; }
public float Heading { get; set; }
@ -46,6 +45,8 @@ namespace RageCoop.Core
public int ModelHash { get; set; }
public uint CurrentWeaponHash { get; set; }
public byte[] Clothes { get; set; }
public Dictionary<uint, bool> WeaponComponents { get; set; }
@ -99,8 +100,6 @@ namespace RageCoop.Core
// Write ped speed
byteArray.Add(Speed);
// Write ped weapon hash
byteArray.AddRange(BitConverter.GetBytes(CurrentWeaponHash));
if (Flags.HasPedFlag(PedDataFlags.IsAiming))
{
@ -115,6 +114,9 @@ namespace RageCoop.Core
// Write model hash
byteArray.AddInt(ModelHash);
// Write ped weapon hash
byteArray.AddUint(CurrentWeaponHash);
byteArray.AddRange(Clothes);
// Write player weapon components
@ -185,8 +187,6 @@ namespace RageCoop.Core
// Read player speed
Speed = reader.ReadByte();
// Read player weapon hash
CurrentWeaponHash = reader.ReadUInt32();
// Try to read aim coords
if (Flags.HasPedFlag(PedDataFlags.IsAiming))
@ -202,6 +202,9 @@ namespace RageCoop.Core
// Read player model hash
ModelHash = reader.ReadInt32();
// Read player weapon hash
CurrentWeaponHash = reader.ReadUInt32();
// Read player clothes
Clothes =reader.ReadBytes(36);