Exemplo n.º 1
0
        static async Task ReAttachWeapons()
        {
            WeaponDisplay.GetAllDisplayedWeaponObjects()
            .Where(d => !(d.Value is null) && d.Value.Exists())
            .ToList()
            .ForEach(d =>
            {
                var weaponDisplayGroup = d.Key;
                var weaponObject       = d.Value;
                var weapon             = WeaponDisplay.GetWeapon(weaponDisplayGroup);

                // Try sync
                API.NetworkRegisterEntityAsNetworked(API.ObjToNet(weaponObject.Handle));
                weaponObject.IsPersistent = true;
                var netId = API.NetworkGetNetworkIdFromEntity(weaponObject.Handle);
                API.SetNetworkIdCanMigrate(netId, true);
                API.SetNetworkIdExistsOnAllMachines(netId, true);
                API.NetworkRequestControlOfEntity(weaponObject.Handle);

                AttachWeapon(weapon, weaponObject);
                Debug.WriteLine($"[{ResourceName}]ReAttachWeapon: weapon: {weapon.Hash}, model: {weaponObject.Model.Hash}, handle: {weaponObject.Handle}");
            });

            await Delay(1000 * 10);
        }
Exemplo n.º 2
0
        public WeaponOnBack()
        {
            _previousWeaponInHand = Game.PlayerPed.Weapons[WeaponHash.Unarmed];

            Tick += UpdateWeaponsOnBackAsync;

        #if DEBUG
            API.RegisterCommand("wob-current", new Action(() =>
            {
                var currentWeapon           = Game.PlayerPed.Weapons.Current;
                var currentWeaponSlot       = API.GetWeapontypeSlot((uint)currentWeapon.Hash);
                var currentWeapontypeInSlot = API.GetPedWeapontypeInSlot(Game.PlayerPed.Handle, (uint)currentWeaponSlot);
                Debug.WriteLine($"currentWeapon: {(uint)currentWeapon.Hash}");
                Debug.WriteLine($"Game.PlayerPed.Weapons.Current.Group: {(uint)Game.PlayerPed.Weapons.Current.Group}");
                Debug.WriteLine($"currentWeaponSlot: {(uint)currentWeaponSlot}");
                Debug.WriteLine($"currentWeapontypeInSlot: {(uint)currentWeapontypeInSlot}");
            }), false);

            API.RegisterCommand("wob-pos", new Action <int, List <object>, string>((source, args, raw) =>
            {
                var weaponObject = Entity.FromHandle(int.Parse(args[0].ToString()));

                if (weaponObject is null || !weaponObject.Exists())
                {
                    return;
                }

                var pedBone   = Game.PlayerPed.Bones[(Bone)int.Parse(args[1].ToString())];
                var attachPos = new Vector3(float.Parse(args[2].ToString()), float.Parse(args[3].ToString()), float.Parse(args[4].ToString()));
                var attachRot = new Vector3(float.Parse(args[5].ToString()), float.Parse(args[6].ToString()), float.Parse(args[7].ToString()));
                weaponObject.AttachTo(pedBone, attachPos, attachRot);
                // CurrentWeaponsOnBack.Values.ForEach(weaponObject => { });
            }), false);

            API.RegisterCommand("wob-view", new Action(() =>
            {
                Debug.WriteLine("_weaponAttachedObject");
                WeaponDisplay.GetAllDisplayedWeaponObjects().ForEach(kvp =>
                {
                    var weaponObject = kvp.Value;
                    Debug.WriteLine($"weapon: {weaponObject?.Model}({weaponObject?.Model.Hash}), modelHandle: {weaponObject?.Handle}");
                });
            }), false);
        #endif
        }
