Example #1
0
        public static int GetNearestBoneIndex(Ped ped, Vector3 hitPosition)
        {
            if (ped == null)
            {
                return(0);
            }

            float shortestBoneDistance = float.MaxValue;
            int   nearestBoneIndex     = 0;

            for (int i = 0; i < PedBoneArray.Length; i++)
            {
                Vector3 bonePosition = ped.GetBoneCoord(PedBoneArray[i]);
                float   boneDistance = bonePosition.DistanceTo(hitPosition);
                Bone    currentBone  = PedBoneArray[i];

                if (boneDistance < shortestBoneDistance)
                {
                    shortestBoneDistance = boneDistance;
                    nearestBoneIndex     = ped.GetBoneIndex(currentBone);
                }
            }

            return(nearestBoneIndex);
        }
Example #2
0
        public void ThirdPersonAimFreelook(Vector2 gazeNormalizedCenterDelta, Ped ped, double aspectRatio)
        {
            if (!GameplayCamera.IsRendering)
            {
                return;
            }

            double deltaX = 0;
            double deltaY = 0;

            if (_settings.ThirdPersonFreelookEnabled &&
                (!IsInFixedDeadzone(gazeNormalizedCenterDelta, aspectRatio)))
            {
                var freelookDeltaVector = new Vector2(gazeNormalizedCenterDelta.X, gazeNormalizedCenterDelta.Y);

                if (ped != null && ped != Game.Player.Character)
                {
                    Vector2 screenCoords;
                    var     pos = ped.GetBoneCoord(Bone.SKEL_L_Clavicle);
                    Geometry.WorldToScreenRel(pos, out screenCoords);
                    freelookDeltaVector = screenCoords;
                }

                deltaX = freelookDeltaVector.X * (float)(_settings.AimingSensitivity);
                deltaY = freelookDeltaVector.Y * (float)(_settings.AimingSensitivity);
            }

            EmulateHid(deltaX, deltaY);
        }
Example #3
0
        private void BomBatAction(Ped ped)
        {
            if (ped.HasBeenDamagedBy(Weapon.BAT))
            {
                GTA.World.AddExplosion(ped.Position + Vector3.WorldUp * 0.5f, GTA.ExplosionType.Grenade, 40.0f,
                                       0.5f);


                var randomVector = InfernoUtilities.CreateRandomVector();
                ped.ApplyForce(randomVector * Random.Next(10, 20));
                ped.Kill();
                Function.Call(Hash.CLEAR_PED_LAST_WEAPON_DAMAGE, ped);
            }
            else if (ped.HasBeenDamagedBy(Weapon.KNIFE))
            {
                GTA.World.AddExplosion(ped.Position, GTA.ExplosionType.Molotov1, 0.1f, 0.0f);
                Function.Call(Hash.CLEAR_PED_LAST_WEAPON_DAMAGE, ped);
            }
            else if (ped.HasBeenDamagedBy(Weapon.GOLFCLUB))
            {
                var randomVector = InfernoUtilities.CreateRandomVector();
                ped.SetToRagdoll(100);
                ped.Velocity = randomVector * 1000;
                ped.ApplyForce(randomVector * Random.Next(2000, 4000));
                Function.Call(Hash.CLEAR_PED_LAST_WEAPON_DAMAGE, ped);
            }
            else if (ped.HasBeenDamagedBy(Weapon.UNARMED) /*&& !ped.HasBeenDamagedByPed(PlayerPed)*/)
            {
                NativeFunctions.ShootSingleBulletBetweenCoords(
                    ped.Position + new Vector3(0, 0, 1),
                    ped.GetBoneCoord(Bone.IK_Head), 1, WeaponHash.StunGun, null, 1.0f);
                Function.Call(Hash.CLEAR_PED_LAST_WEAPON_DAMAGE, ped);
            }
            else if (ped.HasBeenDamagedBy(Weapon.HAMMER))
            {
                if (!ped.IsInRangeOf(PlayerPed.Position, 10))
                {
                    return;
                }
                Shock(ped);
                Function.Call(Hash.CLEAR_PED_LAST_WEAPON_DAMAGE, ped);
            }
            else if (ped.HasBeenDamagedBy(Weapon.Poolcue))
            {
                var blowVector = -ped.ForwardVector;
                ped.SetToRagdoll(1);
                ped.Velocity = blowVector * 10;
                ped.ApplyForce(blowVector * Random.Next(20, 40));
                Function.Call(Hash.CLEAR_PED_LAST_WEAPON_DAMAGE, ped);
            }
        }
Example #4
0
        /// <summary>
        /// Draws a dead marker over the ped head.
        /// </summary>
        /// <param name="GamePed">The ped where the dead marker should be drawn.</param>
        private void DeadMarker(Ped GamePed)
        {
            // Get the coordinates for the head
            Vector3 HeadCoord = GamePed.GetBoneCoord(Bone.SKEL_Head);
            // Get the On Screen position for the head
            Point ScreenPos = UI.WorldToScreen(HeadCoord);

            // Get distance ratio by Ln(Distance + Sqrt(e)), then calculate size of marker using intercept thereom.
            double Ratio = Math.Log(Vector3.Distance(Game.Player.Character.Position, HeadCoord) + 1.65);
            // Calculate the marker size based on the distance between player and dead ped
            Size LiteralMarker = LiteralSize(HudConfig.DeadMarkerWidth, HudConfig.DeadMarkerHeight);
            Size MarkerSize    = new Size((int)(LiteralMarker.Width / Ratio), (int)(LiteralMarker.Height / Ratio));

            // Offset the marker by half width to center, and full height to put on top.
            ScreenPos.Offset(-MarkerSize.Width / 2, -MarkerSize.Height);

            // Finally, draw the marker on screen
            DrawImage("DeadMarker", ScreenPos, MarkerSize);
        }
