public void SpawnMember(bool isFriendly)
        {
            Vector3 spawnPos = isFriendly ?
                               RandoMath.GetRandomElementFromArray(alliedSpawnPoints) : RandoMath.GetRandomElementFromArray(enemySpawnPoints);

            if (spawnPos == default(Vector3))
            {
                return;                               //this means we don't have spawn points set yet
            }
            SpawnedGangMember spawnedMember = null;

            if (isFriendly)
            {
                if (spawnedAllies < maxSpawnedAllies)
                {
                    spawnedMember = SpawnManager.instance.SpawnGangMember(GangManager.instance.PlayerGang, spawnPos, onSuccessfulMemberSpawn: IncrementAlliesCount);
                }
                else
                {
                    return;
                }
            }
            else
            {
                if (spawnedEnemies < maxSpawnedEnemies)
                {
                    spawnedMember = SpawnManager.instance.SpawnGangMember(enemyGang, spawnPos, onSuccessfulMemberSpawn: IncrementEnemiesCount);
                }
                else
                {
                    return;
                }
            }
        }
Exemple #2
0
        public void RestorePlayerBody()
        {
            Ped oldPed = CurrentPlayerCharacter;

            //return to original body
            Function.Call(Hash.CHANGE_PLAYER_PED, Game.Player, theOriginalPed, true, true);
            Game.Player.MaxArmor = 100;
            theOriginalPed.CurrentBlip.Remove();
            theOriginalPed.MaxHealth = defaultMaxHealth;
            if (theOriginalPed.Health > theOriginalPed.MaxHealth)
            {
                theOriginalPed.Health = theOriginalPed.MaxHealth;
            }
            theOriginalPed.Task.ClearAllImmediately();

            if (hasDiedWithChangedBody)
            {
                oldPed.IsInvincible = false;
                oldPed.Health       = 0;
                oldPed.MarkAsNoLongerNeeded();
                oldPed.Kill();
            }
            else
            {
                oldPed.Health            = oldPed.Armor + 100;
                oldPed.RelationshipGroup = GangManager.instance.PlayerGang.relationGroupIndex;
                oldPed.Task.ClearAllImmediately();
            }

            hasDiedWithChangedBody        = false;
            Game.Player.Money             = moneyFromLastProtagonist;
            Game.Player.IgnoredByEveryone = false;
            currentlyControlledMember     = null;
        }
Exemple #3
0
        /// <summary>
        /// takes control of a random gang member in the vicinity.
        /// if there isnt any, creates one parachuting.
        /// you can only respawn if you have died as a gang member
        /// </summary>
        public void RespawnIfPossible()
        {
            if (hasDiedWithChangedBody)
            {
                Ped oldPed = CurrentPlayerCharacter;

                List <Ped> respawnOptions = SpawnManager.instance.GetSpawnedPedsOfGang
                                                (GangManager.instance.PlayerGang);

                for (int i = 0; i < respawnOptions.Count; i++)
                {
                    if (respawnOptions[i].IsAlive && !respawnOptions[i].IsInVehicle())
                    {
                        //we have a new body then
                        TakePedBody(respawnOptions[i]);

                        DiscardDeadBody(oldPed);
                        return;
                    }
                }

                //lets parachute if no one outside a veh is around
                SpawnedGangMember spawnedPara = SpawnManager.instance.SpawnGangMember
                                                    (GangManager.instance.PlayerGang,
                                                    CurrentPlayerCharacter.Position + Vector3.WorldUp * 70);
                if (spawnedPara != null)
                {
                    TakePedBody(spawnedPara.watchedPed);
                    spawnedPara.watchedPed.Weapons.Give(WeaponHash.Parachute, 1, true, true);
                    DiscardDeadBody(oldPed);
                }
            }
        }
Exemple #4
0
        void TakePedBody(Ped targetPed)
        {
            targetPed.Task.ClearAllImmediately();

            Function.Call(Hash.CHANGE_PLAYER_PED, Game.Player, targetPed, true, true);
            Game.Player.MaxArmor      = targetPed.Armor + targetPed.MaxHealth;
            targetPed.Armor          += targetPed.Health;
            targetPed.MaxHealth       = 5000;
            targetPed.Health          = 5000;
            currentlyControlledMember = SpawnManager.instance.GetTargetMemberAI(targetPed);

            Game.Player.CanControlCharacter = true;
        }
