Jump to content

Camhack


Recommended Posts

sx,sy = guiGetScreenSize()

addEvent("CHack_V",true)
local rotX,rotY = 0,0
local mouseFrameDelay = 0
PI = math.pi
lplayer = getLocalPlayer()
local ayudatxt = [[Bienvenido al modo de Version Libre!

Usa los botones de tu teclado numerico
y tu Mouse para mover la camara!

PARA SALIR USA LA TECLA ENTER]]

local cHOpciones = {
	sen = 0.01,
	vel = 2
}

local camHack
function CamhackOn()
	if camHack then
		camHack = false
		setElementData(lplayer,"camHack",false)
		setElementData(lplayer,"Ocupado",false)
		--setPlayerHudComponentVisible("all",true)
		showChat(true)
		toggleAllControls(true, true, false)
		removeEventHandler("onClientCursorMove",root,moverMouse)
		removeEventHandler("onClientPreRender",root,moverCamara)
		setCameraTarget(lplayer)
		unbindKey("h","down",mostrarGUICam)
		unbindKey("enter","down",salirCam)
		destroyElement(camHackGUI)
		if controlsEnableGM or controlsEnableAlpha then
			toggleControl ( "fire", false)
		end
	else
		setElementData(lplayer,"camHack",true)
		setElementData(lplayer,"Ocupado",true)
		camHack = true
		setPlayerHudComponentVisible("all",false)
		showChat(false)
		toggleAllControls(false, true, false)
		
		local x,y,z,lx,ly,lz = getCameraMatrix()
		setCameraMatrix(x,y,z,lx,ly,lz)
		addEventHandler("onClientCursorMove",root,moverMouse)
		addEventHandler("onClientPreRender",root,moverCamara)
		
		aviso("Vista Libre\nPuedes ver la ayuda y opciones con la tecla 'H'")
		cargarGUICam()
		bindKey("enter","down",salirCam)
	end
	verificarCheckPanel()
end
addEventHandler("CHack_V",root,CamhackOn)

function salirCam()
	CamhackOn()
end

function moverMouse(_,_,aX,aY)
	if isCursorShowing() or isMTAWindowActive() then
		mouseFrameDelay = 5
		return
	elseif mouseFrameDelay > 0 then
		mouseFrameDelay = mouseFrameDelay - 1
		return
	end
	
    local width, height = guiGetScreenSize()
    aX = aX - width / 2 
    aY = aY - height / 2
	
	rotX = rotX + aX * cHOpciones.sen
    rotY = rotY - aY * cHOpciones.sen
	
	if rotX > PI then
		rotX = rotX - 2 * PI
	elseif rotX < -PI then
		rotX = rotX + 2 * PI
	end
	if rotY > PI/2 then
		rotY = PI/2-0.001
	elseif rotY < -PI/2 then
		rotY = -PI/2+0.001
	end
end

function moverCamara()
	local x,y,z,lx,ly,lz = getCameraMatrix()
	
	local angZ = math.sin(rotY)
    local angY = math.cos(rotY) * math.cos(rotX)
    local angX = math.cos(rotY) * math.sin(rotX)
	
	local speed = 0
	local speedr = 0
	if getKeyState("w") then
		speed = cHOpciones.vel
	elseif getKeyState("s") then
		speed = -cHOpciones.vel
	end
	if getKeyState("a") then
		speedr = cHOpciones.vel
	elseif getKeyState("d") then
		speedr = -cHOpciones.vel
	end
	if getKeyState("q") then
		z = z - cHOpciones.vel
	elseif getKeyState("e") then
		z = z + cHOpciones.vel
	end
	
	local DisX = x - lx
    local DisY = y - ly
	
	local angleLength = math.sqrt(DisX^2+DisY^2)
	
	lx = x + angX * 100
	ly = y + angY * 100
    lz = z + angZ * 100
	
	x = x + angX * speed
    y = y + angY * speed
    z = z + angZ * speed
	
	x = x + (DisY / angleLength) * speedr
    y = y + -(DisX / angleLength) * speedr
	
	setCameraMatrix(x,y,z,lx,ly,lz)
end

local color = 255
local adtxt = ""
local timer
function cargaraviso()
	if color > 0 then
		color = color - 5
	end
	dxDrawRectangle(0,sy/2-30,sx,60,tocolor(0,color,color,200),false)
	dxDrawText(adtxt,0,sy/2-30,sx,60,tocolor(0,255,0,255),2,"default","center")
end

function aviso(texto)
	color = 200
	adtxt = texto
	if not timer then
		addEventHandler("onClientRender",root,cargaraviso)
		timer = setTimer(function()
			removeEventHandler("onClientRender",root,cargaraviso)
			timer = nil
		end,3000,1)
	else
		killTimer(timer)
		timer = setTimer(function()
			removeEventHandler("onClientRender",root,cargaraviso)
			timer = nil
		end,3000,1)
	end
end

function cargarGUICam()
	camHackGUI = guiCreateWindow(sx/2-204,sy/2-121,409,242,"Opciones de Vista Libre",false)
	guiSetVisible(camHackGUI,false)
	local tabCamHack = guiCreateTabPanel(11,21,389,212,false,camHackGUI)
	
	local tCamAyuda = guiCreateTab("Ayuda",tabCamHack)
	guiCreateMemo(3,6,378,179,ayudatxt,false,tCamAyuda)
	
	local tCamOpciones = guiCreateTab("Opciones",tabCamHack)
	guiCreateLabel(13,12,66,17,"Velocidad:",false,tCamOpciones)
	addEventHandler("onClientGUIChanged",guiCreateEdit(84,10,118,22,tostring(cHOpciones.vel),false,tCamOpciones),function()
		local txt = guiGetText(source)
		if not tonumber(txt) then
			local point
			txt = txt:gsub(".",function(x)
				if x=="." and not point then
					point = true
				elseif not tonumber(x) then
					return ""
				end
			end)
			if txt == guiGetText(source) then return end
			guiSetText(source,txt)
		end
		cHOpciones.vel = txt
	end,false)
	
	guiCreateLabel(13,40,66,17,"Sensibilidad:",false,tCamOpciones)
	addEventHandler("onClientGUIChanged",guiCreateEdit(84,38,118,22,tostring(cHOpciones.sen),false,tCamOpciones),function()
		local txt = guiGetText(source)
		if not tonumber(txt) then
			local point
			txt = txt:gsub(".",function(x)
				if x=="." and not point then
					point = true
				elseif not tonumber(x) then
					return ""
				end
			end)
			if txt == guiGetText(source) then return end
			guiSetText(source,txt)
		end
		cHOpciones.sen = txt
	end,false)
	
	bindKey("h","down",mostrarGUICam)
end

function mostrarGUICam()
	if guiGetVisible(camHackGUI) then
		guiSetVisible(camHackGUI,false)
		showCursor(false,false)
	else
		guiSetVisible(camHackGUI,true)
		showCursor(true)
	end
end

 

  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...