Jump to content

Ped Chasing


Doffy

Recommended Posts

  • Moderators

Maybe try something like that:

-- CLIENT SIDE

addEventHandler("onClientPedDamage", getRootElement(), function(attacker)
    if attacker == localPlayer then
        triggerServerEvent("startFollow", localPlayer, source, localPlayer)
    end
end)
-- SERVER SIDE

local ped = createPed(0, 0, 0, 3)

function startFollow(pedElement, playerElement)
    if isElement(pedElement) then
        setPedAnimation(pedElement, "muscular", "musclerun")
		
        setTimer(function()
            local x1, y1 = getElementPosition(playerElement)
            local x2, y2 = getElementPosition(pedElement)
            local rot = findRotation( x2, y2, x1, y1 )
            setPedRotation(pedElement, rot)
        end, 250, 0)
    end
end
addEvent("startFollow", true)
addEventHandler("startFollow", root, startFollow)

function findRotation( x1, y1, x2, y2 ) 
    local t = -math.deg( math.atan2( x2 - x1, y2 - y1 ) )
    return t < 0 and t + 360 or t
end

 

  • Thanks 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...