using System;
using GTA;
using GTA.Native;
using System.Windows.Forms;

namespace GTAScripts
{
    public class SpeedingCars : Script
    {
        Ped playerped = Game.Player.Character;
        Player player = Game.Player;
        bool modToggle = false;
        public SpeedingCars()
        {
            KeyUp += OnKeyUp;
            Tick += OnTick;
        }

        private void OnTick(object sender, EventArgs e)
        {
            if (modToggle)
            {
                if (playerped.IsInVehicle())
                {
                    Vehicle[] vh = World.GetNearbyVehicles(playerped, 700);
                    for (int i = 0; i < vh.Length; i++)
                    {
                        if (vh[i].Speed > 0 && !vh[i].Equals(player.LastVehicle))
                        {
                            vh[i].Speed = player.LastVehicle.Speed;
                        }
                    }
                }
            }
        }
        void OnKeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F10)
            {
                modToggle = !modToggle;
                if (modToggle)
                {
                    UI.Notify("SpeedingCars has been activated!");
                }
                else
                {
                    UI.Notify("SpeedingCars has been deactivated!");
                }
            }
        }
    }
}