Exemple #5
0
        public Ped SpawnParachutingMember(Gang ownerGang, Vector3 spawnPos, Vector3 destPos)
        {
            SpawnedGangMember spawnedPara = SpawnGangMember(ownerGang, spawnPos);

            if (spawnedPara != null)
            {
                spawnedPara.watchedPed.BlockPermanentEvents = true;
                spawnedPara.watchedPed.Task.ParachuteTo(destPos);
                return(spawnedPara.watchedPed);
            }

            return(null);
        }
Exemple #6
0
        /// <summary>
        /// calls Die on the passengers' AI then clearsAllRefs
        /// </summary>
        public void DespawnProcedure()
        {
            for (int i = 0; i < myPassengers.Count; i++)
            {
                if (myPassengers[i] != null && myPassengers[i].IsAlive && !myPassengers[i].IsPlayer)
                {
                    SpawnedGangMember memberAI = SpawnManager.instance.GetTargetMemberAI(myPassengers[i]);
                    if (memberAI != null)
                    {
                        memberAI.Die();
                    }
                }
            }

            if (!watchedPed.IsPlayer)
            {
                SpawnedGangMember memberAI = SpawnManager.instance.GetTargetMemberAI(watchedPed);
                if (memberAI != null)
                {
                    memberAI.Die();
                }
            }
            ClearAllRefs();
        }
 public void SpawnAmbientMember(Gang curGang)
 {
     Vector3 spawnPos = SpawnManager.instance.FindGoodSpawnPointForMember
                            (MindControl.CurrentPlayerCharacter.Position);
     SpawnedGangMember newMember = SpawnManager.instance.SpawnGangMember(curGang, spawnPos);
 }
Exemple #8
0
        public override void Update()
        {
            if (vehicleIAmDriving.IsAlive && watchedPed.IsAlive)
            {
                if (destination != Vector3.Zero)
                {
                    RideToDest();
                }
                else
                {
                    //we are just wandering arond

                    //if there is a war going on and we're in the war zone, get to the player to help/kill him!
                    if (GangWarManager.instance.isOccurring && GangWarManager.instance.warZone == ZoneManager.instance.GetCurrentTurfZone())
                    {
                        playerAsDest            = true;
                        updatesWhileGoingToDest = 0;
                        RideToDest();
                        return;
                    }

                    //the driver can also do some drive-by
                    if (ModOptions.instance.gangMemberAggressiveness !=
                        ModOptions.gangMemberAggressivenessMode.defensive && ModOptions.instance.fightingEnabled)
                    {
                        watchedPed.Task.FightAgainstHatedTargets(100);
                    }


                    //stop tracking this driver/vehicle if he/she leaves the vehicle
                    if (!watchedPed.IsInVehicle())
                    {
                        ClearAllRefs();
                        return;
                    }

                    //if we get too far from the player, despawn
                    if (World.GetDistance(vehicleIAmDriving.Position, Game.Player.Character.Position) >
                        ModOptions.instance.maxDistanceCarSpawnFromPlayer * 1.5f)
                    {
                        if (!watchedPed.IsPlayer)
                        {
                            SpawnedGangMember memberAI = GangManager.instance.GetTargetMemberAI(watchedPed);
                            if (memberAI != null)
                            {
                                memberAI.Die();
                            }
                        }


                        for (int i = 0; i < myPassengers.Count; i++)
                        {
                            if (!myPassengers[i].IsPlayer)
                            {
                                SpawnedGangMember memberAI = GangManager.instance.GetTargetMemberAI(myPassengers[i]);
                                if (memberAI != null)
                                {
                                    memberAI.Die();
                                }
                            }
                        }
                        ClearAllRefs();
                    }
                }
            }
            else
            {
                //our vehicle has been destroyed/ our driver has died

                for (int i = 0; i < myPassengers.Count; i++)
                {
                    if (myPassengers[i].IsAlive && myPassengers[i].IsInVehicle(vehicleIAmDriving))
                    {
                        myPassengers[i].Task.LeaveVehicle();
                    }
                }
                ClearAllRefs();
            }
        }
