Example #1
0
        //Creates a pedestrian, assigns behavior and adds a blip if necessary. Creates a cop if cop=true, criminal if false
        private void SpawnPedestrian(bool cop)
        {
            if (peds.Count >= MaxPeds)
            {
                return;
            }

            int mod = 1;

            if (!cop)
            {
                mod *= -1;
            }

            Ped ped = World.CreatePed(RandomModel(cop), Player.Character.GetOffsetPosition(new Vector3(mod * RandomNumber(spawnRadius / 2, spawnRadius), mod * RandomNumber(spawnRadius / 2, spawnRadius), 0.0f)).ToGround());

            if (Exists(ped) && ped != null)
            {
                ped.BecomeMissionCharacter(); //makes sure the pedestrian persists while player alive

                if (cop)
                {
                    ped.RelationshipGroup = RelationshipGroup.Cop;
                    ped.ChangeRelationship(RelationshipGroup.Criminal, Relationship.Hate);
                    ped.ChangeRelationship(RelationshipGroup.Dealer, Relationship.Hate);
                    ped.ChangeRelationship(RelationshipGroup.Player, Relationship.Respect);

                    ped.MaxHealth = copHealth;
                    ped.Health    = copHealth;
                    ped.Armor     = 50;
                }
                else
                {
                    ped.RelationshipGroup = RelationshipGroup.Criminal;
                    ped.ChangeRelationship(RelationshipGroup.Cop, Relationship.Hate);
                    ped.ChangeRelationship(RelationshipGroup.Civillian_Male, Relationship.Hate);
                    ped.ChangeRelationship(RelationshipGroup.Civillian_Female, Relationship.Hate);
                    ped.ChangeRelationship(RelationshipGroup.Fireman, Relationship.Hate);
                    ped.ChangeRelationship(RelationshipGroup.Bum, Relationship.Hate);
                    ped.ChangeRelationship(RelationshipGroup.Medic, Relationship.Hate);
                    ped.ChangeRelationship(RelationshipGroup.Player, Relationship.Neutral);

                    ped.MaxHealth      = robberHealth;
                    ped.Health         = robberHealth;
                    ped.Armor          = 0;
                    ped.WantedByPolice = true;
                    ped.StartKillingSpree(true);
                    Blip blip = ped.AttachBlip();
                    blips.Add(ped, blip);
                }

                ped.Task.FightAgainstHatedTargets(fightRadius); //give the pedestrian their task, will repeat

                RandomWeapons(ped, cop);
                peds.Add(ped);
                totalSpawned++;
                Wait(10);
            }
        }