Hi everyone, I am a novice mod developer and I am facing a problem. I have written a pretty simple mod. The essence of which: After pressing the key f12 over the map displays a message that the mod is running, and within a radius of 10 meters from the player fall random cars from the sky with a height of 20 meters, and a delay of 10 seconds. I wrote it and the problem is that as soon as I try to go into story mode to check the mod the game just crashes. I hope you can help me fix this code
C#
		
					
			using GTA;
using GTA.Math;
using GTA.Native;
using System;
using System.Windows.Forms;
using System.Diagnostics.CodeAnalysis; // Добавляем пространство имен для использования атрибута AllowNull
public class CarDropMod : Script
{
    private bool isActive = false;
    private Random random = new Random();
    private int lastCarDropTime = 0;
    public CarDropMod()
    {
        // Добавляем обработчик события нажатия клавиши
        this.KeyDown += OnKeyDown;
        // Добавляем обработчик события отрисовки
        this.Tick += OnTick;
    }
    private void OnKeyDown(object sender, KeyEventArgs e)
    {
        // Проверяем, была ли нажата клавиша "F4"
        if (e.KeyCode == Keys.F4)
        {
            // Инвертируем состояние мода
            isActive = !isActive;
            // Если мод активен, запускаем таймер для сброса машин
            if (isActive)
            {
                GTA.UI.Notify("Мод активирован. Случайные машины будут сбрасываться каждые 10 секунд.");
            }
            // Если мод не активен, останавливаем таймер
            else
            {
                GTA.UI.Notify("Мод деактивирован.");
            }
        }
    }
    private void OnTick([AllowNull] object sender, EventArgs e) // Добавляем атрибут AllowNull для параметра sender
    {
        // Если мод активен, и прошло 10 секунд с последнего сброса машины
        if (isActive && Game.GameTime > lastCarDropTime + 10000)
        {
            // Сбрасываем машину
            DropRandomCar();
            // Обновляем время последнего сброса машины
            lastCarDropTime = Game.GameTime;
        }
    }
    private void DropRandomCar()
    {
        // Получаем позицию игрока
        Vector3 playerPosition = Game.Player.Character.Position;
        // Определяем высоту для сброса машины (например, 20 метров над землей)
        float dropHeight = playerPosition.Z + 20f;
        // Определяем случайную позицию в радиусе 10 метров от игрока
        Vector3 randomPosition = playerPosition.Around(10f);
        // Создаем случайную модель машины
        VehicleHash randomCarHash = (VehicleHash)random.Next(Enum.GetValues(typeof(VehicleHash)).Length);
        // Создаем машину в случайной позиции и сбрасываем ее в воздух
        Vehicle car = World.CreateVehicle(randomCarHash, randomPosition);
        if (car != null)
        {
            car.Position = new Vector3(randomPosition.X, randomPosition.Y, dropHeight);
            car.ApplyForce(Vector3.WorldDown * 20f); // Сила, с которой машина будет падать вниз
        }
    }
}
	
			Display More