Exemple #9
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);
        }
Exemple #10
0
        public SpawnedGangMember SpawnGangMember(Gang ownerGang, Vector3 spawnPos, SuccessfulMemberSpawnDelegate onSuccessfulMemberSpawn = null)
        {
            if (livingMembersCount >= ModOptions.instance.spawnedMemberLimit || spawnPos == Vector3.Zero || ownerGang.memberVariations == 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.memberVariations.Count > 0)
            {
                Logger.Log("spawn member: begin");
                PotentialGangMember chosenMember =
                    RandoMath.GetRandomElementFromList(ownerGang.memberVariations);
                Ped newPed = World.CreatePed(chosenMember.modelHash, spawnPos);
                if (newPed != null)
                {
                    chosenMember.SetPedAppearance(newPed);

                    newPed.Accuracy  = ownerGang.memberAccuracyLevel;
                    newPed.MaxHealth = ownerGang.memberHealth;
                    newPed.Health    = ownerGang.memberHealth;
                    newPed.Armor     = ownerGang.memberArmor;

                    newPed.Money = RandoMath.CachedRandom.Next(60);

                    //set the blip, if enabled
                    if (ModOptions.instance.showGangMemberBlips)
                    {
                        newPed.AddBlip();
                        newPed.CurrentBlip.IsShortRange = true;
                        newPed.CurrentBlip.Scale        = 0.65f;
                        Function.Call(Hash.SET_BLIP_COLOUR, newPed.CurrentBlip, ownerGang.blipColor);

                        //set blip name - got to use native, the c# blip.name returns error ingame
                        Function.Call(Hash.BEGIN_TEXT_COMMAND_SET_BLIP_NAME, "STRING");
                        Function.Call(Hash._ADD_TEXT_COMPONENT_STRING, ownerGang.name + " member");
                        Function.Call(Hash.END_TEXT_COMMAND_SET_BLIP_NAME, newPed.CurrentBlip);
                    }


                    bool hasDriveByGun = false; //used for when the member has to decide between staying inside a vehicle or not

                    //give a weapon
                    if (ownerGang.gangWeaponHashes.Count > 0)
                    {
                        //get one weap from each type... if possible AND we're not forcing melee only
                        newPed.Weapons.Give(ownerGang.GetListedGunFromOwnedGuns(ModOptions.instance.meleeWeapons), 1000, false, true);
                        if (!ModOptions.instance.membersSpawnWithMeleeOnly)
                        {
                            WeaponHash driveByGun = ownerGang.GetListedGunFromOwnedGuns(ModOptions.instance.driveByWeapons);
                            hasDriveByGun = driveByGun != WeaponHash.Unarmed;
                            newPed.Weapons.Give(driveByGun, 1000, false, true);
                            newPed.Weapons.Give(ownerGang.GetListedGunFromOwnedGuns(ModOptions.instance.primaryWeapons), 1000, false, true);

                            //and one extra
                            newPed.Weapons.Give(RandoMath.GetRandomElementFromList(ownerGang.gangWeaponHashes), 1000, false, true);
                        }
                    }

                    //set the relationship group
                    newPed.RelationshipGroup = ownerGang.relationGroupIndex;

                    newPed.NeverLeavesGroup = true;

                    //newPed.BlockPermanentEvents = true;
                    //newPed.StaysInVehicleWhenJacked = true;

                    Function.Call(Hash.SET_CAN_ATTACK_FRIENDLY, newPed, false, false); //cannot attack friendlies
                    Function.Call(Hash.SET_PED_COMBAT_ABILITY, newPed, 100);           //average combat ability
                    //Function.Call(Hash.SET_PED_FLEE_ATTRIBUTES, newPed, 0, 0); //clears the flee attributes?

                    Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, newPed, 46, true); // alwaysFight = true and canFightArmedWhenNotArmed. which one is which is unknown
                    Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, newPed, 5, true);
                    Function.Call(Hash.SET_PED_COMBAT_RANGE, newPed, 2);             //combatRange = far

                    newPed.CanSwitchWeapons = true;
                    newPed.CanWrithe        = false; //no early dying

                    //enlist this new gang member in the spawned list!
                    SpawnedGangMember newMemberAI = null;

                    bool couldEnlistWithoutAdding = false;
                    for (int i = 0; i < livingMembers.Count; i++)
                    {
                        if (livingMembers[i].watchedPed == null)
                        {
                            livingMembers[i].AttachData(newPed, ownerGang, hasDriveByGun);
                            newMemberAI = livingMembers[i];
                            couldEnlistWithoutAdding = true;
                            break;
                        }
                    }
                    if (!couldEnlistWithoutAdding)
                    {
                        if (livingMembers.Count < ModOptions.instance.spawnedMemberLimit)
                        {
                            newMemberAI = new SpawnedGangMember(newPed, ownerGang, hasDriveByGun);
                            livingMembers.Add(newMemberAI);
                        }
                    }

                    livingMembersCount++;
                    onSuccessfulMemberSpawn?.Invoke();
                    Logger.Log("spawn member: end (success). livingMembers list size = " + livingMembers.Count);
                    return(newMemberAI);
                }
                else
                {
                    Logger.Log("spawn member: end with fail (world createped returned null)");
                    return(null);
                }
            }
            return(null);
        }
