Sign in to follow this  
231

Auto aim to command

Recommended Posts

local x, y, z = getElementPosition(getLocalPlayer())

local dx, dy = guiGetScreenSize()
aimX, aimY = dx * 0.54, dy * 0.3971

triggerServerEvent("AimOnPosition", resourceRoot)
function AimOnPosition()
    local setToX, setToY = 0, 0
    local hx, hy, hz = getPedBonePosition(Ped, 6)
    local sx, sy = getScreenFromWorldPosition(hx, hy, hz)

    setToX = math.abs(dx / 2 - (aimX))
    setToY = math.abs(dy / 2 - aimY)

    local a1, a2, a3 = getPedBonePosition(Ped, 6)
    local a4, a5, a6 = getElementPosition(Ped)
    local b1, b2, b3 = getElementPosition(localPlayer)
    local dist = getDistanceBetweenPoints3D(a1, a2, a3, b1, b2, b3)

    -- here

    if isRifle then
        aimX = dx * 0.54 + (10 - dist * 0.2) -- maybe you will need to play around with 10 or *0.2 to get the right result.
    else
        aimX = dx * 0.54
    end

    setToX, setToY = getWorldFromScreenPosition(sx - setToX, sy + setToY, dist)
    _, _, setToX1 = getWorldFromScreenPosition(dx / 2, dy / 2, dist)
    _, _, setToX2 = getWorldFromScreenPosition(aimX, aimY, dist)
    setToX3 = (setToX2 - setToX1)
    setCameraTarget(setToX, setToY, b3 - setToX3 + 0.2 + (a6 - b3))
end

function drawStuff()
    if getControlState("aim_weapon") then
        AimOnPosition()
    end
end
addEventHandler("onClientRender", root, drawStuff)
I want this to be a command for players on my server, help me

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.