Example #5
0
        //public static bool IsEntityAfterAnother(Entity entity1, Entity entity2)
        //{
        //    Vector3 entity1Dimensions = entity1.Model.GetDimensions();
        //    Vector3 positionEntity1 = (entity1.ForwardVector) * entity1.Position;
        //}

        public static Vector3 GetNearestBonePosition(Ped ped, Vector3 hitPosition)
        {
            if (ped == null)
            {
                return(new Vector3(0, 0, 0));
            }

            float   shortestBoneDistance = float.MaxValue;
            Vector3 nearestBonePosition  = new Vector3(0, 0, 0);

            for (int i = 0; i < PedBoneArray.Length; i++)
            {
                Vector3 bonePosition = ped.GetBoneCoord(PedBoneArray[i]);
                float   boneDistance = bonePosition.DistanceTo(hitPosition);

                if (boneDistance < shortestBoneDistance)
                {
                    shortestBoneDistance = boneDistance;
                    nearestBonePosition  = bonePosition;
                }
            }

            return(nearestBonePosition);
        }
Example #6
0
        public void DisplayLocally()
        {
            try
            {
                var   isPlane = Function.Call <bool>(Hash.IS_THIS_MODEL_A_PLANE, VehicleHash);
                float hRange  = isPlane ? 1200f : 400f;

                var gPos    = IsInVehicle ? VehiclePosition : Position;
                var inRange = isPlane ? true : Game.Player.Character.IsInRangeOf(gPos, hRange);

                if (inRange && !_isStreamedIn)
                {
                    _isStreamedIn = true;
                    if (_mainBlip != null)
                    {
                        _mainBlip.Remove();
                        _mainBlip = null;
                    }
                }
                else if (!inRange && _isStreamedIn)
                {
                    Clear();
                    _isStreamedIn = false;
                }

                if (!inRange)
                {
                    if (_mainBlip == null && _blip)
                    {
                        _mainBlip       = World.CreateBlip(gPos);
                        _mainBlip.Color = BlipColor.White;
                        _mainBlip.Scale = 0.8f;
                        SetBlipName(_mainBlip, Name == null ? "<nameless>" : Name);
                    }
                    if (_blip && _mainBlip != null)
                    {
                        _mainBlip.Position = gPos;
                    }
                    return;
                }


                if (Character == null || !Character.Exists() || (!Character.IsInRangeOf(gPos, hRange) && Game.GameTime - LastUpdateReceived < 5000) || Character.Model.Hash != ModelHash || (Character.IsDead && PedHealth > 0))
                {
                    if (Character != null)
                    {
                        Character.Delete();
                    }

                    Character = World.CreatePed(new Model(ModelHash), gPos, Rotation.Z);
                    if (Character == null)
                    {
                        return;
                    }

                    Character.BlockPermanentEvents = true;
                    Character.IsInvincible         = true;
                    Character.CanRagdoll           = false;
                    Character.RelationshipGroup    = _relGroup;
                    if (_blip)
                    {
                        Character.AddBlip();
                        if (Character.CurrentBlip == null)
                        {
                            return;
                        }
                        Character.CurrentBlip.Color = BlipColor.White;
                        Character.CurrentBlip.Scale = 0.8f;
                        SetBlipName(Character.CurrentBlip, Name);
                    }

                    if (PedProps != null)
                    {
                        foreach (KeyValuePair <int, int> pedprop in PedProps)
                        {
                            Function.Call(Hash.SET_PED_COMPONENT_VARIATION, Character.Handle, pedprop.Key, pedprop.Value, 0, 0);
                        }
                    }

                    return;
                }

                if (!Character.IsOccluded && Character.IsInRangeOf(Game.Player.Character.Position, 20f))
                {
                    Vector3 targetPos = Character.GetBoneCoord(Bone.IK_Head) + new Vector3(0, 0, 0.5f);

                    targetPos += Character.Velocity / Game.FPS;

                    Function.Call(Hash.SET_DRAW_ORIGIN, targetPos.X, targetPos.Y, targetPos.Z, 0);

                    float sizeOffset = Math.Max(1f - ((GameplayCamera.Position - Character.Position).Length() / 30f), 0.3f);

                    new UIResText(Name ?? "<Nameless>", new Point(0, 0), 0.4f * sizeOffset, Color.WhiteSmoke, Font.ChaletLondon, UIResText.Alignment.Centered)
                    {
                        Outline = true,
                    }.Draw();

                    Function.Call(Hash.CLEAR_DRAW_ORIGIN);
                }

                if ((!_lastVehicle && IsInVehicle && VehicleHash != 0) || (_lastVehicle && IsInVehicle && (MainVehicle == null || !Character.IsInVehicle(MainVehicle) || MainVehicle.Model.Hash != VehicleHash || VehicleSeat != Util.GetPedSeat(Character))))
                {
                    if (MainVehicle != null && Util.IsVehicleEmpty(MainVehicle))
                    {
                        MainVehicle.Position = MainVehicle.GetOffsetInWorldCoords(new Vector3(0, 0, -100));
                        MainVehicle.Delete();
                    }

                    var vehs = World.GetAllVehicles().OrderBy(v =>
                    {
                        if (v == null)
                        {
                            return(float.MaxValue);
                        }
                        return((v.Position - Character.Position).Length());
                    }).ToList();


                    if (vehs.Any() && vehs[0].Model.Hash == VehicleHash && vehs[0].IsInRangeOf(gPos, 3f))
                    {
                        MainVehicle = vehs[0];

                        /*if (Game.Player.Character.IsInVehicle(MainVehicle) &&
                         *  VehicleSeat == Util.GetPedSeat(Game.Player.Character))
                         * {
                         *  Game.Player.Character.Task.WarpOutOfVehicle(MainVehicle);
                         *  UI.Notify("~r~Car jacked!");
                         * }*/
                    }
                    else
                    {
                        MainVehicle = World.CreateVehicle(new Model(VehicleHash), gPos, 0);
                    }

                    if (MainVehicle != null)
                    {
                        Function.Call(Hash.SET_VEHICLE_COLOURS, MainVehicle, VehiclePrimaryColor, VehicleSecondaryColor);
                        MainVehicle.Livery = Livery;

                        MainVehicle.Quaternion   = VehicleRotation;
                        MainVehicle.IsInvincible = true;
                        Character.SetIntoVehicle(MainVehicle, (VehicleSeat)VehicleSeat);

                        /*if (_playerSeat != -2 && !Game.Player.Character.IsInVehicle(_mainVehicle))
                         * { // TODO: Fix me.
                         *  Game.Player.Character.Task.WarpIntoVehicle(_mainVehicle, (VehicleSeat)_playerSeat);
                         * }*/
                    }

                    _lastVehicle         = true;
                    _justEnteredVeh      = true;
                    _enterVehicleStarted = DateTime.Now;
                    return;
                }

                if (_lastVehicle && _justEnteredVeh && IsInVehicle && !Character.IsInVehicle(MainVehicle) && DateTime.Now.Subtract(_enterVehicleStarted).TotalSeconds <= 4)
                {
                    return;
                }
                _justEnteredVeh = false;

                if (_lastVehicle && !IsInVehicle && MainVehicle != null)
                {
                    if (Character != null)
                    {
                        Character.Task.LeaveVehicle(MainVehicle, true);
                    }
                }

                Character.Health = PedHealth;

                _switch++;

                if (!inRange)
                {
                    if (Character != null && Game.GameTime - LastUpdateReceived < 10000)
                    {
                        if (!IsInVehicle)
                        {
                            Character.PositionNoOffset = gPos;
                        }
                        else if (MainVehicle != null && GetResponsiblePed(MainVehicle).Handle == Character.Handle)
                        {
                            MainVehicle.Position   = VehiclePosition;
                            MainVehicle.Quaternion = VehicleRotation;
                        }
                    }
                    return;
                }

                if (IsInVehicle)
                {
                    if (GetResponsiblePed(MainVehicle).Handle == Character.Handle)
                    {
                        MainVehicle.Health = VehicleHealth;
                        if (MainVehicle.Health <= 0)
                        {
                            MainVehicle.IsInvincible = false;
                            //_mainVehicle.Explode();
                        }
                        else
                        {
                            MainVehicle.IsInvincible = true;
                            if (MainVehicle.IsDead)
                            {
                                MainVehicle.Repair();
                            }
                        }

                        MainVehicle.EngineRunning = IsEngineRunning;

                        if (Plate != null)
                        {
                            MainVehicle.NumberPlate = Plate;
                        }

                        var radioStations = Util.GetRadioStations();

                        if (radioStations?.ElementAtOrDefault(RadioStation) != null)
                        {
                            Function.Call(Hash.SET_VEH_RADIO_STATION, radioStations[RadioStation]);
                        }

                        if (VehicleMods != null && _modSwitch % 50 == 0 &&
                            Game.Player.Character.IsInRangeOf(VehiclePosition, 30f))
                        {
                            var id = _modSwitch / 50;

                            if (VehicleMods.ContainsKey(id) && VehicleMods[id] != MainVehicle.GetMod((VehicleMod)id))
                            {
                                Function.Call(Hash.SET_VEHICLE_MOD_KIT, MainVehicle.Handle, 0);
                                MainVehicle.SetMod((VehicleMod)id, VehicleMods[id], false);
                                Function.Call(Hash.RELEASE_PRELOAD_MODS, id);
                            }
                        }
                        _modSwitch++;

                        if (_modSwitch >= 2500)
                        {
                            _modSwitch = 0;
                        }

                        if (IsHornPressed && !_lastHorn)
                        {
                            _lastHorn = true;
                            MainVehicle.SoundHorn(99999);
                        }

                        if (!IsHornPressed && _lastHorn)
                        {
                            _lastHorn = false;
                            MainVehicle.SoundHorn(1);
                        }

                        if (IsInBurnout && !_lastBurnout)
                        {
                            Function.Call(Hash.SET_VEHICLE_BURNOUT, MainVehicle, true);
                            Function.Call(Hash.TASK_VEHICLE_TEMP_ACTION, Character, MainVehicle, 23, 120000); // 30 - burnout
                        }
                        else if (!IsInBurnout && _lastBurnout)
                        {
                            Function.Call(Hash.SET_VEHICLE_BURNOUT, MainVehicle, false);
                            Character.Task.ClearAll();
                        }

                        _lastBurnout = IsInBurnout;

                        Function.Call(Hash.SET_VEHICLE_BRAKE_LIGHTS, MainVehicle, Speed > 0.2 && _lastSpeed > Speed);

                        if (MainVehicle.SirenActive && !Siren)
                        {
                            MainVehicle.SirenActive = Siren;
                        }
                        else if (!MainVehicle.SirenActive && Siren)
                        {
                            MainVehicle.SirenActive = Siren;
                        }

                        MainVehicle.LightsOn    = LightsOn;
                        MainVehicle.HighBeamsOn = HighBeamsOn;
                        MainVehicle.SirenActive = Siren;
                        if (Steering != MainVehicle.SteeringAngle)
                        {
                            Util.CustomSteeringAngle(MainVehicle.Handle, (float)(Math.PI / 180) * Steering);
                        }
                        Function.Call(Hash.SET_VEHICLE_LIVERY, MainVehicle, Livery);

                        Function.Call(Hash.SET_VEHICLE_COLOURS, MainVehicle, VehiclePrimaryColor, VehicleSecondaryColor);

                        if (MainVehicle.Model.IsPlane && LandingGear != MainVehicle.LandingGear)
                        {
                            MainVehicle.LandingGear = LandingGear;
                        }

                        if (Character.IsOnBike && MainVehicle.ClassType == VehicleClass.Cycles)
                        {
                            var isPedaling     = IsPedaling(false);
                            var isFastPedaling = IsPedaling(true);
                            if (Speed < 2f)
                            {
                                if (isPedaling)
                                {
                                    StopPedalingAnim(false);
                                }
                                else if (isFastPedaling)
                                {
                                    StopPedalingAnim(true);
                                }
                            }
                            else if (Speed < 11f && !isPedaling)
                            {
                                StartPedalingAnim(false);
                            }
                            else if (Speed >= 11f && !isFastPedaling)
                            {
                                StartPedalingAnim(true);
                            }
                        }

                        if ((Speed > 0.2f || IsInBurnout) && MainVehicle.IsInRangeOf(VehiclePosition, 7.0f))
                        {
                            MainVehicle.Velocity = VehicleVelocity + (VehiclePosition - MainVehicle.Position);

                            MainVehicle.Quaternion = Quaternion.Slerp(MainVehicle.Quaternion, VehicleRotation, 0.5f);

                            _stopTime = Game.GameTime;
                        }
                        else if ((Game.GameTime - _stopTime) <= 1000)
                        {
                            Vector3 posTarget = Util.LinearVectorLerp(MainVehicle.Position, VehiclePosition + (VehiclePosition - MainVehicle.Position), (Game.GameTime - _stopTime), 1000);
                            MainVehicle.PositionNoOffset = posTarget;
                            MainVehicle.Quaternion       = Quaternion.Slerp(MainVehicle.Quaternion, VehicleRotation, 0.5f);
                        }
                        else
                        {
                            MainVehicle.PositionNoOffset = VehiclePosition;
                            MainVehicle.Quaternion       = VehicleRotation;
                        }
                    }
                }
                else
                {
                    if (PedProps != null && _clothSwitch % 50 == 0 && Game.Player.Character.IsInRangeOf(Position, 30f))
                    {
                        var id = _clothSwitch / 50;

                        if (PedProps.ContainsKey(id) &&
                            PedProps[id] != Function.Call <int>(Hash.GET_PED_DRAWABLE_VARIATION, Character.Handle, id))
                        {
                            Function.Call(Hash.SET_PED_COMPONENT_VARIATION, Character.Handle, id, PedProps[id], 0, 0);
                        }
                    }

                    _clothSwitch++;
                    if (_clothSwitch >= 750)
                    {
                        _clothSwitch = 0;
                    }

                    if (Character.Weapons.Current.Hash != (WeaponHash)CurrentWeapon)
                    {
                        var wep = Character.Weapons.Give((WeaponHash)CurrentWeapon, 9999, true, true);
                        Character.Weapons.Select(wep);
                    }

                    if (!_lastJumping && IsJumping)
                    {
                        Character.Task.Jump();
                    }

                    if (IsParachuteOpen)
                    {
                        if (_parachuteProp == null)
                        {
                            _parachuteProp = World.CreateProp(new Model(1740193300), Character.Position,
                                                              Character.Rotation, false, false);
                            _parachuteProp.FreezePosition = true;
                            Function.Call(Hash.SET_ENTITY_COLLISION, _parachuteProp.Handle, false, 0);
                        }
                        Character.FreezePosition  = true;
                        Character.Position        = Position - new Vector3(0, 0, 1);
                        Character.Quaternion      = Rotation;
                        _parachuteProp.Position   = Character.Position + new Vector3(0, 0, 3.7f);
                        _parachuteProp.Quaternion = Character.Quaternion;

                        Character.Task.PlayAnimation("skydive@parachute@first_person", "chute_idle_right", 8f, 5000,
                                                     false, 8f);
                    }
                    else
                    {
                        var dest = Position;
                        Character.FreezePosition = false;

                        if (_parachuteProp != null)
                        {
                            _parachuteProp.Delete();
                            _parachuteProp = null;
                        }

                        const int threshold = 50;
                        if (IsAiming && !IsShooting && !Character.IsInRangeOf(Position, 0.5f) && _switch % threshold == 0)
                        {
                            Function.Call(Hash.TASK_GO_TO_COORD_WHILE_AIMING_AT_COORD, Character.Handle, dest.X, dest.Y,
                                          dest.Z, AimCoords.X, AimCoords.Y, AimCoords.Z, 2f, 0, 0x3F000000, 0x40800000, 1, 512, 0,
                                          (uint)FiringPattern.FullAuto);
                        }
                        else if (IsAiming && !IsShooting && Character.IsInRangeOf(Position, 0.5f))
                        {
                            Character.Task.AimAt(AimCoords, 100);
                        }

                        if (!Character.IsInRangeOf(Position, 0.5f) &&
                            ((IsShooting && !_lastShooting) ||
                             (IsShooting && _lastShooting && _switch % (threshold * 2) == 0)))
                        {
                            Function.Call(Hash.TASK_GO_TO_COORD_WHILE_AIMING_AT_COORD, Character.Handle, dest.X, dest.Y,
                                          dest.Z, AimCoords.X, AimCoords.Y, AimCoords.Z, 2f, 1, 0x3F000000, 0x40800000, 1, 0, 0,
                                          (uint)FiringPattern.FullAuto);
                        }
                        else if ((IsShooting && !_lastShooting) ||
                                 (IsShooting && _lastShooting && _switch % (threshold / 2) == 0))
                        {
                            Function.Call(Hash.TASK_SHOOT_AT_COORD, Character.Handle, AimCoords.X, AimCoords.Y,
                                          AimCoords.Z, 1500, (uint)FiringPattern.FullAuto);
                        }

                        if (!IsAiming && !IsShooting && !IsJumping && !IsInParachuteFreeFall)
                        {
                            float distance = Character.Position.DistanceTo(Position);
                            if (distance <= 0.15f || distance > 7.0f) // Still or too far away
                            {
                                if (distance > 7.0f)
                                {
                                    Character.Position   = dest - new Vector3(0, 0, 1f);
                                    Character.Quaternion = Rotation;
                                }
                            }
                            else if (distance <= 1.25f) // Walking
                            {
                                Function.Call(Hash.TASK_GO_STRAIGHT_TO_COORD, Character, Position.X, Position.Y, Position.Z, 1.0f, -1, Character.Heading, 0.0f);
                                Function.Call(Hash.SET_PED_DESIRED_MOVE_BLEND_RATIO, Character, 1.0f);
                            }
                            else if (distance > 1.75f) // Sprinting
                            {
                                Function.Call(Hash.TASK_GO_STRAIGHT_TO_COORD, Character, Position.X, Position.Y, Position.Z, 3.0f, -1, Character.Heading, 2.0f);
                                Function.Call(Hash.SET_RUN_SPRINT_MULTIPLIER_FOR_PLAYER, Character, 1.49f);
                                Function.Call(Hash.SET_PED_DESIRED_MOVE_BLEND_RATIO, Character, 3.0f);
                            }
                            else // Running
                            {
                                Function.Call(Hash.TASK_GO_STRAIGHT_TO_COORD, Character, Position.X, Position.Y, Position.Z, 4.0f, -1, Character.Heading, 1.0f);
                                Function.Call(Hash.SET_PED_DESIRED_MOVE_BLEND_RATIO, Character, 2.0f);
                            }
                        }

                        if (IsInParachuteFreeFall)
                        {
                            if (!Function.Call <bool>(Hash.IS_PED_IN_PARACHUTE_FREE_FALL, Character))
                            {
                                Function.Call(Hash.TASK_SKY_DIVE, Character);
                            }
                            Character.Position   = dest - new Vector3(0, 0, 1f);
                            Character.Quaternion = Rotation;
                        }
                    }
                    _lastJumping  = IsJumping;
                    _lastShooting = IsShooting;
                    _lastAiming   = IsAiming;
                }
                _lastVehicle = IsInVehicle;
            }
            catch (Exception ex)
            {
                UI.Notify("Sync error: " + ex.Message);
                Main.Logger.WriteException("Exception in SyncPed code", ex);
            }
        }