Exemple #11
0
        public override void Update()
        {
            if (vehicleIAmDriving.IsAlive && watchedPed.IsAlive)
            {
                if (mustReachDest)
                {
                    watchedPed.BlockPermanentEvents = true;                     //our driver shouldn't get distracted
                }

                if (destination != Vector3.Zero)
                {
                    //stop tracking this driver/vehicle if he/she leaves the vehicle
                    if (!watchedPed.IsInVehicle(vehicleIAmDriving))
                    {
                        ClearAllRefs();
                    }
                    else
                    {
                        RideToDest();
                    }
                }
                else
                {
                    //we are just wandering arond
                    //if we get too far from the player, despawn
                    if (World.GetDistance(vehicleIAmDriving.Position, MindControl.CurrentPlayerCharacter.Position) >
                        ModOptions.instance.maxDistanceCarSpawnFromPlayer * 2.5f)
                    {
                        for (int i = 0; i < myPassengers.Count; i++)
                        {
                            if (myPassengers[i] != null && myPassengers[i].IsAlive && !myPassengers[i].IsPlayer)
                            {
                                SpawnedGangMember memberAI = SpawnManager.instance.GetTargetMemberAI(myPassengers[i]);
                                if (memberAI != null)
                                {
                                    memberAI.Die();
                                }
                            }
                        }

                        if (!watchedPed.IsPlayer)
                        {
                            SpawnedGangMember memberAI = SpawnManager.instance.GetTargetMemberAI(watchedPed);
                            if (memberAI != null)
                            {
                                memberAI.Die();
                            }
                        }
                        ClearAllRefs();
                        return;
                    }

                    //if there is a war going on and we're in the war zone, get to the player to help/kill him!
                    if (GangWarManager.instance.isOccurring && GangWarManager.instance.playerNearWarzone)
                    {
                        playerAsDest            = true;
                        updatesWhileGoingToDest = 0;
                        RideToDest();
                        return;
                    }

                    //stop tracking this driver/vehicle if he/she leaves the vehicle or something goes wrong
                    if (!watchedPed.IsInVehicle())
                    {
                        ClearAllRefs();
                        return;
                    }
                }
            }
            else
            {
                //our vehicle has been destroyed/ our driver has died

                ClearAllRefs();
            }
        }
 public void SpawnAmbientMember(Gang curGang)
 {
     Vector3           spawnPos  = SpawnManager.instance.FindGoodSpawnPointForMember();
     SpawnedGangMember newMember = SpawnManager.instance.SpawnGangMember(curGang, spawnPos);
 }