-- Define the script name and author
script_name("CamHack")
script_author("sanek a.k.a Maks_Fender, edited by ANIKI")

require "lib.moonloader"
local mad = require "MoonAdditions"

-- Create a table to encapsulate all variables and functions
local camHack = {
    -- Define virtual key codes with descriptive names
    KEY_TOGGLE_FLY_MODE    = 0x43,  -- VK_C (Toggle fly mode)
    KEY_ENABLE_FLY_MODE    = 0x31,  -- VK_1 (Enable fly mode)
    KEY_DISABLE_FLY_MODE   = 0x32,  -- VK_2 (Disable fly mode)
    KEY_MOVE_FORWARD       = 0x57,  -- VK_W (Move forward)
    KEY_MOVE_BACKWARD      = 0x53,  -- VK_S (Move backward)
    KEY_STRAFE_LEFT        = 0x41,  -- VK_A (Strafe left)
    KEY_STRAFE_RIGHT       = 0x44,  -- VK_D (Strafe right)
    KEY_MOVE_UP            = 0x20,  -- VK_SPACE (Move up)
    KEY_MOVE_DOWN          = 0x10,  -- VK_SHIFT (Move down)
    KEY_INCREASE_SPEED     = 0xBB,  -- VK_ADD (Increase speed)
    KEY_DECREASE_SPEED     = 0xBD,  -- VK_SUBTRACT (Decrease speed)

    -- Define camera hack variables
    camHack_posX = 0,
    camHack_posY = 0,
    camHack_posZ = 0,
    camHack_angZ = 0,
    camHack_angY = 0,
    camHack_speed = 1.0,
    camHack_flyModeActive = false,
    camHack_collisionEnabled = true,

    camHack_checkSolidObjects = true,
    camHack_checkVehicles = false,
    camHack_checkPeds = false,
    camHack_checkObjects = true,
    camHack_checkParticles = false,
    camHack_seeThroughObjects = false,
    camHack_ignoreSomeObjects = false,
    camHack_allowShootThrough = false
}

function camHack.enableFlyMode()
    displayRadar(false)
    displayHud(false)
    camHack.camHack_posX, camHack.camHack_posY, camHack.camHack_posZ = getCharCoordinates(playerPed)
    camHack.camHack_angZ = -getCharHeading(playerPed)
    camHack.camHack_angY = 0.0
    setFixedCameraPosition(camHack.camHack_posX, camHack.camHack_posY, camHack.camHack_posZ, 0.0, 0.0, 0.0)
    lockPlayerControl(true)
    camHack.camHack_flyModeActive = true
end

function camHack.disableFlyMode()
    lockPlayerControl(false)
    restoreCameraJumpcut()
    setCameraBehindPlayer()
    displayRadar(true)
    displayHud(true)
    camHack.camHack_flyModeActive = false
end

