//Real Police Offenses V1.3 by Qwerasdzxc
//If you have any questions or you don't understand something please ask them in the comments or on GTA:F. Username there is qwerasdzxc
using GTA;
using GTA.Math;
using GTA.Native;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;

#region IniClass
namespace Ini
{

    public class IniFile
    {
        public string path;

        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);

        /// INIFile Constructor.
        public IniFile(string INIPath)
        {
            path = INIPath;
        }
        /// Write Data to the INI File
        public void IniWriteValue(string Section, string Key, string Value)
        {
            WritePrivateProfileString(Section, Key, Value, this.path);
        }

        /// Read Data Value From the Ini File
        public string IniReadValue(string Section, string Key)
        {
            StringBuilder temp = new StringBuilder(255);
            int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.path);
            return temp.ToString();

        }
    }
}
#endregion

public class RealLife : Script
{

    //Bodyguard test
    int max_companions = 5;
    List<Ped> group_members = new List<Ped>();
    //Police chase timer
    int startTime;
    int waitTime = 20000;
    bool timerStarted = false;
    Vehicle currVeh = Game.Player.Character.CurrentVehicle;

    public RealLife()
    {
        Tick += OnTick;
        KeyDown += OnKeyDown;
        KeyUp += OnKeyUp;

        Interval = 10;
    }

    //Function for printing text in-game
    public void PrintText(string text, int time)
    {
        GTA.Native.Function.Call(GTA.Native.Hash._SET_TEXT_ENTRY_2, "STRING");
        GTA.Native.Function.Call(GTA.Native.Hash._ADD_TEXT_COMPONENT_STRING, text);
        GTA.Native.Function.Call(GTA.Native.Hash._0x9D77056A530643F6, time, 1);
        GTA.Native.Function.Call(GTA.Native.Hash.SET_TEXT_COLOUR, 49, 136, 222, 255); //Not working 
    }

    //Police pursuit texts
    public void PoliceText()
    {
        Random rand2 = new Random();
        Ped playerPed = Game.Player.Character;
        Vehicle currVeh = GTA.Native.Function.Call<Vehicle>(GTA.Native.Hash.GET_VEHICLE_PED_IS_IN, playerPed, false);
        PrintText("~b~POLICE~w~: This is unit " + rand2.Next(105, 999) + ", vehicle didn't stop and we're in pursuit. Plate number is " + currVeh.NumberPlate + "!", 6500);
    }
    public void PoliceText2()
    {
        Random rand3 = new Random();
        Ped playerPed = Game.Player.Character;
        Vehicle currVeh = GTA.Native.Function.Call<Vehicle>(GTA.Native.Hash.GET_VEHICLE_PED_IS_IN, playerPed, false);
        PrintText("~b~POLICE~w~: Suspect is resisting the ticket. Plate number is " + currVeh.NumberPlate + ", we're in full pursuit!", 6500);
    }
    //Above Map Function
    public void NotifyText(string text)
    {
        UI.Notify(text);
    }

    //Police chase timer
    void StartTimer()
    {
        timerStarted = true;
        startTime = Game.GameTime + waitTime;
    }

    //Paying ticket
    void payTicket()
    {
        Player player = Game.Player;
        player.Money = player.Money - 650;
    }

    void payTicket2()
    {
        Player player = Game.Player;
        player.Money = player.Money - 350;
    }

    void payTicket3()
    {
        Player player = Game.Player;
        player.Money = player.Money - 150;
    }

    //Test
    int timeTraffic = 0;
    //Bool for on/off
    Boolean modActive = true;
    //Bools for one-time only text
    Boolean cops = false;
    //Welcome message
    Boolean welcomeMessage = false;
    //Bools for detecting vehicle
    Boolean isEntityHeli = false;
    Boolean isEntityPlane = false;
    Boolean isEntityBoat = false;
    Boolean isEntityBicycle = false;
    //Bool for accept/refuse
    Boolean accepted = false;
    Boolean refused = false;
    Boolean questionActive = false;
    Boolean noWarning = false;
    //Bool for not displaying damage
    Boolean noDamage = false;
    //Bool for police ped spawn
    Boolean policePedSpawned = false;
    //Bools and floats for cruise control
    Boolean cruiseControl = false;
    float cruiseSpeed = 0f;
    float currDamage = 0f;
    Model currVehModel2;
    //Counters
    int warning = 0;
    int wrongLane = 0;
    int trafficLight = 0;
    //Models
    Model currVehModel;
    Ped policePed;
    Ped companion;
    Vehicle policeCar;

