Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. Red Dead Redemption 2

      1. Gameplay
      2. Missions
      3. Help & Support
    2. Red Dead Online

      1. Gameplay
      2. Find Lobbies & Outlaws
      3. Help & Support
    1. Crews & Posses

      1. Recruitment
    2. Events

    1. GTA Online

      1. Diamond Casino & Resort
      2. DLC
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Grand Theft Auto Series

    3. GTA 6

    4. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    5. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA Mods
    6. GTA Chinatown Wars

    7. GTA Vice City Stories

    8. GTA Liberty City Stories

    9. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    10. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    11. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    12. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    13. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    3. Featured Mods

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption

    2. Rockstar Games

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Programming
      5. Movies & TV
      6. Music
      7. Sports
      8. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. News

    2. Forum Support

    3. Site Suggestions

draymon

[C#] Making Peds Fight Each Other with specific weapon? (Question)

Recommended Posts

draymon

Hello, I'm extremely new to modding, and just want to create a simple Riot mod.

So here's what I got so far with a couple of tutorials.

using GTA;using GTA.Native;using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;public class ScriptMod : Script{    public ScriptMod()    {        Tick += OnTick;        KeyDown += OnKeyDown;        KeyUp += OnKeyUp;        Interval = 10;    }    void OnTick(object sender, EventArgs e)    {    }    void OnKeyDown(object sender, KeyEventArgs e)    {        if (e.KeyCode == Keys.F7)        {            Ped player = Game.Player.Character;            GTA.Math.Vector3 playerpos = player.Position;            Ped[] allpeds = GTA.World.GetNearbyPeds(playerpos, 50000);            foreach (Ped p in allpeds)            {                if (p != player)                {                    p.Task.FightAgainst(p);                }            }        }    }    void OnKeyUp(object sender, KeyEventArgs e)    {    }}

The "p.Task.FightAgainst" doesn't really make them fight each other... They just seem to run away. How do I make them constantly fight each other and not run away? Even with the target of player instead of p, only a couple wants to fight me.

 

So basically, I want to know how to make all peds attack each other with a baseball bat. And I have no clue how...

 

Any help would be very much appreciated, thanks.

 

Share this post


Link to post
Share on other sites
jedijosh920

Well, in your for each loop you don't check if they are themselves, so the engine is trying to make the peds fight themselves...

Share this post


Link to post
Share on other sites
draymon

Well, in your for each loop you don't check if they are themselves, so the engine is trying to make the peds fight themselves...

Ah, I see. How could I make them check if they are themselves?

Share this post


Link to post
Share on other sites
AHK1221

From what I know, if the ped that is given the task to fight has nothing (unarmed) selected and you have a gun, then he will run away. And this would would also solve your other "fight with specific weapon" question.

 

First, you have to give the ped a weapon:

 

p.Weapons.Give(WeaponHash.SMG, 999, true, true);
The first param will decide which weapon you want to give. The second one is the amount of ammo. And I believe the last two ones are isAmmoLoaded and equipNow. Since we set equipNow to true, the ped will already have the weapon selected and he will fight against us.

 

I recommend using

p.Task.AimAt(player);
right before the FightAgainst task. Hope this helps!

Share this post


Link to post
Share on other sites
jedijosh920

You don't need to do all that AHK1221, ignore it.

 

All you need to do is apply a combat attribute to the pedestrian.

Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, ped, 46, true);

The 46 value contributes to the combatbehaviour.meta BeahviourFlags and 46 is the "AlwaysFight" attribute so the peds who have that combat attribute will never run from a fight regardless of health, opponent's weapons, etc.

 

 

You can also check if the pedestrian is not themselves by simply doing:

p.Handle != p.Handle

Share this post


Link to post
Share on other sites
draymon

 

You don't need to do all that AHK1221, ignore it.

 

All you need to do is apply a combat attribute to the pedestrian.

Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, ped, 46, true);

The 46 value contributes to the combatbehaviour.meta BeahviourFlags and 46 is the "AlwaysFight" attribute so the peds who have that combat attribute will never run from a fight regardless of health, opponent's weapons, etc.

 

 

You can also check if the pedestrian is not themselves by simply doing:

p.Handle != p.Handle

Here's what I've got so far:

