Log in to reply
 

can't get peds to fight one another, they just run away



  • I've looked over countless examples here and nothing seems to do the trick. I would be grateful if someone could help.

    No matter what I do, when I spawn two peds and assign them the relevant properties so that they should fight, they just run away really fast.

        if (e.KeyCode == Keys.NumPad1)
        {
            UI.ShowSubtitle("create cop new");
            Ped player = Game.Player.Character;
            GTA.Math.Vector3 spawnLoc = player.Position + (player.ForwardVector * 5f);
    
    
            // set up relationships so newly spawned peds hate one another
            int copgroup1 = World.AddRelationshipGroup("cops1");
            int copgroup2 = World.AddRelationshipGroup("cops2");
            int playerRGroup = player.RelationshipGroup;
    
            World.SetRelationshipBetweenGroups(Relationship.Hate, copgroup1, copgroup2);
            World.SetRelationshipBetweenGroups(Relationship.Hate, copgroup2, copgroup1);
    
            string model_name = "s_m_y_cop_01";
            Ped cop1 = GTA.World.CreatePed(model_name, spawnLoc);
            Ped cop2 = GTA.World.CreatePed(model_name, spawnLoc);
    
            cop1.RelationshipGroup = copgroup1;
            cop2.RelationshipGroup = copgroup2;
    
            Function.Call(Hash.SET_BLOCKING_OF_NON_TEMPORARY_EVENTS, cop1, true);
            Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, cop1, 46, true);
            Function.Call(Hash.SET_PED_FLEE_ATTRIBUTES, cop1, 0, 0);
    
            Function.Call(Hash.SET_BLOCKING_OF_NON_TEMPORARY_EVENTS, cop2, true);
            Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, cop2, 46, true);
            Function.Call(Hash.SET_PED_FLEE_ATTRIBUTES, cop2, 0, 0);
    
            cop1.Weapons.Give(WeaponHash.SMG, 999, true, true);
    
            cop1.Task.FightAgainst(cop2);
            cop2.Task.FightAgainst(cop1);
          
        }
    }


  • Try reinstall menyoo, in my case it helped



  • @prismspecs I've done this easily when they are unarmed, they will fight each other and you don't need 90% of the code you have above. All you need is have them fight.

    With weapons, I don't script this kind of thing. But this will work:

    1. Spawn the peds with weapons as part of your group.
    2. Then remove some from your group
    3. Start a fight.
      I'm doing this from my personal trainer as a demo but obviously you can do it just with the code (C#, SHVDN3). This is just my player group (no other relationship groups) and one gun shot to start the fight. Two or three lines of code max.


Log in to reply
 

Looks like your connection to GTA5-Mods.com Forums was lost, please wait while we try to reconnect.