script_name("CamHack")
script_author("sanek a.k.a Maks_Fender, edited by ANIKI")
require "lib.moonloader"
local mad = require "MoonAdditions"

local flyModeActive, speed, radarHud, keyPressed = 0, 1.0, 0, 0
local posX, posY, posZ, angZ, angY = 0, 0, 0, 0, 0

function main()
	while true do
		wait(0)
		
		if flyModeActive == 0 then
			checkFlyModeActivation()
		else
			handleFlyMode()
		end
	end
end

function checkFlyModeActivation()
	if isKeyDown(VK_C) and isKeyDown(VK_1) then
		enterFlyMode()
	end
end

function enterFlyMode()
	displayRadar(false)
	displayHud(false)
	posX, posY, posZ = getCharCoordinates(playerPed)
	angZ = -getCharHeading(playerPed)  -- Inverted for correct orientation
	angY = 0.0
	setFixedCameraPosition(posX, posY, posZ, 0.0, 0.0, 0.0)
	lockPlayerControl(true)
	flyModeActive = 1
end

function handleFlyMode()
	if not sampIsChatInputActive() and not isSampfuncsConsoleActive() then
		adjustCameraAngles()
		moveCamera()
		drawDebugText()
		toggleRadarAndHud()
		adjustSpeed()
		checkFlyModeExit()
	end
end

function adjustCameraAngles()
	local offMouX, offMouY = getPcMouseMovement()
	angZ = (angZ + offMouX / 4.0) % 360
	angY = math.max(math.min(angY + offMouY / 4.0, 89.0), -89.0)
end

function moveCamera()
	local movX, movY, movZ = calculateMovementVectors()
	
	if isKeyDown(VK_W) then
		movePosition(movX, movY, movZ)
	elseif isKeyDown(VK_S) then
		movePosition(-movX, -movY, -movZ)
	end

	if isKeyDown(VK_A) or isKeyDown(VK_D) then
		sideMove(isKeyDown(VK_A) and -math.pi / 2 or math.pi / 2)
	end

	if isKeyDown(VK_SPACE) then
		posZ = posZ + speed
	elseif isKeyDown(VK_SHIFT) then
		posZ = posZ - speed
	end
	
	updateCamera()
end

function calculateMovementVectors()
	local radZ, radY = math.rad(angZ), math.rad(angY)
	local sinZ, cosZ, sinY, cosY = math.sin(radZ), math.cos(radZ), math.sin(radY), math.cos(radY)
	return cosY * sinZ, cosY * cosZ, sinY
end

function movePosition(movX, movY, movZ)
	posX = posX + movX * speed
	posY = posY + movY * speed
	posZ = posZ + movZ * speed
end

function sideMove(angleOffset)
	local sideZ = math.sin(math.rad(angZ) + angleOffset)
	local sideX = math.cos(math.rad(angZ) + angleOffset)
	posX = posX + sideZ * speed
	posY = posY + sideX * speed
end

function updateCamera()
	setFixedCameraPosition(posX, posY, posZ, 0.0, 0.0, 0.0)
	local movX, movY, movZ = calculateMovementVectors()
	pointCameraAtPoint(posX + movX, posY + movY, posZ + movZ, 2)
end

function toggleRadarAndHud()
	if keyPressed == 0 and isKeyDown(VK_F10) then
		keyPressed = 1
		radarHud = 1 - radarHud
		displayRadar(radarHud == 1)
		displayHud(radarHud == 1)
	end
	if wasKeyReleased(VK_F10) and keyPressed == 1 then keyPressed = 0 end
end

function adjustSpeed()
	if isKeyDown(187) then
		speed = speed + 0.01
	elseif isKeyDown(189) then
		speed = math.max(speed - 0.01, 0.01)
	end
	printStringNow(string.format("Speed: %.2f", speed), 1000)
end

function checkFlyModeExit()
	if isKeyDown(VK_C) and isKeyDown(VK_2) then
		exitFlyMode()
	end
end

function exitFlyMode()
	displayRadar(true)
	displayHud(true)
	lockPlayerControl(false)
	restoreCameraJumpcut()
	setCameraBehindPlayer()
	flyModeActive = 0
	radarHud = 0
end

function drawDebugText()
	local movX, movY, movZ = calculateMovementVectors()
	local text = string.format(
		"~p~~h~CamHack Debug Info :3~n~" ..
		"~p~~h~~h~Position:~n~" ..
		" X: ~p~~h~%.2f ~p~~h~~h~ Y: ~p~~h~%.2f ~p~~h~~h~ Z: ~p~~h~%.2f~n~" ..
		"~p~~h~~h~Direction:~n~" ..
		" X: ~p~~h~%.2f ~p~~h~~h~ Y: ~p~~h~%.2f ~p~~h~~h~ Z: ~p~~h~%.2f~n~" ..
		"~p~~h~~h~Angles:~n~" ..
		" Z: ~p~~h~%.2f ~p~~h~~h~degrees~n~" ..
		" Y: ~p~~h~%.2f ~p~~h~~h~degrees~n~" ..
		"~p~~h~~h~Speed:~n~" ..
		" Current: ~p~~h~%.2f ~p~~h~~h~units/sec~n~",
		posX, posY, posZ,
		posX + movX, posY + movY, posZ + movZ,
		angZ, angY, speed
	)
	mad.draw_text(text, 45, 240, mad.font_style.BEFORE_TEXT, 0.48, 1.12, mad.font_align.LEFT, 9999, true, false, 
	              255, 255, 255, 255, 1, 2, 0, 0, 0, 150)
end

local sampev = require "lib.samp.events"

function sampev.onPlayerChatBubble(id, col, dist, dur, msg)
	if flyModeActive == 1 then return {id, col, 1488, dur, msg} end
end

откомментируй этот код согласно женевским конвенциям