    void OnTick(object sender, EventArgs e)
    {

        //Speeding and damage offenses bellow

        Player player = Game.Player;
        Ped playerPed = Game.Player.Character;
        Vehicle currVeh = GTA.Native.Function.Call<Vehicle>(GTA.Native.Hash.GET_VEHICLE_PED_IS_IN, playerPed, false);
        GTA.Math.Vector3 playerPos = playerPed.Position;

        /*
        while (true)
        {
            if (cops == true)
                break;
            else
            {
                //On-tick spawn vehicles test

                //Spawning police vehicles and peds

                //Location 1 = X: -628.2053 Y: 290.1088 Z: 81.18893         prop_t_telescope_01b = telescope in house      prop_telescope_01 = telescope at pier
                //Location 2 = X: 173.7699 Y: 191.7305 Z: 105.2278        
                //Location 3 = X: 964.2743 Y: 162.1605 Z: 80.34409      
                //Location 4 = X: 1288.655 Y: 849.359 Z: 105.0375   - Police
                //Location 5 = X 2711.309 Y: 4751.568 Z: 43.85955   - Police2       Ped - 2709.237    4752.776    44.34803
                //Location 6 = X: 1993.564 Y: 2604.684 Z: 54.30703  - Police3
                //More locations bellow..                            Prop -634.0299 290.4735 81.52164        Prop2 2711.422   4756.097   44.35828

                //Cars
                
                //Police
                GTA.Math.Vector3 policeVehVector3 = new GTA.Math.Vector3(-628.2053f, 290.1088f, 81.18893f);
                Vehicle policeVeh = GTA.World.CreateVehicle("Police", policeVehVector3);
                policeVeh.IsPersistent = true;
                policeVeh.Heading = 90f;

                GTA.Math.Vector3 policeVeh5Vector3 = new GTA.Math.Vector3(1288.655f, 849.359f, 105.0375f);
                Vehicle policeVeh5 = GTA.World.CreateVehicle("Police", policeVeh5Vector3);
                policeVeh5.IsPersistent = true; //Heading?

                //Police2

                GTA.Math.Vector3 policeVeh2Vector3 = new GTA.Math.Vector3(173.7699f, 191.7305f, 105.2278f);
                Vehicle policeVeh2 = GTA.World.CreateVehicle("Police2", policeVeh2Vector3);
                policeVeh2.IsPersistent = true;
                policeVeh2.Heading = 75f;  //Or 105f

                GTA.Math.Vector3 policeVeh4Vector3 = new GTA.Math.Vector3(2711.309f, 4751.568f, 43.85955f);
                Vehicle policeVeh4 = GTA.World.CreateVehicle("Police2", policeVeh4Vector3);
                policeVeh4.IsPersistent = true; //Heading?

                //Police3
                GTA.Math.Vector3 policeVeh3Vector3 = new GTA.Math.Vector3(964.2743f, 162.1605f, 80.34409f);
                Vehicle policeVeh3 = GTA.World.CreateVehicle("Police3", policeVeh3Vector3);
                policeVeh3.IsPersistent = true;
                policeVeh3.Heading = 180f;

                GTA.Math.Vector3 policeVeh6Vector3 = new GTA.Math.Vector3(1993.564f, 2604.684f, 54.30703f);
                Vehicle policeVeh6 = GTA.World.CreateVehicle("Police3", policeVeh6Vector3);
                policeVeh3.IsPersistent = true;
                policeVeh3.Heading = 180f;

                GTA.Math.Vector3 policeVeh7Vector3 = new GTA.Math.Vector3(667.2321f, 3528.822f, 33.79383f);
                Vehicle policeVeh7 = GTA.World.CreateVehicle("Police3", policeVeh7Vector3);
                policeVeh7.IsPersistent = true;

                //End of spawning vehs

                //Props

                GTA.Math.Vector3 policeCameraVector3 = new GTA.Math.Vector3(-634.0299f, 290.4735f, 81.52164f);
                Prop policeCamera = GTA.World.CreateProp("prop_telescope_01", policeCameraVector3, false, true);
                policeCamera.IsPersistent = true;
                policeVeh7.Heading = 180f;

                //Can't spawn 2 props :/

                //End of spawning props

                cops = true;
            }
            Script.Wait(10);
        }
        */

        //Test for welcome message with bool for one time only
        if (welcomeMessage == false)
        {
            Script.Wait(15000);
            UI.Notify("Welcome to Qwerasdzxc's ~b~Real Police Offenses V1.7~w~\nHope you'll have fun with it!");
            welcomeMessage = true;
        }



        //Bodyguards test

        //Kiling and removing guards on player dead
        if (player.IsDead && group_members.Count > 0)
        {
            for (int i = 0; i < group_members.Count; i++)
            {
                group_members[i].Kill();
                group_members.RemoveAt(i);
            }
        }

        //Removing guard if guard dead
        for (int i = 0; i < group_members.Count; i++)
        {
            if (group_members[i].IsDead)
            {
                group_members.RemoveAt(i);
            }
        }

        //End of Bodyguard test

        if (!Entity.Exists(currVeh)) return; // If you are not in a car, dont run this code

        //Area for checking if vehicle is plane,heli... and if vehicle is emergency
        int currVehHash = currVeh.Model.Hash;

        isEntityHeli = GTA.Native.Function.Call<Boolean>(GTA.Native.Hash.IS_THIS_MODEL_A_HELI, currVehHash);
        isEntityPlane = GTA.Native.Function.Call<Boolean>(GTA.Native.Hash.IS_THIS_MODEL_A_PLANE, currVehHash);
        isEntityBoat = GTA.Native.Function.Call<Boolean>(GTA.Native.Hash.IS_THIS_MODEL_A_BOAT, currVehHash);
        isEntityBicycle = GTA.Native.Function.Call<Boolean>(GTA.Native.Hash.IS_THIS_MODEL_A_BICYCLE, currVehHash);

        if ((isEntityBicycle == true) || (isEntityHeli == true) || (isEntityPlane == true) || (isEntityBoat == true))
        {
            return;
        }

        if (currVeh.Model.Equals("Police") || currVeh.Model.Equals("Police2") || currVeh.Model.Equals("Police3") || currVeh.Model.Equals("Police4") || currVeh.Model.Equals("FBI") || currVeh.Model.Equals("FBI2") || currVeh.Model.Equals("FireTruck") || currVeh.Model.Equals("Policeb") || currVeh.Model.Equals("PoliceT") || currVeh.Model.Equals("PoliceOld1") || currVeh.Model.Equals("PoliceOld2") || currVeh.Model.Equals("Ambulance")) return; // Runs only if not in emergency vehicle

        //END of area for checking if vehicle is plane,heli... and if vehicle is emergency

        //Speeding offenses

        float radius = 350f;    // Radius for detecting police vehicles

        //Getting closest police vehicles positions

        Vehicle closestPoliceVeh = GTA.Native.Function.Call<Vehicle>(GTA.Native.Hash.GET_CLOSEST_VEHICLE, playerPos.X, playerPos.Y, playerPos.Z, radius, 0x79FBB0C5, 70); // Police
        Vehicle closestPoliceVeh2 = GTA.Native.Function.Call<Vehicle>(GTA.Native.Hash.GET_CLOSEST_VEHICLE, playerPos.X, playerPos.Y, playerPos.Z, radius, 0x9F05F101, 70); // Police2
        Vehicle closestPoliceVeh3 = GTA.Native.Function.Call<Vehicle>(GTA.Native.Hash.GET_CLOSEST_VEHICLE, playerPos.X, playerPos.Y, playerPos.Z, radius, 0x71FA16EA, 70); // Police3
        Vehicle closestPoliceVeh4 = GTA.Native.Function.Call<Vehicle>(GTA.Native.Hash.GET_CLOSEST_VEHICLE, playerPos.X, playerPos.Y, playerPos.Z, radius, 0x8A63C7B9, 70); // Police4  
        Vehicle closestPoliceBike = GTA.Native.Function.Call<Vehicle>(GTA.Native.Hash.GET_CLOSEST_VEHICLE, playerPos.X, playerPos.Y, playerPos.Z, radius, 0xFDEFAEC3, 70); //Policeb
        Vehicle closestPoliceFBI = GTA.Native.Function.Call<Vehicle>(GTA.Native.Hash.GET_CLOSEST_VEHICLE, playerPos.X, playerPos.Y, playerPos.Z, radius, 0x432EA949, 70); //FBI
        Vehicle closestPoliceFBI2 = GTA.Native.Function.Call<Vehicle>(GTA.Native.Hash.GET_CLOSEST_VEHICLE, playerPos.X, playerPos.Y, playerPos.Z, radius, 0x9DC66994, 70); //FBI2

        Prop closestCamera = GTA.Native.Function.Call<Prop>(GTA.Native.Hash.GET_CLOSEST_OBJECT_OF_TYPE, playerPos.X, playerPos.Y, playerPos.Z, radius, 0x46B1A5AE, true); //Telescope :D

        // Check if breaking the law around existing police
        if (modActive == false) return;

        else if (Entity.Exists(closestPoliceVeh) || Entity.Exists(closestPoliceVeh2) || Entity.Exists(closestPoliceVeh3) || Entity.Exists(closestPoliceVeh4) || Entity.Exists(closestPoliceBike) || Entity.Exists(closestPoliceFBI) || Entity.Exists(closestPoliceFBI2) || Entity.Exists(closestCamera) && (modActive == true))
        {
            float currVehSpeed = currVeh.Speed;

            //Defining random
            Random rand2 = new Random();

            if (currVehSpeed > 36f && currVehSpeed < 42f && player.WantedLevel < 1 && noWarning == false)   // 42f = 155 Km/h
            {
                PrintText("~b~POLICE~w~: You're driving over the speed limit for this area!\n Slow down immediately!", 2500);
            }

            else if (currVehSpeed > 42f && player.WantedLevel < 1)
            {
                warning++;
                //player.WantedLevel = 1;
                PrintText("~b~POLICE~w~: You are speeding! Stop the vehicle now to evade the trouble!", 3500);
                Script.Wait(3000);
                StartTimer();
                questionActive = true;
                noWarning = true;
            }

            // Vehicle damage warnings
            float engineHealth = currVeh.EngineHealth;


            if (currVehModel != currVeh.Model)
            {
                noDamage = false;
            }

            if (engineHealth < 860 && engineHealth > 700 && player.WantedLevel < 1 && modActive == true)
            {

                PrintText("~b~POLICE~w~: Your vehicle is pretty damaged, you should repair it!", 2500);

            }
            else if (engineHealth < 700 && engineHealth > 500 && player.WantedLevel < 1 && modActive == true)
            {

                PrintText("~b~POLICE~w~: Your vehicle is damaged and isn't roadworthy! Please repair it!", 3500);

            }
            else if (engineHealth < 500 && player.WantedLevel < 1 && noWarning == false && modActive == true && noDamage == false)
            {
                payTicket2();
                PrintText("~b~POLICE~w~: Your vehicle is severly damaged and is not roadworthy. We have to charge you ~r~350$~w~!", 5000);

                currVehModel = currVeh.Model;
                noDamage = true;
            }

            //Driving in the wrong lane Real Life V1.7
            timeTraffic = GTA.Native.Function.Call<int>(GTA.Native.Hash.GET_TIME_SINCE_PLAYER_DROVE_AGAINST_TRAFFIC, player);


            if (timeTraffic == 0 && player.WantedLevel < 1)
            {
                if (wrongLane < 3)
                {
                    PrintText("~b~POLICE~w~: You're driving in the wrong direction! Turn your vehicle immediately!", 2500);
                }

                wrongLane++;

                if (wrongLane < 3)
                {
                    Wait(5000);
                }
            }

            //Starting timer for wrong lane
            if (wrongLane > 3 && timerStarted == false)
            {
                StartTimer();
                questionActive = true;
                PrintText("~b~POLICE~w~: You have to pay a ticket for unsafe driving!\nStop the vehicle to procceed!", 4000);
            }

            //Traffic lights offenses
            Vehicle closestVehicle = GTA.Native.Function.Call<Vehicle>(GTA.Native.Hash.GET_CLOSEST_VEHICLE, playerPos.X, playerPos.Y, playerPos.Z, 50f, 0, 70);

            /*
            if (Function.Call<bool>(Hash.IS_VEHICLE_STOPPED_AT_TRAFFIC_LIGHTS, closestVehicle) && (Math.Abs(closestVehicle.Heading - currVeh.Heading) < 30f) && (trafficLight < 3)) //&& (currVeh.Speed <= closestVehicle.Speed)
            {
                if (trafficLight <= 1)
                {
                    PrintText("~b~POLICE~w~: You passed through red light! Watch your driving!", 2500);
                    trafficLight++;
                    Wait(3000);
                }
                else if (trafficLight > 1)
                {
                    PrintText("~b~POLICE~w~: Stop the vehicle immediately to pay the ticket, you're passing through red lights!", 2500);
                    trafficLight++;
                    Wait(3000);
                }
            }
            */
        }

        //Area for tickets and stops

        if (warning > 0 && currVeh.Speed == 0)
        {
            PrintText("~b~POLICE~w~: Please pay the ticket to avoid unnecessary trouble!", 2500);
            UI.Notify("Press ~b~Y~w~ to pay the ticket\nPress ~r~N~w~ to refuse the ticket");
            currVeh.EngineRunning = false;

            if (policePedSpawned == false)
            {
                float currVehHeading = currVeh.Heading;
                policeCar = GTA.World.CreateVehicle("Police2", playerPed.Position + (playerPed.ForwardVector * -10));
                policeCar.Heading = currVeh.Heading;
                policePed = GTA.World.CreatePed("csb_cop", playerPed.Position + (playerPed.RightVector * -2));
                policePed.Heading = currVehHeading - 80f;
                policePedSpawned = true;
                Script.Wait(300);
                GTA.Native.Function.Call(GTA.Native.Hash.TASK_START_SCENARIO_IN_PLACE, policePed, "CODE_HUMAN_MEDIC_TIME_OF_DEATH", 1, true);
            }

            if (accepted == true)
            {
                PrintText("~b~POLICE~w~: Thanks for paying the ~r~650$~w~ ticket! Drive safe in the future!", 3000);
                payTicket();
                player.WantedLevel = 0;
                warning = 0;
                accepted = false;
                questionActive = false;
                timerStarted = false;
                noWarning = false;
                startTime = 0;
                currVeh.EngineRunning = true;
                policePedSpawned = false;
                policePed.Task.GoTo(policeCar);
                policePed.Task.EnterVehicle(policeCar, VehicleSeat.Driver, 0);
                policePed.Task.CruiseWithVehicle(policeCar, 10f);

            }
            else if (refused == true)
            {
                PoliceText2();
                player.WantedLevel = 2;
                warning = 0;
                refused = false;
                questionActive = false;
                timerStarted = false;
                noWarning = false;
                startTime = 0;
                currVeh.EngineRunning = true;
                policePedSpawned = false;
            }

        }

        if (wrongLane > 3 && currVeh.Speed <= 1)
        {
            PrintText("~b~POLICE~w~: Please pay the ticket to avoid unnecessary trouble!", 2500);
            UI.Notify("Press ~b~Y~w~ to pay the ticket\nPress ~r~N~w~ to refuse the ticket");
            currVeh.EngineRunning = false;

            if (policePedSpawned == false)
            {
                float currVehHeading = currVeh.Heading;
                policeCar = GTA.World.CreateVehicle("Police2", playerPed.Position + (playerPed.ForwardVector * -10));
                policeCar.Heading = currVeh.Heading;
                policePed = GTA.World.CreatePed("csb_cop", playerPed.Position + (playerPed.RightVector * -2));
                policePed.Heading = currVehHeading - 80f;
                policePedSpawned = true;
                Script.Wait(300);
                GTA.Native.Function.Call(GTA.Native.Hash.TASK_START_SCENARIO_IN_PLACE, policePed, "CODE_HUMAN_MEDIC_TIME_OF_DEATH", 1, true);
            }

            if (accepted == true)
            {
                PrintText("~b~POLICE~w~: Thanks for paying the ~r~150$~w~ ticket! Drive safe in the future!", 2500);
                payTicket3();
                player.WantedLevel = 0;
                wrongLane = 0;
                accepted = false;
                questionActive = false;
                timerStarted = false;
                startTime = 0;
                currVeh.EngineRunning = true;
                policePedSpawned = false;
                policePed.Task.GoTo(policeCar);
                policePed.Task.EnterVehicle(policeCar, VehicleSeat.Driver, 0);
                policePed.Task.CruiseWithVehicle(policeCar, 10f);
            }
            else if (refused == true)
            {
                PoliceText2();
                player.WantedLevel = 2;
                wrongLane = 0;
                refused = false;
                questionActive = false;
                timerStarted = false;
                noWarning = false;
                startTime = 0;
                currVeh.EngineRunning = true;
                policePedSpawned = false;
            }
        }

        if (trafficLight > 1 && currVeh.Speed == 0)
        {
            questionActive = true;
            PrintText("~b~POLICE~w~: Please pay the ticket to avoid unnecessary trouble!", 2500);
            UI.Notify("Press ~b~Y~w~ to pay the ticket\nPress ~r~N~w~ to refuse the ticket");
            currVeh.EngineRunning = false;

            if (policePedSpawned == false)
            {
                float currVehHeading = currVeh.Heading;
                policeCar = GTA.World.CreateVehicle("Police2", playerPed.Position + (playerPed.ForwardVector * -10));
                policeCar.Heading = currVeh.Heading;
                policePed = GTA.World.CreatePed("csb_cop", playerPed.Position + (playerPed.RightVector * -2));
                policePed.Heading = currVehHeading - 80f;
                policePedSpawned = true;
                Script.Wait(300);
                GTA.Native.Function.Call(GTA.Native.Hash.TASK_START_SCENARIO_IN_PLACE, policePed, "CODE_HUMAN_MEDIC_TIME_OF_DEATH", 1, true);
            }

            if (accepted == true)
            {
                PrintText("~b~POLICE~w~: Thanks for paying the ~r~500$~w~ ticket! Drive safe in the future!", 3000);
                payTicket();
                player.WantedLevel = 0;
                trafficLight = 0;
                accepted = false;
                questionActive = false;
                timerStarted = false;
                noWarning = false;
                startTime = 0;
                currVeh.EngineRunning = true;
                policePedSpawned = false;
                policePed.Task.GoTo(policeCar);
                policePed.Task.EnterVehicle(policeCar, VehicleSeat.Driver, 0);
                policePed.Task.CruiseWithVehicle(policeCar, 10f);

            }
            else if (refused == true)
            {
                PoliceText2();
                player.WantedLevel = 2;
                trafficLight = 0;
                refused = false;
                questionActive = false;
                timerStarted = false;
                noWarning = false;
                startTime = 0;
                currVeh.EngineRunning = true;
                policePedSpawned = false;
            }

        }

        ///////////////////

        if (timerStarted && Game.GameTime > startTime && currVeh.Speed > 0 && questionActive == true)
        {
            timerStarted = false;
            noWarning = false;
            PoliceText();
            player.WantedLevel = 2;
            warning = 0;
            questionActive = false;
            startTime = 0;
            wrongLane = 0;

        }

        if (playerPed.IsDead == true)
        {
            timerStarted = false;
            noWarning = false;
            warning = 0;
            wrongLane = 0;
            questionActive = false;
            startTime = 0;
            refused = false;
            accepted = false;
        }
        /*
        if (cruiseControl == true)
        {
            currVeh.Speed = cruiseSpeed;
        }

        
        if (currVeh.EngineHealth < currDamage && cruiseControl == true)
        {
            UI.Notify("~r~Cruise control~w~ now disabled");
            cruiseControl = false;
        }
        */
       
    }