void OnKeyUp(object sender, KeyEventArgs e)    {        if (e.KeyCode == Keys.F7)        {            UI.Notify("Riot Mode Enabled");            Game.Player.WantedLevel = 0;            Function.Call(Hash.SET_POLICE_IGNORE_PLAYER, Game.Player, true);            Function.Call(Hash.SET_WANTED_LEVEL_MULTIPLIER, 0.0);            Ped player = Game.Player.Character;            GTA.Math.Vector3 playerpos = player.Position;            Ped[] allpeds = GTA.World.GetAllPeds();            foreach (Ped p in allpeds)            {                if (p != player)                {                    p.Weapons.Give(WeaponHash.Bat, 1, true, true);                    Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, p, 46, true);                    //p.Task.FightAgainst(p);                    p.Task.FightAgainst(player);                }            }        }    }

Sorry for so many questions, but I still have some issues:

 

1. My code doesn't affect all peds, only a few will come and fight me, while the rest will still run away. With the

Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, p, 46, true);

the ones fighting will no longer run away when shot at, so thank you for that.

 

2. Under where should I put

p.Handle != p.Handle

3. How can I make the code loop so I don't have to keep pressing the hotkey to enable it?

 

4. and also, when i looked at other people's code, how come they have it like

PED::SET_PED_COMBAT_ATTRIBUTES(p, 46, true);

instead of

Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, p, 46, true)

Sorry again for so many questions, and thanks a lot for the help!

Edited by draymon

Share this post


Link to post
Share on other sites
BenBaron

"4. and also, when i looked at other people's code, how come they have it like

PED::SET_PED_COMBAT_ATTRIBUTES(p, 46, true);

instead of

Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, p, 46, true)

Sorry again for so many questions, and thanks a lot for the help!"

 

That is because you are coding in C# whereas those other people are using C++...different languages, thus the differences in syntax.

Share this post


Link to post
Share on other sites
GeorgeZhang

 

2. Under where should I put

p.Handle != p.Handle

If you need them to fight each others, you might need a nested loop. like:

foreach(Ped p in allpeds){   foreach(Ped q in allpeds)      if(p.Handle != q.Handle)          p.Task.FightAgainst(q);}

The length of 'allpeds' must be quite big so doing so might cause lag. Add Script.Yield() in the outer loop if you find it lagging a lot.

 

Hope it helps!

Share this post


Link to post
Share on other sites
milkjunk87

check out my code its just .cs not dll and has relationship groups for gangwar fare:

int relgrpA = 0;    int relgrpB = 0; relgrpA = World.AddRelationshipGroup("A");                relgrpB = World.AddRelationshipGroup("B");                                relgrpB = World.AddRelationshipGroup("player");                World.SetRelationshipBetweenGroups(Relationship.Hate, relgrpA, relgrpB);        World.SetRelationshipBetweenGroups(Relationship.Hate, relgrpB, relgrpA);        World.SetRelationshipBetweenGroups(Relationship.Companion, relgrpA, relgrpA);        World.SetRelationshipBetweenGroups(Relationship.Companion, relgrpB, relgrpB);   Game.Player.Character.RelationshipGroup = relgrpB;Ped stripperenemy = GTA.World.CreatePed(angrystrippers, stripperdrop+ new Vector3(0f,-7f,5f),Game.Player.Character.Heading-90f);            stripperenemy.RelationshipGroup = relgrpA;{stripperenemy.Weapons.Give(GTA.Native.WeaponHash.RPG, -1, true, true);}

and combat attribute stuff (fight to the death):

GTA.Native.Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, stripperenemy, 46, true);

https://www.gta5-mods.com/scripts/kamikaze-mod

Edited by milkjunk87

Share this post


Link to post
Share on other sites
draymon

"4. and also, when i looked at other people's code, how come they have it like

PED::SET_PED_COMBAT_ATTRIBUTES(p, 46, true);

instead of

Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, p, 46, true)

Sorry again for so many questions, and thanks a lot for the help!"

 

That is because you are coding in C# whereas those other people are using C++...different languages, thus the differences in syntax.

Ah, that makes sense, thanks!

 

 

 

2. Under where should I put

p.Handle != p.Handle

If you need them to fight each others, you might need a nested loop. like:

foreach(Ped p in allpeds){   foreach(Ped q in allpeds)      if(p.Handle != q.Handle)          p.Task.FightAgainst(q);}

The length of 'allpeds' must be quite big so doing so might cause lag. Add Script.Yield() in the outer loop if you find it lagging a lot.

 

