ch3y3zze Posted September 17, 2012 Share Posted September 17, 2012 (edited) Ok tried to fix ur bugs, see below: http://dl.dropbox.com/u/55310026/NiceCops(v2).cs namespace NiceCops{ using System; using System.Collections.Generic; using GTA; public class Main : Script { List<Ped> copList; List<Ped> armedList; bool copsAreAlarmed; public Main() { copList = new List<Ped>(); armedList = new List<Ped>(); Interval = 1000; Tick += new EventHandler(Main_Tick); } void Main_Tick(object sender, EventArgs e) { //Populates cop list with all living cops, removes dead and ones deleted by game GetCops(); //Populates armed list with all peds that are living, armed and potential threats, removes dead and ones deleted by game GetArmedPeds(); //now will check if any cop is near and can see armed ped //this will return true if armed peds can be seen by cops copsAreAlarmed = CopsAlarmed(); //if u have more than 1 star script will deactivate and cops with bats deleted //so game can replace with normal cops if (Game.LocalPlayer.WantedLevel > 1 || copsAreAlarmed)//OK now if u have wanted level or cops can see armed ped then gun cops will come { GiveCopsGuns(); } else//here u only have 0 or 1 star or no armed peds can be seen by cops so all cops will have bats only;D { GiveCopsBats(); } } void GiveCopsGuns() { foreach (Ped cop in copList) { //finds cops with bats only and gives guns (gives M4 to swat cop all others get glock unless u want that changed) if (Game.Exists(cop) && cop.Weapons.BaseballBat.Ammo == 1 && cop.Weapons.AssaultRifle_M4.Ammo == 0 && cop.Weapons.Glock.Ammo == 0) { cop.Weapons.RemoveAll(); if (cop.Model == "M_Y_SWAT") { cop.Weapons.AssaultRifle_M4.Ammo = 500; } else { cop.Weapons.Glock.Ammo = 500; } } } } void GiveCopsBats() { foreach (Ped cop in copList) { if (Game.Exists(cop) && (cop.Weapons.BaseballBat.Ammo < 1 || cop.Weapons.Glock.Ammo > 0 || cop.Weapons.AssaultRifle_M4.Ammo > 0)) { if (cop.isAliveAndWell) { cop.Weapons.RemoveAll(); cop.Weapons.BaseballBat.Ammo = 1; } } } } void GetCops() { Ped[] pedArray = World.GetAllPeds(); foreach (Ped ped in pedArray) { if (ped.isAliveAndWell && !copList.Contains(ped)) { if ((ped.RelationshipGroup == RelationshipGroup.Cop || ped.PedType == PedType.Cop) && !copList.Contains(ped)) { copList.Add(ped); } } } foreach (Ped ped in World.GetAllPeds()) { if (Game.Exists(ped)) { if (!ped.isAliveAndWell && copList.Contains(ped)) { copList.Remove(ped); } } } for (int i = 0; i < copList.Count; i++) { if (!Game.Exists(copList[i])) { copList.RemoveAt(i); } } } void GetArmedPeds() { Ped[] pedArray = World.GetAllPeds(); foreach (Ped ped in pedArray) { //skip dead if (!ped.isAliveAndWell) continue; //skip other cops if (ped.RelationshipGroup == RelationshipGroup.Cop || ped.PedType == PedType.Cop) continue; //skip unarmed and peds holding stuff like drinks/cigarettes/etc if (ped.Weapons.CurrentType == Weapon.Unarmed || ped.Weapons.CurrentType == Weapon.Misc_Object) continue; //I think these are the security guards which are armed and want to skip since not a threat if (ped.Model == "M_M_ARMOURED" || ped.Model == "M_M_SECURITYMAN") continue; //peds here are armed and will be added to list to check if in sight of any cop in cop list if (!armedList.Contains(ped)) { if (!armedList.Contains(ped)) { armedList.Add(ped); } } } //Cleanup dead peds from list foreach (Ped ped in World.GetAllPeds()) { if (Game.Exists(ped)) { if (!ped.isAliveAndWell && armedList.Contains(ped)) { armedList.Remove(ped); } } } //Cleanup deleted peds for (int i = 0; i < armedList.Count; i++) { if (!Game.Exists(armedList[i])) { armedList.RemoveAt(i); } } } bool Ped1SpottedPed2(Ped ped1, Ped ped2) { return GTA.Native.Function.Call<bool>("HAS_CHAR_SPOTTED_CHAR_IN_FRONT", ped1, ped2); } bool CopsAlarmed() { for (int i = copList.Count - 1; i >= 0; i--) { Ped cop = copList[i]; if (Game.Exists(cop) && cop.isAliveAndWell) { foreach (Ped armed in armedList) { if (Ped1SpottedPed2(cop, armed)) { return true; } } } else { copList.RemoveAt(i); } } return false; } }} This is untested so let me know how it goes Edited September 20, 2012 by ch3y3zze Link to comment Share on other sites More sharing options...
SWEG4MER Posted September 17, 2012 Author Share Posted September 17, 2012 Ok tried to fix ur bugs, see below: http://dl.dropbox.com/u/55310026/NiceCops(v2).cs namespace NiceCops{ using System; using System.Collections.Generic; using GTA; public class Main : Script { List<Ped> copList; List<Ped> armedList; bool copsAreAlarmed; public Main() { copList = new List<Ped>(); armedList = new List<Ped>(); Tick += new EventHandler(Main_Tick); } void Main_Tick(object sender, EventArgs e) { //Populates cop list with all living cops, removes dead and ones deleted by game GetCops(); //Populates armed list with all peds that are living, armed and potential threats, removes dead and ones deleted by game GetArmedPeds(); //now will check if any cop is near and can see armed ped //this will return true if armed peds can be seen by cops copsAreAlarmed = CopsAlarmed(); //if u have more than 1 star script will deactivate and cops with bats deleted //so game can replace with normal cops if (Game.LocalPlayer.WantedLevel > 1 || copsAreAlarmed)//OK now if u have wanted level or cops can see armed ped then gun cops will come { GiveCopsGuns(); } else//here u only have 0 or 1 star or no armed peds can be seen by cops so all cops will have bats only;D { GiveCopsBats(); } } void GiveCopsGuns() { foreach (Ped cop in copList) { //finds cops with bats only and gives guns (gives M4 to swat cop all others get glock unless u want that changed) if (Game.Exists(cop) && cop.Weapons.BaseballBat.Ammo == 1 && cop.Weapons.AssaultRifle_M4.Ammo == 0 && cop.Weapons.Glock.Ammo == 0) { cop.Weapons.RemoveAll(); if (cop.Model == "M_Y_SWAT") { cop.Weapons.AssaultRifle_M4.Ammo = 500; } else { cop.Weapons.Glock.Ammo = 500; } } } } void GiveCopsBats() { foreach (Ped cop in copList) { if (Game.Exists(cop) && (cop.Weapons.BaseballBat.Ammo < 1 || cop.Weapons.Glock.Ammo > 0 || cop.Weapons.AssaultRifle_M4.Ammo > 0)) { if (cop.isAliveAndWell) { cop.Weapons.RemoveAll(); cop.Weapons.BaseballBat.Ammo = 1; } } } } void GetCops() { Ped[] pedArray = World.GetAllPeds(); foreach (Ped ped in pedArray) { if (ped.isAliveAndWell && !copList.Contains(ped)) { if ((ped.RelationshipGroup == RelationshipGroup.Cop || ped.PedType == PedType.Cop) && !copList.Contains(ped)) { copList.Add(ped); } } } foreach (Ped ped in World.GetAllPeds()) { if (Game.Exists(ped)) { if (!ped.isAliveAndWell && copList.Contains(ped)) { copList.Remove(ped); } } } for (int i = 0; i < copList.Count; i++) { if (!Game.Exists(copList[i])) { copList.RemoveAt(i); } } } void GetArmedPeds() { Ped[] pedArray = World.GetAllPeds(); foreach (Ped ped in pedArray) { //skip dead if (!ped.isAliveAndWell) continue; //skip other cops if (ped.RelationshipGroup == RelationshipGroup.Cop || ped.PedType == PedType.Cop) continue; //skip unarmed and peds holding stuff like drinks/cigarettes/etc if (ped.Weapons.CurrentType == Weapon.Unarmed || ped.Weapons.CurrentType == Weapon.Misc_Object) continue; //I think these are the security guards which are armed and want to skip since not a threat if (ped.Model == "M_M_ARMOURED" || ped.Model == "M_M_SECURITYMAN") continue; //peds here are armed and will be added to list to check if in sight of any cop in cop list if (!armedList.Contains(ped)) { if (!armedList.Contains(ped)) { armedList.Add(ped); } } } //Cleanup dead peds from list foreach (Ped ped in World.GetAllPeds()) { if (Game.Exists(ped)) { if (!ped.isAliveAndWell && armedList.Contains(ped)) { armedList.Remove(ped); } } } //Cleanup deleted peds for (int i = 0; i < armedList.Count; i++) { if (!Game.Exists(armedList[i])) { armedList.RemoveAt(i); } } } bool Ped1SpottedPed2(Ped ped1, Ped ped2) { return GTA.Native.Function.Call<bool>("HAS_CHAR_SPOTTED_CHAR_IN_FRONT", ped1, ped2); } bool CopsAlarmed() { for (int i = copList.Count - 1; i >= 0; i--) { Ped cop = copList[i]; if (Game.Exists(cop) && cop.isAliveAndWell) { foreach (Ped armed in armedList) { if (Ped1SpottedPed2(cop, armed)) { return true; } } } else { copList.RemoveAt(i); } } return false; } }} This is untested so let me know how it goes So i have tested it out now and sadly it doesn't really work... The police use their pistols but when i start to fight with them i can see that some weird gun change glitch appear... like i can see that they try to use the bat but the guns is just respawning for them... First i had some other scripts installed so i removed them and tried with this one only... no change... anyway here is a log: 2012-09-17 20:28:07 - Initializing ScriptHookDotNet v1.7.1.7 BETA (on GTA IV version 1.0.7.0 with C++ Hook version 0.5.1) 2012-09-17 20:28:54 - Direct3D device created! 2012-09-17 20:28:54 - SEARCHING FOR SCRIPTS... 2012-09-17 20:28:54 - Loading dynamic scriptfile 'scripts\NiceCops(v2).cs' ... 2012-09-17 20:28:54 - ...found script 'NiceCops.Main'! 2012-09-17 20:28:54 - DONE! 1 valid scripts found! 2012-09-17 20:28:54 - STARTING SCRIPTS... 2012-09-17 20:28:54 - INFO: Phone number checks are not available! 2012-09-17 20:28:54 - ...successfully started script 'NiceCops.Main'! 2012-09-17 20:31:08 - Direct3D device lost! 2012-09-17 20:31:08 - SCRIPTS TERMINATED! Link to comment Share on other sites More sharing options...
ch3y3zze Posted September 17, 2012 Share Posted September 17, 2012 Ok well I was scared I was going to lag the game but I can try to debug once at home in front of gtaiv, so did it not work at all or was working then glitched? Link to comment Share on other sites More sharing options...
SWEG4MER Posted September 17, 2012 Author Share Posted September 17, 2012 Ok well I was scared I was going to lag the game but I can try to debug once at home in front of gtaiv, so did it not work at all or was working then glitched? Well, the officer pulled out the bat and at the same time i thought i´he was goin to hit me with it he putted it pack and started to shot me with a gun -.- so it (almost) works but something is not right... edit: no, no lag at all Link to comment Share on other sites More sharing options...
ch3y3zze Posted September 17, 2012 Share Posted September 17, 2012 Ok cool I will do my best to fix once I can play gta and test Link to comment Share on other sites More sharing options...
SWEG4MER Posted September 18, 2012 Author Share Posted September 18, 2012 Ok cool I will do my best to fix once I can play gta and test Ehm... have you found the error? Link to comment Share on other sites More sharing options...
ch3y3zze Posted September 19, 2012 Share Posted September 19, 2012 (edited) Sorry I'm lagging on this one, just working on few things, trying to get my next version of Drugwars out but I really want to fix and use this, I will try to make some time to fix tonight. I just have not even had a chance to try it but I'm not forgetting edit: testing now Edited September 20, 2012 by ch3y3zze Link to comment Share on other sites More sharing options...
ch3y3zze Posted September 20, 2012 Share Posted September 20, 2012 (edited) ok i think i have the fix and it was pretty simple actually, i was giving the instructions to the peds too quickly so look for this in the script public Main(){ copList = new List<Ped>(); armedList = new List<Ped>(); Tick += new EventHandler(Main_Tick);} and change to this, this will allow the ammo settings to be set and prevent it from glitching, lets say too much performance is not always a good thing lol public Main(){ copList = new List<Ped>(); armedList = new List<Ped>(); Interval = 1000; Tick += new EventHandler(Main_Tick);} that should get it working, basically this means my script will make a decision every 1 second, before it was set to 0 lol, ive been playing and works pretty well. Thanks for the idea, i wouldnt have thought to do this Edited September 20, 2012 by ch3y3zze Link to comment Share on other sites More sharing options...
ch3y3zze Posted September 20, 2012 Share Posted September 20, 2012 (edited) looks good to me Edited September 20, 2012 by ch3y3zze Link to comment Share on other sites More sharing options...
ch3y3zze Posted September 20, 2012 Share Posted September 20, 2012 (edited) here i compiled to a .net file for easy install and i fixed the bug, i think ill release on gta4-mods the projects and dll too, ill mention ur name edit: found a bug will update soon Ok this is working how it should. Cops will be armed with guns as soon as armed peds are within sight, so not behind a cop to make it realistic let me know how it goes: https://dl.dropbox.com/u/55310026/NiceCops.rar Edited September 20, 2012 by ch3y3zze Link to comment Share on other sites More sharing options...
SWEG4MER Posted September 20, 2012 Author Share Posted September 20, 2012 here i compiled to a .net file for easy install and i fixed the bug, i think ill release on gta4-mods the projects and dll too, ill mention ur name edit: found a bug will update soon Ok this is working how it should. Cops will be armed with guns as soon as armed peds are within sight, so not behind a cop to make it realistic let me know how it goes: https://dl.dropbox.com/u/55310026/NiceCops.rar Man, thats pure awesomeness! I dont know how i ever will be able to thank you enough... going test it in a couple of minutes... And oh btw ... u dont really have to mention my name... i wont be so active on this forum i think... but i have a youtube channel though... www.youtube.com/SWEG4MER Link to comment Share on other sites More sharing options...
SWEG4MER Posted September 20, 2012 Author Share Posted September 20, 2012 So now i've tested it and ... i must say PERFECT Link to comment Share on other sites More sharing options...
ch3y3zze Posted September 20, 2012 Share Posted September 20, 2012 Awesome here is how the script works in action, this is me debugging... Link to comment Share on other sites More sharing options...
SWEG4MER Posted September 20, 2012 Author Share Posted September 20, 2012 Awesome here is how the script works in action, this is me debugging... Just a question... i havent tested it but how does the police react to civilians with guns? Link to comment Share on other sites More sharing options...
ch3y3zze Posted September 20, 2012 Share Posted September 20, 2012 (edited) Well when armed peds r around, cops will be armed with guns so they should act normal, I didn't really notice anything that looked funny so it appears they r acting correctly, let me know what u see Edited September 20, 2012 by ch3y3zze 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