Example #7
0
        private void FindGazeProjection(out Vector3 shootCoord, out Vector3 shootCoordSnap, out Vector3 shootMissileCoord, out Ped ped)
        {
            const float joystickRadius = 0.1f;

            var controllerState = _controllerEmulation.ControllerState;

            var joystickDelta = new Vector2(controllerState.Gamepad.RightThumbX, -controllerState.Gamepad.RightThumbY) *
                                (1.0f / 32768.0f) * joystickRadius;

            var w = (float)(1 - _settings.GazeFiltering * 0.9);

            _gazePointDelta = new Vector2(_gazePointDelta.X + (_lastNormalizedCenterDelta.X - _gazePointDelta.X) * w,
                                          _gazePointDelta.Y + (_lastNormalizedCenterDelta.Y - _gazePointDelta.Y) * w);

            _gazePlusJoystickDelta           = _gazePointDelta + joystickDelta;
            _unfilteredgazePlusJoystickDelta = _lastNormalizedCenterDelta;

            var hitUnfiltered = Geometry.RaycastEverything(_unfilteredgazePlusJoystickDelta);

            shootMissileCoord = hitUnfiltered;
            shootCoordSnap    = hitUnfiltered;

            var hitFiltered = Geometry.RaycastEverything(_gazePlusJoystickDelta);

            shootCoord = hitFiltered;


            ped = Geometry.RaycastPed(_unfilteredgazePlusJoystickDelta);
            if ((ped != null) &&
                (ped.Handle != Game.Player.Character.Handle))
            {
                shootCoordSnap = ped.GetBoneCoord(Bone.SKEL_L_Clavicle);

                if (_settings.SnapAtPedestriansEnabled)
                {
                    shootCoord = shootCoordSnap;
                }
            }
            else
            {
                var vehicle = Geometry.RaycastVehicle(_unfilteredgazePlusJoystickDelta);
                if (vehicle != null &&
                    !((Game.Player.Character.IsInVehicle()) &&
                      (vehicle.Handle == Game.Player.Character.CurrentVehicle.Handle)))
                {
                    shootCoordSnap    = vehicle.Position + vehicle.Velocity * 0.06f;
                    shootMissileCoord = shootCoordSnap;
                }
            }
            var playerDistToGround = Game.Player.Character.Position.Z - World.GetGroundHeight(Game.Player.Character.Position);
            var targetDir          = shootMissileCoord - Game.Player.Character.Position;

            targetDir.Normalize();
            var justBeforeTarget   = shootMissileCoord - targetDir;
            var targetDistToGround = shootMissileCoord.Z - World.GetGroundHeight(justBeforeTarget);
            var distToTarget       = (Game.Player.Character.Position - shootMissileCoord).Length();

            if ((playerDistToGround < 2) && (playerDistToGround >= -0.5))             //on the ground
            {
                if (((targetDistToGround < 2) && (targetDistToGround >= -0.5)) ||              //shoot too low
                    ((targetDistToGround < 5) && (targetDistToGround >= -0.5) && (distToTarget > 70.0))) //far away add near the ground
                {
                    shootMissileCoord.Z = World.GetGroundHeight(justBeforeTarget)                        //ground level at target
                                          + playerDistToGround;                                          //offset
                }
            }

            if (!_menuOpen &&
                (controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.DPadDown) ||
                 User32.IsKeyPressed(VirtualKeyStates.VK_LMENU)))
            {
                //character selection
            }
            else if (!_isInVehicle && controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.LeftShoulder))
            {
                _radialMenu.Process(_lastNormalizedCenterDelta, _aspectRatio);
            }
            else
            {
                _freelook.Process(_lastNormalizedCenterDelta, ped, _aspectRatio);
            }
        }
