Загрузка данных


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

public class NativeVehicleCamera : Script
{
    private float _heightOffset = 0.90f; 
    private bool _wasInCar = false;
    private ScriptSettings _config;

    public NativeVehicleCamera()
    {
        _config = ScriptSettings.Load("scripts\\CameraOffsets.ini");
        KeyDown += OnKeyDown;
        Tick += OnTick;
        UI.Notify("~g~[v3] Нативный скрипт камеры загружен!");
    }

    private void OnTick(object sender, EventArgs e)
    {
        var vehicle = Game.Player.Character.CurrentVehicle;

        if (vehicle == null) 
        {
            Function.Call(Hash.SET_FOLLOW_VEHICLE_CAM_OFFSET, 1, 0.0f, 0.0f, 0.0f);
            _wasInCar = false;
            return; 
        }

        bool isTarget = (vehicle.Model.Hash == Game.GenerateHash("jzx100") || 
                         vehicle.Model.Hash == Game.GenerateHash("mk2100"));

        if (isTarget)
        {
            // При посадке считываем сохраненную высоту из INI-файла
            if (!_wasInCar)
            {
                string modelName = GetModelName(vehicle);
                _heightOffset = _config.GetValue<float>("Offsets", modelName, 0.90f);
                _wasInCar = true;
            }

            int viewMode = Function.Call<int>(Hash.GET_FOLLOW_VEHICLE_CAM_VIEW_MODE);
            
            // Опускаем камеру только для третьего лица
            if (viewMode != 4) 
            {
                Function.Call(Hash.SET_FOLLOW_VEHICLE_CAM_OFFSET, 1, 0.0f, 0.0f, _heightOffset);
            }
        }
        else
        {
            _wasInCar = false;
            Function.Call(Hash.SET_FOLLOW_VEHICLE_CAM_OFFSET, 1, 0.0f, 0.0f, 0.0f);
        }
    }

    private void OnKeyDown(object sender, KeyEventArgs e)
    {
        var vehicle = Game.Player.Character.CurrentVehicle;
        if (vehicle == null) return;
        
        bool isTarget = (vehicle.Model.Hash == Game.GenerateHash("jzx100") || 
                         vehicle.Model.Hash == Game.GenerateHash("mk2100"));
        if (!isTarget) return;

        if (e.KeyCode == Keys.NumPad9)
        {
            _heightOffset += 0.05f;
            SaveHeight(vehicle);
            UI.Notify("~g~Высота: " + _heightOffset.ToString("F2")); 
        }
        else if (e.KeyCode == Keys.NumPad3)
        {
            _heightOffset -= 0.05f;
            SaveHeight(vehicle);
            UI.Notify("~y~Высота: " + _heightOffset.ToString("F2")); 
        }
    }

    private string GetModelName(Vehicle vehicle)
    {
        if (vehicle.Model.Hash == Game.GenerateHash("jzx100")) return "jzx100";
        return "mk2100"; 
    }

    private void SaveHeight(Vehicle vehicle)
    {
        _config.SetValue<float>("Offsets", GetModelName(vehicle), _heightOffset);
        _config.Save();
    }
}