using System;
using System.Drawing;
using System.Windows.Forms;
using GTA;

namespace SilientShoot
{

   public class SilientShoot : Script
   {
       bool stopclearwanted=true;
       int indexplayer;
       Weapon yourweapon;

       public SilientShoot()
       {
           //Interval = Settings.GetValueInteger("INTERVAL", "SETTINGS", 5);   // Interval how many times in miliseconds will run script
           this.Tick += new EventHandler(this.IgnoreShoot);
       }
       private void IgnoreShoot(object sender, EventArgs e)
       {
           if (Player.Character.Weapons.CurrentType == Weapon.SMG_MP5)   // Your silient weapon. CHANGE IT !!!
           {
               indexplayer = Player.Index;
               if (GTA.Game.isGameKeyPressed(GameKey.Aim))
               {

                   Ped[] pedArray = GTA.World.GetPeds(Player.Character.Position, 100.00F);
                   foreach (GTA.Ped pedignoreplayer in pedArray)
                   {
                       if ((pedignoreplayer == null) || (pedignoreplayer == Player.Character))
                       {
                           continue;
                       }
                       GTA.Native.Function.Call("SET_EVERYONE_IGNORE_PLAYER", indexplayer, true);
                       GTA.Native.Function.Call("SET_BLOCKING_OF_NON_TEMPORARY_EVENTS", pedignoreplayer, true);
                       GTA.Native.Function.Call("CANCEL_CURRENTLY_PLAYING_AMBIENT_SPEECH", pedignoreplayer);
                       if (GTA.Native.Function.Call<bool>("IS_CHAR_SHOOTING", Player.Character))
                       {
                           stopclearwanted = false;
                       }
                       else
                           if (!(GTA.Native.Function.Call<bool>("IS_CHAR_SHOOTING", Player.Character)))
                           {
                               if (pedignoreplayer.Position.DistanceTo(Player.Character.Position) < 5.9F)
                               {
                                   GTA.Native.Function.Call("SET_EVERYONE_IGNORE_PLAYER", indexplayer, false);
                                   GTA.Native.Function.Call("SET_BLOCKING_OF_NON_TEMPORARY_EVENTS", pedignoreplayer, false);
                               }
                           }
                   }
               }
               else if (!(GTA.Game.isGameKeyPressed(GameKey.Aim)))
               {

                   if (stopclearwanted == false)
                   {
                       stopclearwanted = true;

                       Ped[] pedArray2 = GTA.World.GetPeds(Player.Character.Position, 100.00F);
                       foreach (GTA.Ped pedaround in pedArray2)
                       {
                           if ((pedaround == null) || (pedaround == Player.Character))
                           {
                               continue;
                           }
                           if (pedaround.Position.DistanceTo(Player.Character.Position) < 5.0F)
                           {
                               GTA.Native.Function.Call("SET_EVERYONE_IGNORE_PLAYER", indexplayer, false);
                               GTA.Native.Function.Call("SET_BLOCKING_OF_NON_TEMPORARY_EVENTS", pedaround, false);
                               pedaround.Task.ClearAll();

                           }

                       }
                   }
               }
           }
               else
               {
                   Ped[] pedArray3 = GTA.World.GetPeds(Player.Character.Position, 100.00F);
                   foreach (GTA.Ped pednormal in pedArray3)
                   {
                       if ((pednormal == null) || (pednormal == Player.Character))
                       {
                           continue;
                       }
                       GTA.Native.Function.Call("SET_EVERYONE_IGNORE_PLAYER", indexplayer, false);
                       GTA.Native.Function.Call("SET_BLOCKING_OF_NON_TEMPORARY_EVENTS", pednormal, false);

                   }
               }
           }
       }
}