Example #8
0
        /// <summary>
        /// This will fire at the targeted ped and will handle changing targets
        /// </summary>
        /// <param name="firstButton">The first (aiming) button which needs to pressed before handling this update</param>
        /// <param name="secondButton">The second (firing) button which needs to pressed before the actual shooting</param>
        private void UpdateCombat(Func <bool> firstButton, Func <bool> secondButton)
        {
            if (Input.isPressed(DeviceButton.DPadLeft))
            {
                foreach (WeaponHash projectile in throwables)
                {
                    Function.Call(Hash.EXPLODE_PROJECTILES, Ped, new InputArgument(projectile), true);
                }
            }
            if (firstButton.Invoke())
            {
                if (!secondButton.Invoke())
                {
                    Targets = GetTargets();
                }
                if (CanDoAction(PlayerPedAction.SelectTarget, 500))
                {
                    Direction dir = Input.GetDirection(DeviceButton.RightStick);
                    if (Input.IsDirectionLeft(dir))
                    {
                        TargetIndex--;
                        UpdateLastAction(PlayerPedAction.SelectTarget);
                    }
                    if (Input.IsDirectionRight(dir))
                    {
                        TargetIndex++;
                        UpdateLastAction(PlayerPedAction.SelectTarget);
                    }
                }

                Ped target = Targets.ElementAtOrDefault(TargetIndex);

                if (target == null)
                {
                    return;
                }

                if (!target.IsAlive)
                {
                    Targets = GetTargets();
                }

                if (target != null)
                {
                    World.DrawMarker(MarkerType.UpsideDownCone, target.GetBoneCoord(Bone.SKEL_Head) + new Vector3(0, 0, 1), GameplayCamera.Direction, GameplayCamera.Rotation, new Vector3(1, 1, 1), Color.OrangeRed);

                    if (secondButton.Invoke())
                    {
                        SelectWeapon(Ped, weapons[WeaponIndex]);

                        if (IsThrowable(weapons[WeaponIndex]))
                        {
                            if (CanDoAction(PlayerPedAction.ThrowTrowable, 1500))
                            {
                                Function.Call(Hash.TASK_THROW_PROJECTILE, Ped, target.Position.X, target.Position.Y, target.Position.Z);
                                UpdateLastAction(PlayerPedAction.ThrowTrowable);
                            }
                        }
                        else if (CanDoAction(PlayerPedAction.Shoot, 750))
                        {
                            if (Ped.IsInVehicle())
                            {
                                Function.Call(Hash.TASK_DRIVE_BY, Ped, target, 0, 0, 0, 0, 50.0f, 100, 1, (uint)FiringPattern.FullAuto);
                            }
                            else if (IsMelee(weapons[WeaponIndex]))
                            {
                                // Ped.Task.ShootAt(target, 750, FiringPattern.FullAuto);
                                // UI.ShowSubtitle("Melee weapons are not supported yet.");
                                Ped.Task.FightAgainst(target, -1);
                            }
                            else
                            {
                                Ped.Task.ShootAt(target, 750, FiringPattern.FullAuto);
                            }

                            UpdateLastAction(PlayerPedAction.Shoot);
                        }
                    }
                    else
                    {
                        Ped.Task.AimAt(target, 100);
                    }
                }

                if (Ped.IsOnScreen)
                {
                    Vector3 headPos = Ped.GetBoneCoord(Bone.SKEL_Head);
                    headPos.Z += 0.3f;
                    headPos.X += 0.1f;

                    UIRectangle rect = new UIRectangle(UI.WorldToScreen(headPos), new Size(MaxHealth / 2, 5), Color.LimeGreen);
                    rect.Draw();
                    rect.Size  = new Size(Ped.Health / 2, 5);
                    rect.Color = Color.IndianRed;
                    rect.Draw();
                }
            }
            else
            {
                TargetIndex = 0;
            }
        }
