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. PC
      2. Gameplay
      3. Missions
      4. Help & Support
    2. Red Dead Online

      1. Gameplay
      2. Find Lobbies & Outlaws
      3. Help & Support
      4. Frontier Pursuits
    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 IV 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 SA Mods
    10. GTA Vice City

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

      1. Guides & Strategies
      2. Help & Support
      3. GTA III 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

Sign in to follow this  
SWEG4MER

Make police use another weapon?

Recommended Posts

ch3y3zze

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

Share this post


Link to post
Share on other sites
SWEG4MER
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!

Share this post


Link to post
Share on other sites
ch3y3zze

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?

Share this post


Link to post
Share on other sites
SWEG4MER

 

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

Share this post


Link to post
Share on other sites
ch3y3zze

Ok cool I will do my best to fix once I can play gta and test

Share this post


Link to post
Share on other sites
SWEG4MER
Ok cool I will do my best to fix once I can play gta and test

Ehm... have you found the error? smile.gif

Share this post


Link to post
Share on other sites
ch3y3zze

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

Share this post


Link to post
Share on other sites
ch3y3zze

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

Share this post


Link to post
Share on other sites
ch3y3zze

 

 

 

 

looks good to me smile.gif

Edited by ch3y3zze

Share this post


Link to post
Share on other sites
ch3y3zze

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

Share this post


Link to post
Share on other sites
SWEG4MER
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

Share this post


Link to post
Share on other sites
SWEG4MER

So now i've tested it and ... i must say PERFECT biggrin.gif

Share this post


Link to post
Share on other sites
ch3y3zze

Awesome biggrin.gif

 

here is how the script works in action, this is me debugging...

 

 

Share this post


Link to post
Share on other sites
SWEG4MER
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?

Share this post


Link to post
Share on other sites
ch3y3zze

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

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.
Note: Your post will require moderator approval before it will be visible.

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.

Sign in to follow this  

  • 2 Users Currently Viewing
    0 members, 0 Anonymous, 2 Guests

×
×
  • Create New...

Important Information

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