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


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

public class SedanCabinCamera : Script
{
    private Camera _carCamera;
    private float _heightOffset = 1.2f; 
    private bool _wasInCar = false;
    private float _currentHeadingOffset = 0.0f;
    private float _currentPitch = 0.0f;

    public SedanCabinCamera()
    {
        KeyDown += OnKeyDown;
        Tick += OnTick;
        UI.Notify("~g~Скрипт камеры (v2) успешно загружен!");
    }

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

        if (vehicle == null) 
        { 
            RemoveCamera(); 
            _wasInCar = false; 
            return; 
        }

        bool isTarget = (vehicle.Model.Hash == Game.GenerateHash("jzx100") || 
                         vehicle.Model.Hash == Game.GenerateHash("mk2100"));
        
        if (!isTarget) 
        { 
            RemoveCamera(); 
            _wasInCar = false; 
            return; 
        }

        if (!_wasInCar)
        {
            UI.Notify("~b~Обнаружена машина: " + vehicle.Model.ToString());
            _wasInCar = true;
        }

        if (Function.Call<int>(Hash.GET_FOLLOW_VEHICLE_CAM_VIEW_MODE) == 4) 
        { 
            RemoveCamera(); 
            return; 
        }

        if (_carCamera == null || !_carCamera.Exists())
        {
            _carCamera = World.CreateCamera(vehicle.Position, vehicle.Rotation, 60f);
            _currentHeadingOffset = 0.0f;
            _currentPitch = 0.0f;
        }

        float lookLR = Function.Call<float>(Hash.GET_CONTROL_NORMAL, 0, 2);
        float lookUD = Function.Call<float>(Hash.GET_CONTROL_NORMAL, 0, 3);

        _currentHeadingOffset -= lookLR * 4.0f;
        _currentPitch -= lookUD * 2.0f;
        _currentPitch = Math.Max(-80.0f, Math.Min(80.0f, _currentPitch));

        if (Math.Abs(lookLR) < 0.1f)
        {
            _currentHeadingOffset += (0.0f - _currentHeadingOffset) * 0.05f;
        }

        float finalHeading = vehicle.Heading + _currentHeadingOffset;
        float rad = (float)(finalHeading * Math.PI / 180.0f);
        
        Vector3 camPos = new Vector3(
            vehicle.Position.X - (float)Math.Sin(rad) * 3.5f,
            vehicle.Position.Y - (float)Math.Cos(rad) * 3.5f,
            vehicle.Position.Z + _heightOffset
        );

        _carCamera.Position = camPos;
        _carCamera.Rotation = new Vector3(_currentPitch, 0f, finalHeading);
        
        World.RenderingCamera = _carCamera;
        Function.Call(Hash.RENDER_SCRIPT_CAMS, true, false, 0, true, false);
    }

    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;
            UI.Notify("~g~Высота: " + _heightOffset.ToString("F2")); 
        }
        else if (e.KeyCode == Keys.NumPad3)
        {
            _heightOffset -= 0.05f;
            UI.Notify("~y~Высота: " + _heightOffset.ToString("F2")); 
        }
    }

    private void RemoveCamera()
    {
        if (_carCamera != null && _carCamera.Exists())
        {
            World.RenderingCamera = null;
            Function.Call(Hash.RENDER_SCRIPT_CAMS, false, false, 0, true, false);
            Function.Call(Hash.DESTROY_CAM, _carCamera.Handle, true); 
            _carCamera = null;
        }
    }
}