Hope it helps!

 

Hmm. Still doesn't work. They still seem to be running away from each other. Even if try to make them just fight me, most of them run away, even with the attributes of 46.

Share this post


Link to post
Share on other sites
InfamousSabre

Use this as well. This makes peds without firearms fight you also, even if you have a firearm.

PED::SET_PED_COMBAT_ATTRIBUTES(p, 5, true);

Share this post


Link to post
Share on other sites
draymon

 

Use this as well. This makes peds without firearms fight you also, even if you have a firearm.

PED::SET_PED_COMBAT_ATTRIBUTES(p, 5, true);

Thank you, with that attribute, a lot more peds now wants to fight me, but a little of them still run away. Are there any more attributes?

 

EDIT: I've noticed that only three peds will fight me at once, even though the map is full of red blips. The ones not fighting me will either just run away, or stand around holding a bat.

Edited by draymon

Share this post


Link to post
Share on other sites
InfamousSabre

Most games with melee (the well programmed ones, anyway) have a limit on how many characters can attack another single character at once. Im not sure if you can change this. May I ask though; have you made these attacking peds into mission peds?

Share this post


Link to post
Share on other sites
jedijosh920

Most games with melee (the well programmed ones, anyway) have a limit on how many characters can attack another single character at once. Im not sure if you can change this. May I ask though; have you made these attacking peds into mission peds?

 

Yeah it sucks how they capped it at 7, the other pedestrians are in a waiting queue just staring at you until the other combating pedestrians die or flee, whatever.

Share this post


Link to post
Share on other sites
draymon

Most games with melee (the well programmed ones, anyway) have a limit on how many characters can attack another single character at once. Im not sure if you can change this. May I ask though; have you made these attacking peds into mission peds?

Ah, i see.

I have tried to make these peds into mission peds by using

Function.Call(Hash.SET_ENTITY_AS_MISSION_ENTITY, p, true);

but the game crashed after a few seconds.

 