Exemplo n.º 3
0
        public WeaponOnBack()
        {
            _previousWeaponInHand = Game.PlayerPed.Weapons[WeaponHash.Unarmed];

            Tick += UpdateWeaponsOnBackAsync;
            Tick += LoadWeaponAsset;
            Tick += ReAttachWeapons;

            API.RegisterCommand("wob", new Action <int, List <object>, string>((source, args, raw) =>
            {
                try
                {
                    var commandArg1  = args[0].ToString().ToLower();
                    var weapon       = _latestWeaponOnBack;
                    var weaponObject = _latestWeaponObjectOnBack;

                    switch (commandArg1)
                    {
                    case "pos":
                    case "position":
                        var position = new Vector3(
                            float.Parse(args[1].ToString()) / 100,
                            float.Parse(args[2].ToString()) / 100,
                            float.Parse(args[3].ToString()) / 100);
                        WeaponOffset.Set(weapon.Hash, WeaponOffset.OffsetType.Position, position);
                        AttachWeapon(weapon, weaponObject);
                        Debug.WriteLine($"[{ResourceName}]{GameModeName}:{ResourceName}:CommandSucceed: {raw}");
                        TriggerEvent($"{GameModeName}:{ResourceName}:CommandSucceed", raw);
                        break;

                    case "rot":
                    case "rotation":
                        var rotation = new Vector3(
                            float.Parse(args[1].ToString()),
                            float.Parse(args[2].ToString()),
                            float.Parse(args[3].ToString()));
                        WeaponOffset.Set(weapon.Hash, WeaponOffset.OffsetType.Rotation, rotation);
                        AttachWeapon(weapon, weaponObject);
                        Debug.WriteLine($"[{ResourceName}]{GameModeName}:{ResourceName}:CommandSucceed: {raw}");
                        TriggerEvent($"{GameModeName}:{ResourceName}:CommandSucceed", raw);
                        break;

//			        case "reg":
//				        // Sync
//				        var handle = weaponObject.Handle;
//
//				        if (API.NetworkGetEntityIsNetworked(weaponObject.Handle))
//				        {
//					        Debug.WriteLine($"not networked {weaponObject.Handle}");
//				        }
//				        weaponObject.IsPersistent = true;
//				        var netId = API.NetworkGetNetworkIdFromEntity(handle);
//				        API.NetworkRegisterEntityAsNetworked(API.ObjToNet(handle));
//				        API.SetNetworkIdCanMigrate(netId, true);
//				        API.SetNetworkIdExistsOnAllMachines(netId, true);
//				        API.NetworkRequestControlOfEntity(handle);
//				        Debug.WriteLine($"try set prop as networked {weaponObject.Handle}");
//				        break;
                    default:
                        Debug.WriteLine($"[{ResourceName}]{GameModeName}:{ResourceName}:CommandFailed: {raw}");
                        TriggerEvent($"{GameModeName}:{ResourceName}:CommandFailed", raw);
                        break;
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine($"[{ResourceName}][ERROR]{e.Message}");
                    // Debug.WriteLine($"[{ResourceName}]Usage: /wob pos [posX] [posY] [posZ]");
                    // Debug.WriteLine($"[{ResourceName}]Usage: /wob rot [rotX] [rotY] [rotZ]");
                    Debug.WriteLine($"[{ResourceName}]{GameModeName}:{ResourceName}:CommandFailed: {raw}");
                    TriggerEvent($"{GameModeName}:{ResourceName}:CommandFailed", raw);
                }
            }), false);

        #if DEBUG
            API.RegisterCommand("wob-current", new Action(() =>
            {
                var currentWeapon           = Game.PlayerPed.Weapons.Current;
                var currentWeaponSlot       = API.GetWeapontypeSlot((uint)currentWeapon.Hash);
                var currentWeapontypeInSlot = API.GetPedWeapontypeInSlot(Game.PlayerPed.Handle, (uint)currentWeaponSlot);
                Debug.WriteLine($"currentWeapon: {(uint)currentWeapon.Hash}");
                Debug.WriteLine($"Game.PlayerPed.Weapons.Current.Group: {(uint)Game.PlayerPed.Weapons.Current.Group}");
                Debug.WriteLine($"currentWeaponSlot: {(uint)currentWeaponSlot}");
                Debug.WriteLine($"currentWeapontypeInSlot: {(uint)currentWeapontypeInSlot}");
            }), false);

            API.RegisterCommand("wob-pos", new Action <int, List <object>, string>((source, args, raw) =>
            {
                var weaponObject = Entity.FromHandle(int.Parse(args[0].ToString()));

                if (weaponObject is null || !weaponObject.Exists())
                {
                    return;
                }

                var pedBone   = Game.PlayerPed.Bones[(Bone)int.Parse(args[1].ToString())];
                var attachPos = new Vector3(float.Parse(args[2].ToString()), float.Parse(args[3].ToString()), float.Parse(args[4].ToString()));
                var attachRot = new Vector3(float.Parse(args[5].ToString()), float.Parse(args[6].ToString()), float.Parse(args[7].ToString()));
                weaponObject.AttachTo(pedBone, attachPos, attachRot);
                // CurrentWeaponsOnBack.Values.ForEach(weaponObject => { });
            }), false);

            API.RegisterCommand("wob-view", new Action(() =>
            {
                Debug.WriteLine("_weaponAttachedObject");
                WeaponDisplay.GetAllDisplayedWeaponObjects().ForEach(kvp =>
                {
                    var weaponObject = kvp.Value;
                    Debug.WriteLine($"weapon: {weaponObject?.Model}({weaponObject?.Model.Hash}), modelHandle: {weaponObject?.Handle}");
                });
            }), false);
        #endif
        }