Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. The Criminal Enterprises
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

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

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

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

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

    2. Support

    3. Suggestions

*DO NOT* SHARE MEDIA OR LINKS TO LEAKED COPYRIGHTED MATERIAL. Discussion is allowed.

Armed & Hating Ped Script


Kahega12
 Share

Recommended Posts

Hello,

 

I was reading through the "Police Officers Behavior Mod" thread in an attempt to make a small mod/script.

My goal is to have the GunNut characters around the map and attack 'cop' whenever they are around, and for the GunNut characters to be armed with an AK.

I've already got the map stuff worked out, and I changed 'GANG_BIKER_2' to just be GunNut characters and nobody else, and all of that seems to work out alright. Some of the GunNut characters are even armed and I modded them to be plenty brave/attack/defend, etc. (via personality), but I've only ever seen them with the pistol, knife or pump shotgun - no AKs, and none have been attacking the police.

 

Here's the script I have in the 'scripts' folder. Sorry if it has some noobie mistake, I was just trying to teach myself via a few other threads.

 

 

using System;using GTA;public class ArmedGunnut : Script{  public ArmedGunnut()  {      Tick += ArmedGunnut_Tick;  }  void ArmedGunnut_Tick(object sender, EventArgs e)  {      foreach (Ped ped in World.GetAllPeds())      {          if (ped.isAliveAndWell && ped.PedType == PedType.GANG_BIKER_2)          {              ped.Weapons.AssaultRifle_AK47.Ammo = 500;       ped.ChangeRelationship(RelationshipGroup.Cop, Relationship.Hate)       ped.Task.FightAgainstHatedTargets(30.0f);          }   if (ped.isAliveAndWell && ped.PedType == PedType.GANG_BIKER_2 && ped.isIdle && !ped.isInCombat && !ped.isShooting)   {       ped.ChangeRelationship(RelationshipGroup.Cop, Relationship.Hate)       ped.ChangeRelationship(RelationshipGroup.GANG_BIKER_2, Relationship.Like)       ped.Task.FightAgainstHatedTargets(50.0f);   }      }  }}

 

 

So, the idea was: If part of GANG_BIKER_2, give them an AK, make them hate 'cop', then tell them to target hated. Then, I wanted it to be so that if one GunNut got into a fight, then others from further away would come to help (hence the 50f).

 

Can anybody let me know what I need to fix to get GANG_BIKER_2 to automatically engage any police? And to make them actually get AKs?

 

Thank you.

Link to comment
Share on other sites

TheLastStarFighterOfPlanetXenon

whenever you loop through peds u should check existence before anything else

 

 

if (!Game.Exists(ped)) continue;

 

 

add that to the first line of your foreach loop to prevent crashes

 

to get bikers to use AK47s try taking away all their guns first then giving them ak47 ammo, also no need to make them like bikers they already do. Also the 2 if statements seems redundant, just set them to attack 50f away in the first if statement and delete the 2nd one and u can add those additional ped property checks to the first if statement

 

this is how i'd write it:

 

 

using System;using GTA;public class ArmedGunnut : Script{   public ArmedGunnut()   {       Tick += ArmedGunnut_Tick;   }   void ArmedGunnut_Tick(object sender, EventArgs e)   {       foreach (Ped ped in World.GetAllPeds())       {           if (!Game.Exists(ped)) continue;//skips nonexisting peds which avoids crash                      if (ped.isAliveAndWell && ped.PedType == PedType.GANG_BIKER_2 && ped.isIdle && !ped.isInCombat && !ped.isShooting)           {               if (ped.Weapons.AssaultRifle_AK47.Ammo == 0)               {                   //hopefully this makes them listen to u but will need to reverse this when they die                   ped.BecomeMissionCharacter();                   ped.Weapons.RemoveAll();                   ped.Weapons.AssaultRifle_AK47.Ammo = 500;               }               ped.ChangeRelationship(RelationshipGroup.Cop, Relationship.Hate);               ped.Task.FightAgainstHatedTargets(50f);           }           else if (!ped.isAliveAndWell && ped.PedType == PedType.GANG_BIKER_2)           {               ped.NoLongerNeeded();//this will allow game to delete dead bikers u made mission characters           }       }   }}

 

Edited by TheLastStarFighterOfPlanetXenon
Link to comment
Share on other sites

Thanks for working on this guys,

I was looking for something identical to this from the Police Officers Behavior Mod also.

TheLastStarFighterOfPlanetXenon, I've tried using your revised script, but I get a "line 24 ; expected" error.

I don't know how to script, would you happen to know what this error is?

Link to comment
Share on other sites

TheLastStarFighterOfPlanetXenon

 

Thanks for working on this guys,

I was looking for something identical to this from the Police Officers Behavior Mod also.

TheLastStarFighterOfPlanetXenon, I've tried using your revised script, but I get a "line 24 ; expected" error.

I don't know how to script, would you happen to know what this error is?

 

i fixed the script, copy it from above again, and btw i wrote that police behavior mod wink.gif

Link to comment
Share on other sites

 

i fixed the script, copy it from above again, and btw i wrote that police behavior mod wink.gif

Thanks for the quick reply, I really appreciate the scripting especially with the crazy cops, that works like a charm.

 

Your correction has fixed the "line 24 ; expected" error, now a separate issue has arisen,

 

gta.pedtype does not contain a definition for GANG_BIKER_2.

 

Would it be possible to obtain the proper ped type list that works for .cs scripts? For the crazy cops script,

ped.PedType == PedType.Cop works pefectly, but I haven't been able to find any other variation that also works such as GANG_ALBANIAN, or CRIMINAL for example.

 

Edit: I managed to get the script running by using "PedType == PedType.Criminal" however, there is no chaos.

Edited by lemonwire
Link to comment
Share on other sites

Thanks for the tips LastStarFighter (and thanks for the original work on Police Behavior), and thanks lemonwire for trying some of the stuff out too.

 

I too still don't have any chaos / random fights breaking out with the new code.

 

Hopefully we can figure it out, thanks.

Link to comment
Share on other sites

TheLastStarFighterOfPlanetXenon

i added a few more lines of code to make bikers mission characters, i think they might listen to your script better like that. I think the game has scripts that conflict but if they are mission characters they ignore the game's scripts that controls their normal activity. I also added code to reverse that when they are dead so the game can delete them like normal

Link to comment
Share on other sites

Still the best I get is an occasional guy with a pump shotgun or pistol, and even those few won't engage cops automatically.

 

I tried switching over to pedtype.criminal, and that made the cops at least chase them around, but still nobody had AKs (I temporarily modded the script too to match).

And I still prefer the idea of using Gang_Biker_2, because I don't want just all criminal characters getting the AK and going mad.

 

Also, the characters still don't ally with each other. I can walk up to a group of 4-6 of them, draw a pistol on them, and maybe one guy will draw and engage me, but the others will just scatter.

 

Thanks for the help.

Link to comment
Share on other sites

TheLastStarFighterOfPlanetXenon

just keep trying different things, it is possible but u just have to set the right properties. im not on gtaiv so cant test

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • 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.