/// <summary>
        /// spawns a vehicle that has the player as destination
        /// </summary>
        public SpawnedDrivingGangMember SpawnAngryVehicle(bool isFriendly)
        {
            Math.Vector3 spawnPos  = SpawnManager.instance.FindGoodSpawnPointForCar(),
                         playerPos = MindControl.CurrentPlayerCharacter.Position;

            if (spawnPos == Vector3.Zero)
            {
                return(null);
            }

            SpawnedDrivingGangMember spawnedVehicle = null;

            if (!isFriendly && spawnedEnemies - 4 < maxSpawnedEnemies)
            {
                spawnedVehicle = SpawnManager.instance.SpawnGangVehicle(enemyGang,
                                                                        spawnPos, playerPos, true, false, IncrementEnemiesCount);
            }
            else if (spawnedAllies - 4 < maxSpawnedAllies)
            {
                spawnedVehicle = SpawnManager.instance.SpawnGangVehicle(GangManager.instance.PlayerGang,
                                                                        spawnPos, playerPos, true, false, IncrementAlliesCount);
            }

            return(spawnedVehicle);
        }
        public void SpawnAmbientVehicle(Gang curGang)
        {
            Vector3 vehSpawnPoint = SpawnManager.instance.FindGoodSpawnPointForCar();
            SpawnedDrivingGangMember spawnedVehicleAI = SpawnManager.instance.SpawnGangVehicle(curGang,
                                                                                               vehSpawnPoint, Vector3.Zero, true);

            if (spawnedVehicleAI != null)
            {
                SpawnManager.instance.TryPlaceVehicleOnStreet(spawnedVehicleAI.vehicleIAmDriving, vehSpawnPoint);
                Ped driver = spawnedVehicleAI.watchedPed;
                if (driver != null) //if, for some reason, we don't have a driver, do nothing
                {
                    driver.Task.CruiseWithVehicle(spawnedVehicleAI.vehicleIAmDriving, 20, ModOptions.instance.wanderingDriverDrivingStyle);
                }
            }
        }
Example #3
0
        SpawnedDrivingGangMember EnlistDrivingMember(Ped pedToEnlist, Vehicle vehicleDriven, Vector3 destPos, bool friendlyToPlayer, bool playerIsDest = false, bool mustReachDest = false)
        {
            SpawnedDrivingGangMember newDriverAI = null;

            bool couldEnlistWithoutAdding = false;

            for (int i = 0; i < livingDrivingMembers.Count; i++)
            {
                if (livingDrivingMembers[i].watchedPed == null)
                {
                    newDriverAI = livingDrivingMembers[i];
                    livingDrivingMembers[i].AttachData(pedToEnlist, vehicleDriven, destPos, friendlyToPlayer, playerIsDest, mustReachDest);
                    couldEnlistWithoutAdding = true;
                    break;
                }
            }
            if (!couldEnlistWithoutAdding)
            {
                newDriverAI = new SpawnedDrivingGangMember(pedToEnlist, vehicleDriven, destPos, friendlyToPlayer, playerIsDest, mustReachDest);
                livingDrivingMembers.Add(newDriverAI);
            }

            return(newDriverAI);
        }
Example #4
0
        public SpawnedDrivingGangMember SpawnGangVehicle(Gang ownerGang, Vector3 spawnPos, Vector3 destPos, bool playerIsDest = false, bool mustReachDest = false, SuccessfulMemberSpawnDelegate onSuccessfulPassengerSpawn = null)
        {
            if (livingMembersCount >= ModOptions.instance.spawnedMemberLimit || spawnPos == Vector3.Zero || ownerGang.carVariations == null)
            {
                //don't start spawning, we're on the limit already or we failed to find a good spawn point or we haven't started up our data properly yet
                return(null);
            }

            if (ownerGang.carVariations.Count > 0)
            {
                Logger.Log("spawn car: start");
                Vehicle newVehicle = World.CreateVehicle(RandoMath.GetRandomElementFromList(ownerGang.carVariations).modelHash, spawnPos);
                if (newVehicle != null)
                {
                    newVehicle.PrimaryColor = ownerGang.vehicleColor;


                    SpawnedGangMember driver = SpawnGangMember(ownerGang, spawnPos, onSuccessfulMemberSpawn: onSuccessfulPassengerSpawn);

                    if (driver != null)
                    {
                        driver.curStatus = SpawnedGangMember.MemberStatus.inVehicle;
                        driver.watchedPed.SetIntoVehicle(newVehicle, VehicleSeat.Driver);

                        int passengerCount = newVehicle.PassengerSeats;
                        if (destPos == Vector3.Zero && passengerCount > 4)
                        {
                            passengerCount = 4;                                                //limit ambient passengers in order to have less impact in ambient spawning
                        }
                        for (int i = 0; i < passengerCount; i++)
                        {
                            SpawnedGangMember passenger = SpawnGangMember(ownerGang, spawnPos, onSuccessfulMemberSpawn: onSuccessfulPassengerSpawn);
                            if (passenger != null)
                            {
                                passenger.curStatus = SpawnedGangMember.MemberStatus.inVehicle;
                                passenger.watchedPed.SetIntoVehicle(newVehicle, VehicleSeat.Any);
                            }
                        }

                        SpawnedDrivingGangMember driverAI = EnlistDrivingMember(driver.watchedPed, newVehicle, destPos, ownerGang == GangManager.instance.PlayerGang, playerIsDest, mustReachDest);

                        if (ModOptions.instance.showGangMemberBlips)
                        {
                            newVehicle.AddBlip();
                            newVehicle.CurrentBlip.IsShortRange = true;

                            Function.Call(Hash.SET_BLIP_COLOUR, newVehicle.CurrentBlip, ownerGang.blipColor);
                        }

                        Logger.Log("spawn car: end (success)");
                        return(driverAI);
                    }
                    else
                    {
                        newVehicle.Delete();
                        Logger.Log("spawn car: end (fail: couldnt spawn driver)");
                        return(null);
                    }
                }

                Logger.Log("spawn car: end (fail: car creation failed)");
            }

            return(null);
        }