    void OnKeyDown(object sender, KeyEventArgs e)
    {
        /* if ((e.KeyCode == Keys.W || e.KeyCode == Keys.S || e.KeyCode == Keys.Space) && cruiseControl == true)
         {
             cruiseControl = false;
             UI.Notify("~r~Cruise control~w~ now disabled");
         } */
    }

    void OnKeyUp(object sender, KeyEventArgs e)
    {
        Ped playerPed = Game.Player.Character;
        
        //Bodyguards test
        if (e.KeyCode == Keys.NumPad3 && group_members.Count < max_companions && modActive == true)
        {

            PrintText("~r~Guard~w~ Spawned!", 2500);

            Vehicle lastVeh = Game.Player.LastVehicle;
            Ped player = Game.Player.Character;
            Player Pplayer = Game.Player;
            GTA.Math.Vector3 spawnLoc = player.Position + (player.ForwardVector * 5);

            //Defining guards
            List<string> model_names = new List<string>();
            model_names.Add("u_m_m_bankman");
            model_names.Add("u_m_m_fibarchitect");
            model_names.Add("G_M_M_ArmBoss_01");
            model_names.Add("ig_fbisuit_01");
            model_names.Add("s_m_y_doorman_01");

            //Defining random
            Random rand = new Random();

            //Spawning guards
            companion = GTA.World.CreatePed(model_names[rand.Next(0, model_names.Count - 1)], spawnLoc);
            group_members.Add(companion);

            //Putting guards to follow you
            int player_group = GTA.Native.Function.Call<int>(GTA.Native.Hash.GET_PED_GROUP_INDEX, player.ID);
            GTA.Native.Function.Call(GTA.Native.Hash.SET_PED_AS_GROUP_MEMBER, companion.ID, player_group);

            //Putting guards to protect you
            companion.Task.ClearAllImmediately();
            GTA.Native.Function.Call(GTA.Native.Hash.TASK_COMBAT_HATED_TARGETS_IN_AREA, companion, 50000, 0);
            GTA.Native.Function.Call(GTA.Native.Hash.SET_PED_KEEP_TASK, companion, true);

            //Giving guards weapons
            GTA.Native.Function.Call(GTA.Native.Hash.GIVE_WEAPON_TO_PED, companion.ID, 0x1B06D571, 200, true, true);  // Need to check
            GTA.Native.Function.Call(GTA.Native.Hash.GIVE_WEAPON_TO_PED, companion, 0x1B06D571, 200, true, true);   // which one works?

            //Giving guards armour
            GTA.Native.Function.Call(GTA.Native.Hash.SET_PLAYER_MAX_ARMOUR, companion, true);   // or companion.ID ?

            //Find a way to add and remove blips on guards
        }

        if (e.KeyCode == Keys.NumPad6 && modActive == true)
        {
            //Killing and removing guards
            group_members[group_members.Count - 1].Kill();
            group_members.RemoveAt(group_members.Count - 1);

            PrintText("~r~Guard~w~ Removed!", 2500);
        }
        
        //Activation and de-activation Real Life 1.2 Update
        if (e.KeyCode == Keys.PageDown && modActive == true)
        {
            UI.Notify("~b~Real Police Offenses~w~ by Qwerasdzxc turned off\nTo turn it on again press ~g~PageUp~w~");
            modActive = false;
            timerStarted = false;
            noWarning = false;
            warning = 0;
            questionActive = false;
            startTime = 0;
            refused = false;
            accepted = false;
            questionActive = false;
            startTime = 0;
            wrongLane = 0;
            trafficLight = 0;
        }

        if (e.KeyCode == Keys.PageUp && modActive == false)
        {
            UI.Notify("~b~Real Police Offenses~w~ by Qwerasdzxc turned on\nTo turn it off again press ~g~PageDown~w~");
            modActive = true;
        }

        if (e.KeyCode == Keys.Y && questionActive == true)
        {
            accepted = true;
        }

        if (e.KeyCode == Keys.N && questionActive == true)
        {
            refused = true;
        }

        /*
        if (e.KeyCode == Keys.N)
        {
            GTA.Native.Function.Call(GTA.Native.Hash.TASK_START_SCENARIO_IN_PLACE, playerPed, "CODE_HUMAN_MEDIC_TIME_OF_DEATH", 1, true);
        }

        if (e.KeyCode == Keys.K)
        {
            playerPed.Task.ClearAllImmediately();
        }
        
        if (e.KeyCode == Keys.NumPad7 && cruiseControl == false)
        {
            currVehModel2 = currVeh.Model;
            float kmhSpeed = currVeh.Speed * 2.25f * 1.60934f;
            UI.Notify("~b~Cruise control~w~ now active\nYour speed is " + Math.Round(kmhSpeed) + " Km/h");
            cruiseControl = true;
            cruiseSpeed = currVeh.Speed;
            currDamage = currVeh.EngineHealth;
        }
        */

        /*
        if (e.KeyCode == Keys.O)
        {
            GTA.Native.Function.Call(GTA.Native.Hash.TASK_START_SCENARIO_IN_PLACE, playerPed, "CODE_HUMAN_POLICE_INVESTIGATE", 1, true); //test animation with leaning !!!
            PrintText("Animation started!", 2500);
        }
        if (e.KeyCode == Keys.L)
        {
            playerPed.Task.ClearAllImmediately();
            playerPed.Task.ClearAnimation("WORLD_HUMAN_CLIPBOARD", "WORLD_HUMAN_CLIPBOARD");
        }
        */
    }
}