Vehicle turret synchronization (experimental and not finished yet)

This commit is contained in:
EntenKoeniq
2021-12-06 00:56:08 +01:00
parent bce2a7cbc2
commit bec80e6082
6 changed files with 74 additions and 11 deletions

View File

@ -172,6 +172,7 @@ namespace CoopClient.Entities
/// ?
/// </summary>
public float VehicleSteeringAngle { get; set; }
private int LastVehicleAim;
/// <summary>
/// ?
/// </summary>
@ -560,9 +561,19 @@ namespace CoopClient.Entities
LastVehTires = VehTires;
}
if (AimCoords != default)
{
int gameTime = Game.GameTime;
if (gameTime - LastVehicleAim > 30)
{
Function.Call(Hash.TASK_VEHICLE_AIM_AT_COORD, Character.Handle, AimCoords.X, AimCoords.Y, AimCoords.Z);
LastVehicleAim = gameTime;
}
}
}
}
if (VehicleSteeringAngle != MainVehicle.SteeringAngle)
{
MainVehicle.CustomSteeringAngle((float)(Math.PI / 180) * VehicleSteeringAngle);

View File

@ -240,12 +240,12 @@ namespace CoopClient
DebugSyncPed = Players[0];
}
if ((Util.GetTickCount64() - ArtificialLagCounter) < 157)
if ((Util.GetTickCount64() - ArtificialLagCounter) < 56)
{
return;
}
bool fullSync = (Util.GetTickCount64() - LastFullDebugSync) > 1500;
bool fullSync = (Util.GetTickCount64() - LastFullDebugSync) > 500;
if (fullSync)
{
@ -282,6 +282,7 @@ namespace CoopClient
DebugSyncPed.VehicleVelocity = veh.Velocity;
DebugSyncPed.VehicleSpeed = veh.Speed;
DebugSyncPed.VehicleSteeringAngle = veh.SteeringAngle;
DebugSyncPed.AimCoords = veh.IsTurretSeat((int)player.SeatIndex) ? Util.GetVehicleAimCoords() : new GTA.Math.Vector3();
DebugSyncPed.VehicleColors = new int[] { primaryColor, secondaryColor };
DebugSyncPed.VehicleMods = veh.Mods.GetVehicleMods();
DebugSyncPed.VehDoors = veh.Doors.GetVehicleDoors();

View File

@ -335,6 +335,7 @@ namespace CoopClient
player.VehicleVelocity = packet.VehVelocity.ToVector();
player.VehicleSpeed = packet.VehSpeed;
player.VehicleSteeringAngle = packet.VehSteeringAngle;
player.AimCoords = packet.VehAimCoords.ToVector();
player.VehicleColors = packet.VehColors;
player.VehicleMods = packet.VehMods;
player.VehDoors = packet.VehDoors;
@ -661,6 +662,7 @@ namespace CoopClient
VehVelocity = vehVelocity,
VehSpeed = vehSpeed,
VehSteeringAngle = vehSteeringAngle,
VehAimCoords = veh.IsTurretSeat((int)player.SeatIndex) ? Util.GetVehicleAimCoords().ToLVector() : new LVector3(),
VehColors = new int[] { primaryColor, secondaryColor },
VehMods = vehMods,
VehDoors = vehDoors,

View File

@ -472,18 +472,21 @@ namespace CoopClient
public float VehSteeringAngle { get; set; }
[ProtoMember(13)]
public int[] VehColors { get; set; }
public LVector3 VehAimCoords { get; set; }
[ProtoMember(14)]
public Dictionary<int, int> VehMods { get; set; }
public int[] VehColors { get; set; }
[ProtoMember(15)]
public VehicleDoors[] VehDoors { get; set; }
public Dictionary<int, int> VehMods { get; set; }
[ProtoMember(16)]
public int VehTires { get; set; }
public VehicleDoors[] VehDoors { get; set; }
[ProtoMember(17)]
public int VehTires { get; set; }
[ProtoMember(18)]
public byte? Flag { get; set; } = 0;
public override void PacketToNetOutGoingMessage(NetOutgoingMessage message)
@ -514,6 +517,7 @@ namespace CoopClient
VehVelocity = data.VehVelocity;
VehSpeed = data.VehSpeed;
VehSteeringAngle = data.VehSteeringAngle;
VehAimCoords = data.VehAimCoords;
VehColors = data.VehColors;
VehMods = data.VehMods;
VehDoors = data.VehDoors;

View File

@ -139,6 +139,15 @@ namespace CoopClient
return aimOrShoot ? (isNpc ? GetLastWeaponImpact(ped) : RaycastEverything(new Vector2(0, 0))) : new Vector3();
}
/// <summary>
/// Only works for players NOT NPCs
/// </summary>
/// <returns>Vector3</returns>
public static Vector3 GetVehicleAimCoords()
{
return RaycastEverything(new Vector2(0, 0));
}
public static byte? GetVehicleFlags(this Vehicle veh, bool fullSync)
{
byte? flags = 0;
@ -337,6 +346,38 @@ namespace CoopClient
return coord.GetResult<Vector3>();
}
public static bool IsTurretSeat(this Vehicle veh, int seat)
{
if (!Function.Call<bool>(Hash.DOES_VEHICLE_HAVE_WEAPONS, veh.Handle))
{
return false;
}
switch (seat)
{
case -1:
return (VehicleHash)veh.Model.Hash == VehicleHash.Rhino
|| (VehicleHash)veh.Model.Hash == VehicleHash.Khanjari
|| (VehicleHash)veh.Model.Hash == VehicleHash.FireTruck;
case 1:
return (VehicleHash)veh.Model.Hash == VehicleHash.Valkyrie
|| (VehicleHash)veh.Model.Hash == VehicleHash.Valkyrie2
|| (VehicleHash)veh.Model.Hash == VehicleHash.Technical
|| (VehicleHash)veh.Model.Hash == VehicleHash.Technical2
|| (VehicleHash)veh.Model.Hash == VehicleHash.Technical3
|| (VehicleHash)veh.Model.Hash == VehicleHash.HalfTrack; // Not sure
case 2:
return (VehicleHash)veh.Model.Hash == VehicleHash.Valkyrie
|| (VehicleHash)veh.Model.Hash == VehicleHash.Valkyrie2;
case 3:
return (VehicleHash)veh.Model.Hash == VehicleHash.Limo2;
case 7:
return (VehicleHash)veh.Model.Hash == VehicleHash.Insurgent;
}
return false;
}
public static double DegToRad(double deg)
{
return deg * Math.PI / 180.0;

View File

@ -387,18 +387,21 @@ namespace CoopServer
public float VehSteeringAngle { get; set; }
[ProtoMember(13)]
public int[] VehColors { get; set; }
public LVector3 VehAimCoords { get; set; }
[ProtoMember(14)]
public Dictionary<int, int> VehMods { get; set; }
public int[] VehColors { get; set; }
[ProtoMember(15)]
public VehicleDoors[] VehDoors { get; set; }
public Dictionary<int, int> VehMods { get; set; }
[ProtoMember(16)]
public int VehTires { get; set; }
public VehicleDoors[] VehDoors { get; set; }
[ProtoMember(17)]
public int VehTires { get; set; }
[ProtoMember(18)]
public byte? Flag { get; set; } = 0;
public override void PacketToNetOutGoingMessage(NetOutgoingMessage message)
@ -429,6 +432,7 @@ namespace CoopServer
VehVelocity = data.VehVelocity;
VehSpeed = data.VehSpeed;
VehSteeringAngle = data.VehSteeringAngle;
VehAimCoords = data.VehAimCoords;
VehColors = data.VehColors;
VehMods = data.VehMods;
VehDoors = data.VehDoors;