Example #9
0
        /// <summary>
        /// くっつけるコルーチン
        /// </summary>
        IEnumerable <object> PedAttachCoroutine(Ped ped, Vehicle veh)
        {
            var handleId = ped.Handle;

            ped.SetToRagdoll(1, 2);
            SetPedProof(ped, true);

            //ターゲットが車に触るまでforceを加える
            foreach (var s in WaitForSeconds(3))
            {
                if (!IsEnableStatus(ped, veh))
                {
                    processingPedIdSet.Remove(ped.Handle);
                    yield break;
                }

                //触ったら終わり
                if (ped.IsTouching(veh))
                {
                    break;
                }

                //車に向かって引っ張る
                var dir = (veh.Position + Vector3.WorldUp * 2.0f - ped.Position).Normalized;
                ped.ApplyForce(dir * 3.0f, Vector3.Zero, ForceType.MaxForceRot2);
                yield return(null);
            }

            //オブジェクトが消失した、または車に触っていなかったら終了
            if (!IsEnableStatus(ped, veh) || !ped.IsTouching(veh))
            {
                if (ped.IsSafeExist())
                {
                    SetPedProof(ped, false);
                }
                processingPedIdSet.Remove(ped.Handle);
                yield break;
            }

            var rHandCoord     = ped.GetBoneCoord(Bone.SKEL_R_Hand);
            var offsetPosition = Function.Call <Vector3>(Hash.GET_OFFSET_FROM_ENTITY_GIVEN_WORLD_COORDS,
                                                         veh,
                                                         rHandCoord.X,
                                                         rHandCoord.Y,
                                                         rHandCoord.Z);

            //掴み始めたら追加
            processingPedList.Add(ped);

            //掴みループ
            while (IsEnableStatus(ped, veh))
            {
                GripVehicle(ped, veh, offsetPosition);
                yield return(null);
            }

            if (ped.IsSafeExist())
            {
                ReleaseVehicle(ped);
            }
            processingPedIdSet.Remove(handleId);
        }
        public void FindGazeProjection(
            Vector2 gazePoint,
            Vector2 joystickDelta,
            out Vector3 shootCoord,
            out Vector3 shootCoordSnap,
            out Vector3 shootMissileCoord,
            out Ped ped,
            out Entity missileTarget
            )
        {
            Entity target = null;

            var w = (float)(1 - _settings.Responsiveness * 0.9);

            _filteredGazePoint = new Vector2(_filteredGazePoint.X + (gazePoint.X - _filteredGazePoint.X) * w,
                                             _filteredGazePoint.Y + (gazePoint.Y - _filteredGazePoint.Y) * w);

            var filteredGazePointPlusJoystickDelta   = _filteredGazePoint + joystickDelta;
            var unfilteredGazePointPlusJoystickDelta = gazePoint;

            Entity unfilteredEntity;
            Entity filteredEntity;
            var    hitUnfiltered = Geometry.ConecastPedsAndVehicles(unfilteredGazePointPlusJoystickDelta, out unfilteredEntity);

            shootMissileCoord = hitUnfiltered;
            shootCoordSnap    = hitUnfiltered;


            var hitFiltered = Geometry.RaycastEverything(filteredGazePointPlusJoystickDelta, out filteredEntity, 0);

            shootCoord = hitFiltered;


            if (unfilteredEntity != null &&
                ScriptHookExtensions.IsEntityAPed(unfilteredEntity) &&
                unfilteredEntity.IsAlive)
            {
                ped = unfilteredEntity as Ped;
            }
            else
            {
                //if (_frameSkip == 0)
                //{
                //	ped = Geometry.SearchPed(unfilteredGazePointPlusJoystickDelta); //Too slow :(
                //	_lastPed = ped;
                //}
                //else
                {
                    ped = _lastPed;
                }
            }

            if ((ped != null) &&
                (ped.Handle != Game.Player.Character.Handle))
            {
                shootCoordSnap = ped.GetBoneCoord(Bone.SKEL_L_Clavicle);
                target         = ped;
                if (_settings.SnapAtTargetsEnabled)
                {
                    shootCoord = shootCoordSnap;
                }
            }
            else
            {
                Vehicle vehicle;
                if (unfilteredEntity != null &&
                    ScriptHookExtensions.IsEntityAVehicle(unfilteredEntity) &&
                    unfilteredEntity.IsAlive)
                {
                    vehicle = unfilteredEntity as Vehicle;
                }
                else
                {
                    //if (_frameSkip == 0)
                    //{
                    //	vehicle = Geometry.SearchVehicle(unfilteredGazePointPlusJoystickDelta); // Too slow :(
                    //	_lastVehicle = vehicle;
                    //}
                    //else
                    {
                        vehicle = _lastVehicle;
                    }
                }

                if (vehicle != null &&
                    !((Game.Player.Character.IsInVehicle()) &&
                      (vehicle.Handle == Game.Player.Character.CurrentVehicle.Handle)))
                {
                    shootCoordSnap    = vehicle.Position + vehicle.Velocity * 0.06f;
                    shootMissileCoord = shootCoordSnap;
                    target            = vehicle;
                }
            }


            ProcessMissileLock(target);


            missileTarget = _missileTarget;
            _frameSkip++;
            if (_frameSkip > _maxSkipFrames)
            {
                _frameSkip = 0;
            }
        }
