Weapon sync cleanup 1
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using GTA;
|
using GTA;
|
||||||
using GTA.Math;
|
using GTA.Math;
|
||||||
|
using GTA.Native;
|
||||||
using Lidgren.Network;
|
using Lidgren.Network;
|
||||||
using RageCoop.Client.Scripting;
|
using RageCoop.Client.Scripting;
|
||||||
using RageCoop.Core;
|
using RageCoop.Core;
|
||||||
@ -25,15 +26,6 @@ namespace RageCoop.Client
|
|||||||
}, ConnectionChannel.SyncEvents, NetDeliveryMethod.ReliableOrdered);
|
}, 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)
|
public static void TriggerNozzleTransform(int vehID, bool hover)
|
||||||
{
|
{
|
||||||
Networking.SendSync(new Packets.NozzleTransform { VehicleID = vehID, Hover = hover },
|
Networking.SendSync(new Packets.NozzleTransform { VehicleID = vehID, Hover = hover },
|
||||||
@ -89,8 +81,9 @@ namespace RageCoop.Client
|
|||||||
var asset = new WeaponAsset(weaponHash);
|
var asset = new WeaponAsset(weaponHash);
|
||||||
if (!asset.IsLoaded) asset.Request();
|
if (!asset.IsLoaded) asset.Request();
|
||||||
|
|
||||||
bool isVeh = p.VehicleWeapon != VehicleWeaponHash.Invalid;
|
var vehWeap = p.VehicleWeapon;
|
||||||
var bone = c.GetMuzzleBone(isVeh);
|
bool isVeh = vehWeap != VehicleWeaponHash.Invalid;
|
||||||
|
var bone = isVeh ? c.MainPed.CurrentVehicle.GetMuzzleBone(vehWeap) : c.MainPed.GetMuzzleBone();
|
||||||
|
|
||||||
World.ShootBullet(bone.Position, end, p, asset, damage);
|
World.ShootBullet(bone.Position, end, p, asset, damage);
|
||||||
|
|
||||||
@ -148,21 +141,14 @@ namespace RageCoop.Client
|
|||||||
bool getBulletImpact()
|
bool getBulletImpact()
|
||||||
{
|
{
|
||||||
var endPos = subject.LastWeaponImpactPosition;
|
var endPos = subject.LastWeaponImpactPosition;
|
||||||
|
var vehWeap = subject.VehicleWeapon;
|
||||||
// Impact found
|
if (vehWeap == VehicleWeaponHash.Invalid)
|
||||||
|
{
|
||||||
|
// Ped weapon sync
|
||||||
|
var pedWeap = subject.Weapons.Current.Hash;
|
||||||
if (endPos != default)
|
if (endPos != default)
|
||||||
{
|
{
|
||||||
TriggerBulletShot(c, endPos);
|
Networking.SendBullet(c.ID, (uint)pedWeap, endPos);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
var vehWeap = subject.VehicleWeapon;
|
|
||||||
|
|
||||||
// Not found, but it's shot from a vehicle
|
|
||||||
if (vehWeap != VehicleWeaponHash.Invalid)
|
|
||||||
{
|
|
||||||
var b = c.MainPed.CurrentVehicle.GetMuzzleBone(vehWeap);
|
|
||||||
TriggerBulletShot(c, b.Position + b.ForwardVector * 200);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,8 +157,20 @@ namespace RageCoop.Client
|
|||||||
|
|
||||||
// Exceeded maximum wait of 5 ticks, return (inaccurate) aim coordinate
|
// Exceeded maximum wait of 5 ticks, return (inaccurate) aim coordinate
|
||||||
endPos = subject.GetAimCoord();
|
endPos = subject.GetAimCoord();
|
||||||
TriggerBulletShot(c, endPos);
|
Networking.SendBullet(c.ID, (uint)pedWeap, endPos);
|
||||||
return true;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,11 +101,9 @@ namespace RageCoop.Client
|
|||||||
return result;
|
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.Weapons.CurrentWeaponObject?.Bones["gun_muzzle"];
|
||||||
|
|
||||||
return p.MainPed?.Weapons.CurrentWeaponObject?.Bones["gun_muzzle"];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float GetWeaponDamage(this Ped P, uint hash)
|
public static float GetWeaponDamage(this Ped P, uint hash)
|
||||||
|
Reference in New Issue
Block a user