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())
                {
                    Ped[] peds = World.GetNearbyPeds(playerped, 700);
                    foreach (Ped p in peds)
                    {
                        if (p.IsInVehicle())
                        {
                            if (p.CurrentVehicle.Speed >= 0 && !p.CurrentVehicle.Equals(player.LastVehicle) && player.LastVehicle.Speed >= 20)
                            {
                                p.CurrentVehicle.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!");
                }
            }
        }
    }
}
