Weapon sync cleanup 1

This commit is contained in:
Sardelka9515
2023-03-19 13:43:46 +08:00
parent ba8c2c741d
commit 0cb1098819
2 changed files with 32 additions and 36 deletions

View File

@ -1,6 +1,7 @@
using System;
using GTA;
using GTA.Math;
using GTA.Native;
using Lidgren.Network;
using RageCoop.Client.Scripting;
using RageCoop.Core;
@ -25,15 +26,6 @@ namespace RageCoop.Client
}, ConnectionChannel.SyncEvents, NetDeliveryMethod.ReliableOrdered);
}
public static void TriggerBulletShot(SyncedPed owner, Vector3 impactPosition)
{
var hash = (uint)owner.MainPed.VehicleWeapon;
if (hash == (uint)VehicleWeaponHash.Invalid)
hash = (uint)owner.MainPed.Weapons.Current.Hash;
Networking.SendBullet(owner.ID, hash, impactPosition);
}
public static void TriggerNozzleTransform(int vehID, bool hover)
{
Networking.SendSync(new Packets.NozzleTransform { VehicleID = vehID, Hover = hover },
@ -89,8 +81,9 @@ namespace RageCoop.Client
var asset = new WeaponAsset(weaponHash);
if (!asset.IsLoaded) asset.Request();
bool isVeh = p.VehicleWeapon != VehicleWeaponHash.Invalid;
var bone = c.GetMuzzleBone(isVeh);
var vehWeap = p.VehicleWeapon;
bool isVeh = vehWeap != VehicleWeaponHash.Invalid;
var bone = isVeh ? c.MainPed.CurrentVehicle.GetMuzzleBone(vehWeap) : c.MainPed.GetMuzzleBone();
World.ShootBullet(bone.Position, end, p, asset, damage);
@ -148,31 +141,36 @@ namespace RageCoop.Client
bool getBulletImpact()
{
var endPos = subject.LastWeaponImpactPosition;
// Impact found
if (endPos != default)
{
TriggerBulletShot(c, endPos);
return true;
}
var vehWeap = subject.VehicleWeapon;
// Not found, but it's shot from a vehicle
if (vehWeap != VehicleWeaponHash.Invalid)
if (vehWeap == VehicleWeaponHash.Invalid)
{
var b = c.MainPed.CurrentVehicle.GetMuzzleBone(vehWeap);
TriggerBulletShot(c, b.Position + b.ForwardVector * 200);
// Ped weapon sync
var pedWeap = subject.Weapons.Current.Hash;
if (endPos != default)
{
Networking.SendBullet(c.ID, (uint)pedWeap, endPos);
return true;
}
// Get impact in next tick
if (++i <= 5) return false;
// Exceeded maximum wait of 5 ticks, return (inaccurate) aim coordinate
endPos = subject.GetAimCoord();
Networking.SendBullet(c.ID, (uint)pedWeap, endPos);
return true;
}
else
{
// Veh weapon sync
if (endPos == default)
{
var b = c.MainPed.CurrentVehicle.GetMuzzleBone(vehWeap);
endPos = b.Position + b.ForwardVector * 200;
}
Networking.SendBullet(c.ID, (uint)vehWeap, endPos);
return true;
}
// Get impact in next tick
if (++i <= 5) return false;
// Exceeded maximum wait of 5 ticks, return (inaccurate) aim coordinate
endPos = subject.GetAimCoord();
TriggerBulletShot(c, endPos);
return true;
}

View File

@ -101,11 +101,9 @@ namespace RageCoop.Client
return result;
}
public static EntityBone GetMuzzleBone(this SyncedPed p, bool veh)
public static EntityBone GetMuzzleBone(this Ped p)
{
if (veh) return p.MainPed.CurrentVehicle.GetMuzzleBone(p.VehicleWeapon);
return p.MainPed?.Weapons.CurrentWeaponObject?.Bones["gun_muzzle"];
return p.Weapons.CurrentWeaponObject?.Bones["gun_muzzle"];
}
public static float GetWeaponDamage(this Ped P, uint hash)