Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Drug Wars
      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

Make police use another weapon?


SWEG4MER
 Share

Recommended Posts

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 wink.gif

Edited by ch3y3zze
Link to comment
Share on other sites

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 wink.gif

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

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

 

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 smile.gif

Link to comment
Share on other sites

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 wink.gif

 

edit: testing now

Edited by ch3y3zze
Link to comment
Share on other sites

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 wink.gif

Edited by ch3y3zze
Link to comment
Share on other sites

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 wink.gif

 

edit: found a bug wow.gif will update soon wink.gif

 

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 by ch3y3zze
Link to comment
Share on other sites

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 wink.gif

 

edit: found a bug wow.gif will update soon wink.gif

 

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

Awesome biggrin.gif

 

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

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 wink.gif

Edited by ch3y3zze
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.