Example #11
0
        public void FindGazeProjection(
            Vector2 gazePoint,
            Vector2 joystickDelta,
            out Vector3 shootCoord,
            out Vector3 shootCoordSnap,
            out Vector3 shootMissileCoord,
            out Ped ped,
            out Entity missileTarget
            )
        {
            Entity target = null;

            var w = (float)(1 - _settings.GazeFiltering * 0.9);

            _filteredGazePoint = new Vector2(_filteredGazePoint.X + (gazePoint.X - _filteredGazePoint.X) * w,
                                             _filteredGazePoint.Y + (gazePoint.Y - _filteredGazePoint.Y) * w);

            var filteredGazePointPlusJoystickDelta   = _filteredGazePoint + joystickDelta;
            var unfilteredGazePointPlusJoystickDelta = gazePoint;

            Entity unfilteredEntity;
            Entity filteredEntity;
            var    hitUnfiltered = Geometry.ConecastPedsAndVehicles(unfilteredGazePointPlusJoystickDelta, out unfilteredEntity);

            shootMissileCoord = hitUnfiltered;
            shootCoordSnap    = hitUnfiltered;
            //Util.Log("B - " + DateTime.UtcNow.Ticks);

            var hitFiltered = Geometry.RaycastEverything(filteredGazePointPlusJoystickDelta, out filteredEntity, true);

            shootCoord = hitFiltered;
            //Util.Log("C - " + DateTime.UtcNow.Ticks);

            if (unfilteredEntity != null &&
                Util.IsEntityAPed(unfilteredEntity))
            {
                ped = unfilteredEntity as Ped;
            }
            else
            {
                if (_frameSkip == 0)
                {
                    ped      = Geometry.SearchPed(unfilteredGazePointPlusJoystickDelta);                //Too slow :(
                    _lastPed = ped;
                }
                else
                {
                    ped = _lastPed;
                }
            }

            if ((ped != null) &&
                (ped.Handle != Game.Player.Character.Handle))
            {
                shootCoordSnap = ped.GetBoneCoord(Bone.SKEL_L_Clavicle);
                target         = ped;
                if (_settings.SnapAtPedestriansEnabled)
                {
                    shootCoord = shootCoordSnap;
                }
            }
            else
            {
                //Util.Log("D - " + DateTime.UtcNow.Ticks);
                Vehicle vehicle;
                if (unfilteredEntity != null &&
                    Util.IsEntityAVehicle(unfilteredEntity))
                {
                    vehicle = unfilteredEntity as Vehicle;
                }
                else
                {
                    if (_frameSkip == 0)
                    {
                        vehicle      = Geometry.SearchVehicle(unfilteredGazePointPlusJoystickDelta);                    // Too slow :(
                        _lastVehicle = vehicle;
                    }
                    else
                    {
                        vehicle = _lastVehicle;
                    }
                }

                if (vehicle != null &&
                    !((Game.Player.Character.IsInVehicle()) &&
                      (vehicle.Handle == Game.Player.Character.CurrentVehicle.Handle)))
                {
                    shootCoordSnap    = vehicle.Position + vehicle.Velocity * 0.06f;
                    shootMissileCoord = shootCoordSnap;
                    target            = vehicle;
                }
            }
            //Util.Log("E - " + DateTime.UtcNow.Ticks);

            ProcessMissileLock(target);
            //Util.Log("F - " + DateTime.UtcNow.Ticks);

            missileTarget = _missileTarget;
            _frameSkip++;
            if (_frameSkip > _maxSkipFrames)
            {
                _frameSkip = 0;
            }
        }
