помести все переменные и функцию в этом коде в одну таблицу, которую будет в конце возвращать скрипт



-- 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"

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

-- Define camera hack variables
local camHack_posX, camHack_posY, camHack_posZ = 0, 0, 0  -- Camera position coordinates
local camHack_angZ, camHack_angY	= 0, 0  -- Camera angle in Z and Y directions
local camHack_speed					= 1.0  -- Movement speed of the camera
local camHack_flyModeActive 		= 0  -- State of fly mode: 0 = inactive, 1 = active
local camHack_collisionEnabled		= true  -- Flag for collision detection

-- Flags for different types of collision checks
local camHack_checkSolidObjects 	= true
local camHack_checkVehicles			= false
local camHack_checkPeds				= false
local camHack_checkObjects			= true
local camHack_checkParticles		= false
local camHack_seeThroughObjects 	= false
local camHack_ignoreSomeObjects 	= false
local camHack_allowShootThrough 	= false


function processCamHack()
	wait(0)  -- Wait for a short time before continuing

	-- Activate fly mode if conditions are met
	if camHack_flyModeActive == 0 then
		if isKeyDown(KEY_TOGGLE_FLY_MODE) and isKeyDown(KEY_ENABLE_FLY_MODE) then
			displayRadar(false)  -- Hide the radar
			displayHud(false)  -- Hide the HUD
			camHack_posX, camHack_posY, camHack_posZ = getCharCoordinates(playerPed)  -- Get player position
			camHack_angZ = -getCharHeading(playerPed)  -- Set camera heading
			camHack_angY = 0.0  -- Reset vertical angle
			setFixedCameraPosition(camHack_posX, camHack_posY, camHack_posZ, 0.0, 0.0, 0.0)  -- Fix camera position
			lockPlayerControl(true)  -- Lock player controls
			camHack_flyModeActive = 1  -- Set fly mode to active
		end
	else
		-- Check for input and update camera position if fly mode is active
		if not sampIsChatInputActive() and not isSampfuncsConsoleActive() then
			local offMouX, offMouY = getPcMouseMovement()  -- Get mouse movement
			camHack_angZ = (camHack_angZ + offMouX / 4.0) % 360  -- Update camera Z angle
			camHack_angY = math.max(math.min(camHack_angY + offMouY / 4.0, 89.0), -89.0)  -- Update camera Y angle

			-- Calculate movement direction based on camera angles
			local radZ, radY = math.rad(camHack_angZ), math.rad(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_posX, camHack_posY, camHack_posZ

			-- Handle forward and backward movement
			if isKeyDown(KEY_MOVE_FORWARD) then
				newX = camHack_posX + movX * camHack_speed
				newY = camHack_posY + movY * camHack_speed
				newZ = camHack_posZ + movZ * camHack_speed
			elseif isKeyDown(KEY_MOVE_BACKWARD) then
				newX = camHack_posX - movX * camHack_speed
				newY = camHack_posY - movY * camHack_speed
				newZ = camHack_posZ - movZ * camHack_speed
			end

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

			-- Handle vertical movement (up and down)
			if isKeyDown(KEY_MOVE_UP) then
				newZ = camHack_posZ + camHack_speed
			elseif isKeyDown(KEY_MOVE_DOWN) then
				newZ = camHack_posZ - camHack_speed
			end

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

			-- Update camera position and set new fixed camera position
			camHack_posX, camHack_posY, camHack_posZ = adjX, adjY, adjZ
			setFixedCameraPosition(camHack_posX, camHack_posY, camHack_posZ, 0.0, 0.0, 0.0)
			pointCameraAtPoint(camHack_posX + movX, camHack_posY + movY, camHack_posZ + movZ, 2)

			-- Adjust camera speed with keys
			if isKeyDown(KEY_INCREASE_SPEED) then
				camHack_speed = camHack_speed + 0.01
			elseif isKeyDown(KEY_DECREASE_SPEED) then
				camHack_speed = math.max(camHack_speed - 0.01, 0.01)
			end

			-- Display collision and debug information
			local collisionText
			if collision then
				collisionText = string.format(
					"~g~~h~~h~~h~Collision Detected~n~" ..
					"~w~Entity: ~p~~h~%d~n~" ..
					"~w~Type: ~p~~h~%d~p~~h~ ~w~Surface: ~p~~h~%d~n~" ..
					"~w~Position: ~p~~h~(%.2f, %.2f, %.2f)~n~" ..
					"~w~Normal: ~p~~h~(%.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 = "~r~~h~~h~~h~No Collision"
			end

			if not camHack_collisionEnabled then
				collisionText = "~y~~h~Collision Disabled"
			end

			-- Format and display debug information on screen
			local text = string.format(
				"~b~~h~~h~~h~CamHack Debug Info~n~" ..
				"~w~Position:~n~" ..
				" ~p~~h~(%.2f, %.2f, %.2f)~n~" ..
				"~w~Direction:~n~" ..
				" ~p~~h~(%.2f, %.2f, %.2f)~n~" ..
				"~w~Angle:~n~" ..
				" ~p~~h~Z: %.2f| ~p~~h~Y: %.2f|~n~" ..
				"~w~Speed:~n~" ..
				" ~p~~h~%.2f units/sec~n~" ..
				"~w~Collision Status:~n~" ..
				" %s",
				camHack_posX, camHack_posY, camHack_posZ,
				camHack_posX + movX, camHack_posY + movY, camHack_posZ + movZ,
				camHack_angZ, camHack_angY, 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)

			-- Deactivate fly mode and restore player controls if conditions are met
			if isKeyDown(KEY_TOGGLE_FLY_MODE) and isKeyDown(KEY_DISABLE_FLY_MODE) then
				lockPlayerControl(false)  -- Unlock player controls
				restoreCameraJumpcut()  -- Restore default camera behavior
				setCameraBehindPlayer()  -- Set camera behind player
				camHack_flyModeActive = 0  -- Set fly mode to inactive
			end
		end
	end
end