Here's what I got so far:

    void OnTick(object sender, EventArgs e)    {        UI.Notify("Riot Mode Enabled");        Game.Player.WantedLevel = 0;        Function.Call(Hash.SET_POLICE_IGNORE_PLAYER, Game.Player, true);        Function.Call(Hash.SET_WANTED_LEVEL_MULTIPLIER, 0.0f);        //Function.Call(Hash.SET_PED_DENSITY_MULTIPLIER_THIS_FRAME, 3.0f);        // Function.Call(Hash.SET_VEHICLE_DENSITY_MULTIPLIER_THIS_FRAME, 0.1f);        Ped player = Game.Player.Character;        //GTA.Math.Vector3 playerpos = player.Position;        Ped[] allpeds = World.GetAllPeds();        foreach (Ped p in allpeds)        {            if (p != player)            {                //Function.Call(Hash.SET_ENTITY_AS_MISSION_ENTITY, p, true);                Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, p, 46, true);                Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, p, 5, true);                p.Weapons.Give(WeaponHash.Bat, 1, true, true);                Function.Call(Hash.TASK_COMBAT_PED, p, player, 0, 16);            }        }    }

I still can't figure out how to make them fight each other though :/.

Share this post


Link to post
Share on other sites
AHK1221

 

Most games with melee (the well programmed ones, anyway) have a limit on how many characters can attack another single character at once. Im not sure if you can change this. May I ask though; have you made these attacking peds into mission peds?

 

Ah, i see.

I have tried to make these peds into mission peds by using

 

Function.Call(Hash.SET_ENTITY_AS_MISSION_ENTITY, p, true);
but the game crashed after a few seconds.

 

Here's what I got so far:

 

void OnTick(object sender, EventArgs e)    {        UI.Notify("Riot Mode Enabled");        Game.Player.WantedLevel = 0;        Function.Call(Hash.SET_POLICE_IGNORE_PLAYER, Game.Player, true);        Function.Call(Hash.SET_WANTED_LEVEL_MULTIPLIER, 0.0f);        //Function.Call(Hash.SET_PED_DENSITY_MULTIPLIER_THIS_FRAME, 3.0f);        // Function.Call(Hash.SET_VEHICLE_DENSITY_MULTIPLIER_THIS_FRAME, 0.1f);        Ped player = Game.Player.Character;        //GTA.Math.Vector3 playerpos = player.Position;        Ped[] allpeds = World.GetAllPeds();        foreach (Ped p in allpeds)        {            if (p != player)            {                //Function.Call(Hash.SET_ENTITY_AS_MISSION_ENTITY, p, true);                Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, p, 46, true);                Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, p, 5, true);                p.Weapons.Give(WeaponHash.Bat, 1, true, true);                Function.Call(Hash.TASK_COMBAT_PED, p, player, 0, 16);            }        }    }
I still can't figure out how to make them fight each other though :/. you could use relationship groups like how milkjunk used.

Share this post


Link to post
Share on other sites
draymon

 

 

Most games with melee (the well programmed ones, anyway) have a limit on how many characters can attack another single character at once. Im not sure if you can change this. May I ask though; have you made these attacking peds into mission peds?

Ah, i see.

I have tried to make these peds into mission peds by using

 

Function.Call(Hash.SET_ENTITY_AS_MISSION_ENTITY, p, true);
but the game crashed after a few seconds.

 

Here's what I got so far:

 

void OnTick(object sender, EventArgs e)    {        UI.Notify("Riot Mode Enabled");        Game.Player.WantedLevel = 0;        Function.Call(Hash.SET_POLICE_IGNORE_PLAYER, Game.Player, true);        Function.Call(Hash.SET_WANTED_LEVEL_MULTIPLIER, 0.0f);        //Function.Call(Hash.SET_PED_DENSITY_MULTIPLIER_THIS_FRAME, 3.0f);        // Function.Call(Hash.SET_VEHICLE_DENSITY_MULTIPLIER_THIS_FRAME, 0.1f);        Ped player = Game.Player.Character;        //GTA.Math.Vector3 playerpos = player.Position;        Ped[] allpeds = World.GetAllPeds();        foreach (Ped p in allpeds)        {            if (p != player)            {                //Function.Call(Hash.SET_ENTITY_AS_MISSION_ENTITY, p, true);                Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, p, 46, true);                Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, p, 5, true);                p.Weapons.Give(WeaponHash.Bat, 1, true, true);                Function.Call(Hash.TASK_COMBAT_PED, p, player, 0, 16);            }        }    }
I still can't figure out how to make them fight each other though :/.
you could use relationship groups like how milkjunk used.

 

Yeah, good idea, but I don't really understand it. Is there a guide anywhere specifically on relationships, or if someone here could explain it to me, that'd be awesome.

Share this post


Link to post
Share on other sites
AHK1221

 

 

 

Most games with melee (the well programmed ones, anyway) have a limit on how many characters can attack another single character at once. Im not sure if you can change this. May I ask though; have you made these attacking peds into mission peds?

 

Ah, i see.

I have tried to make these peds into mission peds by using

Function.Call(Hash.SET_ENTITY_AS_MISSION_ENTITY, p, true);
but the game crashed after a few seconds.

 

Here's what I got so far:

void OnTick(object sender, EventArgs e)    {        UI.Notify("Riot Mode Enabled");        Game.Player.WantedLevel = 0;        Function.Call(Hash.SET_POLICE_IGNORE_PLAYER, Game.Player, true);        Function.Call(Hash.SET_WANTED_LEVEL_MULTIPLIER, 0.0f);        //Function.Call(Hash.SET_PED_DENSITY_MULTIPLIER_THIS_FRAME, 3.0f);        // Function.Call(Hash.SET_VEHICLE_DENSITY_MULTIPLIER_THIS_FRAME, 0.1f);        Ped player = Game.Player.Character;        //GTA.Math.Vector3 playerpos = player.Position;        Ped[] allpeds = World.GetAllPeds();        foreach (Ped p in allpeds)        {            if (p != player)            {                //Function.Call(Hash.SET_ENTITY_AS_MISSION_ENTITY, p, true);                Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, p, 46, true);                Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, p, 5, true);                p.Weapons.Give(WeaponHash.Bat, 1, true, true);                Function.Call(Hash.TASK_COMBAT_PED, p, player, 0, 16);            }        }    }
I still can't figure out how to make them fight each other though :/.
you could use relationship groups like how milkjunk used.

 

Yeah, good idea, but I don't really understand it. Is there a guide anywhere specifically on relationships, or if someone here could explain it to me, that'd be awesome. if that's too hard (I think the groups are hard too lol), you could follow GeorgeZhangs method.

 

 

2. Under where should I put

 

p.Handle != p.Handle
If you need them to fight each others, you might need a nested loop. like:

 

foreach(Ped p in allpeds){   foreach(Ped q in allpeds)      if(p.Handle != q.Handle)          p.Task.FightAgainst(q);}
The length of 'allpeds' must be quite big so doing so might cause lag. Add Script.Yield() in the outer loop if you find it lagging a lot.

 

Hope it helps!

Share this post


Link to post
Share on other sites
InfamousSabre

Were they mission peds when they just stood around? Im currently making a riot script too and if i make them mission peds, most of them just stand around. If i dont, however, they behave just fine. Problem is that they get deleted too soon.

 

Im using relationship groups, but i kinda have to. They are kinda tricky, but if you use the built-in ones, its not so bad. only thing i cant get them to do is throw grenades or molotovs.

Share this post


Link to post
Share on other sites
GeorgeZhang

 

 

 

Most games with melee (the well programmed ones, anyway) have a limit on how many characters can attack another single character at once. Im not sure if you can change this. May I ask though; have you made these attacking peds into mission peds?

Ah, i see.

I have tried to make these peds into mission peds by using

 

Function.Call(Hash.SET_ENTITY_AS_MISSION_ENTITY, p, true);
but the game crashed after a few seconds.

 

Here's what I got so far:

 

void OnTick(object sender, EventArgs e)    {        UI.Notify("Riot Mode Enabled");        Game.Player.WantedLevel = 0;        Function.Call(Hash.SET_POLICE_IGNORE_PLAYER, Game.Player, true);        Function.Call(Hash.SET_WANTED_LEVEL_MULTIPLIER, 0.0f);        //Function.Call(Hash.SET_PED_DENSITY_MULTIPLIER_THIS_FRAME, 3.0f);        // Function.Call(Hash.SET_VEHICLE_DENSITY_MULTIPLIER_THIS_FRAME, 0.1f);        Ped player = Game.Player.Character;        //GTA.Math.Vector3 playerpos = player.Position;        Ped[] allpeds = World.GetAllPeds();        foreach (Ped p in allpeds)        {            if (p != player)            {                //Function.Call(Hash.SET_ENTITY_AS_MISSION_ENTITY, p, true);                Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, p, 46, true);                Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, p, 5, true);                p.Weapons.Give(WeaponHash.Bat, 1, true, true);                Function.Call(Hash.TASK_COMBAT_PED, p, player, 0, 16);            }        }    }
I still can't figure out how to make them fight each other though :/.
you could use relationship groups like how milkjunk used.

 

Yeah, good idea, but I don't really understand it. Is there a guide anywhere specifically on relationships, or if someone here could explain it to me, that'd be awesome.

 

Quoting myself from this topic: http://gtaforums.com/topic/814647-calling-all-critters/

 

Relationship group:

this one doesn't exactly feel like a group. It's more like a identifier that tells the game what type of people you are. Players, gang members, cops, armies etc. has their respective relationship groups, and these relationship groups have default relationships with each others(like, hate, neutral and more).

However, you can set peds' relationship groups with some codes. Relationship groups can also be created, and the relationships between relationship groups can be assigned as well.

 

1.create:

int EnemyRGroup = World.AddRelationshipGroup("badassenemies");int playerRGroup = player.RelationShipGroup;

2.set:

myped.RelationShipGroup = EnemyRGroup;World.SetRelationshipBetweenGroups(Relationship.Hate, EnemyRGroup, playerRGroup);World.SetRelationshipBetweenGroups(Relationship.Hate, playerRGroup, EnemyRGroup);

You can get existing in-game relationshipgroup hashes by:

int copHash = Function.Call<int>(Hash.GET_HASH_KEY, "COP");

more in-game relationship groups/information check this post(and check replies as well)

http://gtaforums.com...s-from-fleeing/

Edited by GeorgeZhang

Share this post


Link to post
Share on other sites
InfamousSabre

So I recently found that if you want more than 3 peds to use melee at once you have to edit gameconfig.xml. Theres a line that sets the limit for melee managers or something like that. Its default is 3, I set it to 30. Much better. Everyone riots now! Apparently this makes the new patch crash, so be sure and backup before you try this out.

Share this post


Link to post
Share on other sites
NOTHING2

So there is no way to set NPC weapons 'ammo right ?

by the way. Can you help me set reload IS_PED_RELOADING ? how it works

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.