Kahega12 Posted February 20, 2013 Share Posted February 20, 2013 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 More sharing options...
TheLastStarFighterOfPlanetXenon Posted February 20, 2013 Share Posted February 20, 2013 (edited) 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 February 20, 2013 by TheLastStarFighterOfPlanetXenon Link to comment Share on other sites More sharing options...
lemonwire Posted February 20, 2013 Share Posted February 20, 2013 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 More sharing options...
TheLastStarFighterOfPlanetXenon Posted February 20, 2013 Share Posted February 20, 2013 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 Link to comment Share on other sites More sharing options...
lemonwire Posted February 20, 2013 Share Posted February 20, 2013 (edited) i fixed the script, copy it from above again, and btw i wrote that police behavior mod 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 February 20, 2013 by lemonwire Link to comment Share on other sites More sharing options...
Kahega12 Posted February 20, 2013 Author Share Posted February 20, 2013 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 More sharing options...
TheLastStarFighterOfPlanetXenon Posted February 20, 2013 Share Posted February 20, 2013 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 More sharing options...
Kahega12 Posted February 20, 2013 Author Share Posted February 20, 2013 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 More sharing options...
TheLastStarFighterOfPlanetXenon Posted February 20, 2013 Share Posted February 20, 2013 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now