Exemplo n.º 1
0
        static async Task UpdateWeaponsOnBackAsync()
        {
            await Delay(100);

            var currentWeaponInHand = Game.PlayerPed.Weapons.Current;

            // is weapon in hand changed?
            var isWeaponInHandChanged = _previousWeaponInHand != currentWeaponInHand;

            if (!isWeaponInHandChanged)
            {
                return;
            }

            var previousWeaponDisplayGroup = WeaponDisplay.GetWeaponDisplayGroup(_previousWeaponInHand);
            var currentWeaponDisplayGroup  = WeaponDisplay.GetWeaponDisplayGroup(currentWeaponInHand);

            // update
            WeaponDisplay.SetWeapon(currentWeaponInHand);
            // prevent duplicate weapon objects
            WeaponDisplay.DeleteWeaponObject(currentWeaponDisplayGroup);
            WeaponDisplay.DeleteWeaponObject(previousWeaponDisplayGroup);

            var weaponNeedToCreate = _previousWeaponInHand;

            // update previous weapon in hand
            _previousWeaponInHand = currentWeaponInHand;

            var isWeaponNeedToDisplay =
                weaponNeedToCreate.Model.IsValid && weaponNeedToCreate.Model.IsInCdImage &&
                !WeaponGroupBlacklist.Contains(weaponNeedToCreate.Group) &&
                !WeaponBlacklist.Contains(weaponNeedToCreate.Hash);

            if (!isWeaponNeedToDisplay)
            {
                return;
            }

            var weaponObject = await CreateWeaponObject(weaponNeedToCreate);

            if (weaponObject is null)
            {
                Debug.WriteLine($"[{ResourceName}]Create object {weaponNeedToCreate.Model.Hash} failed");
                return;
            }

            AttachWeapon(weaponNeedToCreate, weaponObject);

            WeaponDisplay.SetWeapon(WeaponDisplay.GetWeaponDisplayGroup(weaponNeedToCreate), weaponNeedToCreate);
            WeaponDisplay.SetWeaponObject(WeaponDisplay.GetWeaponDisplayGroup(weaponNeedToCreate), weaponObject);

            _latestWeaponObjectOnBack = weaponObject;
            _latestWeaponOnBack       = weaponNeedToCreate;
        }
Exemplo n.º 2
0
        static async Task UpdateWeaponsOnBackAsync()
        {
            await Delay(100);

            var currentWeaponInHand = Game.PlayerPed.Weapons.Current;

            // is weapon in hand changed?
            var isWeaponInHandChanged = _previousWeaponInHand != currentWeaponInHand;

            if (!isWeaponInHandChanged)
            {
                return;
            }

            var previousWeaponDisplayGroup = WeaponDisplay.GetWeaponDisplayGroup(_previousWeaponInHand);
            var currentWeaponDisplayGroup  = WeaponDisplay.GetWeaponDisplayGroup(currentWeaponInHand);

            // update
            WeaponDisplay.SetWeapon(currentWeaponInHand);
            // prevent duplicate weapon objects
            WeaponDisplay.DeleteWeaponObject(currentWeaponDisplayGroup);
            WeaponDisplay.DeleteWeaponObject(previousWeaponDisplayGroup);

            var weaponNeedToCreate = _previousWeaponInHand;

            // update previous weapon in hand
            _previousWeaponInHand = currentWeaponInHand;

            var isWeaponNeedToDisplay =
                weaponNeedToCreate.Model.IsValid && weaponNeedToCreate.Model.IsInCdImage &&
                !WeaponGroupsBlacklist.Contains(weaponNeedToCreate.Group) &&
                !WeaponsBlacklist.Contains(weaponNeedToCreate.Hash);

            if (!isWeaponNeedToDisplay)
            {
                return;
            }

            var weaponObject = await CreateWeaponObject(weaponNeedToCreate);

            if (weaponObject is null)
            {
                Debug.WriteLine($"[{ResourceName}]Create object {weaponNeedToCreate.Model.Hash} failed");
                return;
            }

            var info = WeaponsAttachDetails.Single(wad => wad.WeaponGroup == weaponNeedToCreate.Group);

            weaponObject.AttachTo(Game.PlayerPed.Bones[info.Bone], info.Position, info.Rotation);
            Debug.WriteLine($"[{ResourceName}]Attach {weaponNeedToCreate.Hash}({weaponNeedToCreate.Group}) to {info.Bone}, {info.Position}, {info.Rotation}");

            WeaponDisplay.SetWeaponObject(WeaponDisplay.GetWeaponDisplayGroup(weaponNeedToCreate), weaponObject);
        }