function camHack.processCamHack()
    if not camHack.camHack_flyModeActive then
        if isKeyDown(camHack.KEY_TOGGLE_FLY_MODE) and isKeyDown(camHack.KEY_ENABLE_FLY_MODE) then
            camHack.enableFlyMode()
        end
    else
        if not sampIsChatInputActive() and not isSampfuncsConsoleActive() then
            local offMouX, offMouY = getPcMouseMovement()
            camHack.camHack_angZ = (camHack.camHack_angZ + offMouX / 4.0) % 360
            camHack.camHack_angY = math.max(math.min(camHack.camHack_angY + offMouY / 4.0, 89.0), -89.0)

            local radZ, radY = math.rad(camHack.camHack_angZ), math.rad(camHack.camHack_angY)
            local sinZ, cosZ, sinY, cosY = math.sin(radZ), math.cos(radZ), math.sin(radY), math.cos(radY)
            local movX, movY, movZ = cosY * sinZ, cosY * cosZ, sinY
            local newX, newY, newZ = camHack.camHack_posX, camHack.camHack_posY, camHack.camHack_posZ

            if isKeyDown(camHack.KEY_MOVE_FORWARD) then
                newX = camHack.camHack_posX + movX * camHack.camHack_speed
                newY = camHack.camHack_posY + movY * camHack.camHack_speed
                newZ = camHack.camHack_posZ + movZ * camHack.camHack_speed
            elseif isKeyDown(camHack.KEY_MOVE_BACKWARD) then
                newX = camHack.camHack_posX - movX * camHack.camHack_speed
                newY = camHack.camHack_posY - movY * camHack.camHack_speed
                newZ = camHack.camHack_posZ - movZ * camHack.camHack_speed
            end

            if isKeyDown(camHack.KEY_STRAFE_LEFT) or isKeyDown(camHack.KEY_STRAFE_RIGHT) then
                local sideOffset = isKeyDown(camHack.KEY_STRAFE_LEFT) and -math.pi / 2 or math.pi / 2
                local sideZ = math.sin(math.rad(camHack.camHack_angZ) + sideOffset)
                local sideX = math.cos(math.rad(camHack.camHack_angZ) + sideOffset)
                newX = newX + sideZ * camHack.camHack_speed
                newY = newY + sideX * camHack.camHack_speed
            end

            if isKeyDown(camHack.KEY_MOVE_UP) then
                newZ = camHack.camHack_posZ + camHack.camHack_speed
            elseif isKeyDown(camHack.KEY_MOVE_DOWN) then
                newZ = camHack.camHack_posZ - camHack.camHack_speed
            end

            local collision, colPoint, adjX, adjY, adjZ
            if camHack.camHack_collisionEnabled then
                local result
                result, colPoint = processLineOfSight(
                    camHack.camHack_posX, camHack.camHack_posY, camHack.camHack_posZ, newX, newY, newZ,
                    camHack.camHack_checkSolidObjects, camHack.camHack_checkVehicles, camHack.camHack_checkPeds,
                    camHack.camHack_checkObjects, camHack.camHack_checkParticles, camHack.camHack_seeThroughObjects,
                    camHack.camHack_ignoreSomeObjects, camHack.camHack_allowShootThrough
                )
                if result then
                    collision, adjX, adjY, adjZ = true, camHack.camHack_posX, camHack.camHack_posY, camHack.camHack_posZ
                else
                    collision, adjX, adjY, adjZ = false, newX, newY, newZ
                end
            else
                collision, adjX, adjY, adjZ = false, newX, newY, newZ
            end

            camHack.camHack_posX, camHack.camHack_posY, camHack.camHack_posZ = adjX, adjY, adjZ
            setFixedCameraPosition(camHack.camHack_posX, camHack.camHack_posY, camHack.camHack_posZ, 0.0, 0.0, 0.0)
            pointCameraAtPoint(camHack.camHack_posX + movX, camHack.camHack_posY + movY, camHack.camHack_posZ + movZ, 2)

            if isKeyDown(camHack.KEY_INCREASE_SPEED) then
                camHack.camHack_speed = camHack.camHack_speed + 0.01
            elseif isKeyDown(camHack.KEY_DECREASE_SPEED) then
                camHack.camHack_speed = math.max(camHack.camHack_speed - 0.01, 0.01)
            end

            local collisionText
            if collision then
                collisionText = string.format(
                    "~ghhh~Collision Detected~n~" ..
                    "~w~Entity: ~ph~%d~n~" ..
                    "~w~Type: ~ph~%d~ph~ ~w~Surface: ~ph~%d~n~" ..
                    "~w~Position: ~ph~(%.2f, %.2f, %.2f)~n~" ..
                    "~w~Normal: ~ph~(%.2f, %.2f, %.2f)",
                    colPoint.entity, colPoint.entityType, colPoint.surfaceType[1],
                    colPoint.pos[1], colPoint.pos[2], colPoint.pos[3],
                    colPoint.normal[1], colPoint.normal[2], colPoint.normal[3]
                )
            else
                collisionText = "~rhhh~No Collision"
            end

            if not camHack.camHack_collisionEnabled then
                collisionText = "~yh~Collision Disabled"
            end

            local text = string.format(
                "~bhhh~CamHack Debug Info~n~" ..
                "~w~Position:~n~" ..
                " ~ph~(%.2f, %.2f, %.2f)~n~" ..
                "~w~Direction:~n~" ..
                " ~ph~(%.2f, %.2f, %.2f)~n~" ..
                "~w~Angle:~n~" ..
                " ~ph~Z: %.2f| ~ph~Y: %.2f|~n~" ..
                "~w~Speed:~n~" ..
                " ~p~~h~%.2f units/sec~n~" ..
                "~w~Collision Status:~n~" ..
                " %s",
                camHack.camHack_posX, camHack.camHack_posY, camHack.camHack_posZ,
                camHack.camHack_posX + movX, camHack.camHack_posY + movY, camHack.camHack_posZ + movZ,
                camHack.camHack_angZ, camHack.camHack_angY, camHack.camHack_speed,
                collisionText
            )

            mad.draw_text(text, 45, 240, mad.font_style.BEFORE_TEXT, 0.40, 1.0, mad.font_align.LEFT, 9999, true, false, 255, 255, 255, 255, 1, 2, 0, 0, 0, 150)

            if isKeyDown(camHack.KEY_TOGGLE_FLY_MODE) and isKeyDown(camHack.KEY_DISABLE_FLY_MODE) then
                camHack.disableFlyMode()
            end
        end
    end
end

return camHack

перепиши код так, чтобы хоткеи только меняли значение переменной, а в processCamHack уже происходила бы проверка этой переменной и исходя из ее значения - вызов функция включения и выключения