Example #12
0
        private void OnTick(object sender, EventArgs eventArgs)
        {
            Ped           playerPed = Game.Player.Character;
            int           model     = playerPed.Model.Hash;
            VariationInfo v         = null;

            foreach (var var in _variationInfos)
            {
                if (var.ModelHash != model)
                {
                    continue;
                }
                v = var;
                break;
            }
            if (v == null)
            {
                return;
            }

            bool isWeather    = (World.Weather == Weather.Raining || World.Weather == Weather.ThunderStorm) && v.AllowRain;
            bool isUnderwater = playerPed.IsSwimmingUnderWater || (playerPed.IsSwimming && playerPed.IsSprinting);
            bool isHeadWet    = (isWeather || isUnderwater) && !playerPed.IsWearingHelmet;

            if (isHeadWet)
            {
                if (_isWatered)
                {
                    return;
                }

                var boneCoord = playerPed.GetBoneCoord((Bone)v.DepthBone);
                if (boneCoord != Vector3.Zero)
                {
                    unsafe
                    {
                        float depth = 0f;
                        Function.Call(Hash.GET_WATER_HEIGHT, boneCoord.X, boneCoord.Y, boneCoord.Z, &depth);
                        depth = Math.Max(depth - boneCoord.Z, 0f);

                        if (depth < v.MinDepth)
                        {
                            return;
                        }
                    }
                }

                Function.Call(Hash.SET_PED_COMPONENT_VARIATION, playerPed, (uint)v.Variation, v.WetDrawableIndex,
                              v.WetTextureIndex, 0);

                v.ResetTimer();
                _isWatered = true;
            }
            else
            {
                if (!_isWatered)
                {
                    return;
                }
                if (v.m_WetnessTimer > 0)
                {
                    v.m_WetnessTimer -= Game.LastFrameTime;
                    return;
                }
                Function.Call(Hash.SET_PED_COMPONENT_VARIATION, playerPed, (uint)v.Variation,
                              v.DryDrawableIndex, v.DryTextureIndex, 0);
                _isWatered = false;
            }
        }