-- Function to get the front position of a vehicle
function GetFrontOfVehicle(vehicle, distance)
local position = GetEntityCoords(vehicle)
local forwardVector = GetEntityForwardVector(vehicle)
return vector3(position.x + (forwardVector.x * distance), position.y + (forwardVector.y * distance), position.z)
end
-- Function to make a ped walk to the front of a vehicle and play an animation
function PedWalkAndPlayAnimation(ped, vehicle, animationDictionary, animationName, animationSpeed)
local frontPosition = GetFrontOfVehicle(vehicle, 1.0) -- 1.0 is the distance from the front of the vehicle
TaskGoToCoordAnyMeans(ped, frontPosition.x, frontPosition.y, frontPosition.z, 1.0, false, true, 786603, 0xbf800000) -- 1.0 is the speed, 786603 is a hex flag for walking
-- Waiting for the ped to reach the destination
while not IsPedAtCoord(ped, frontPosition.x, frontPosition.y, frontPosition.z, 0.5, 0.5, 1.0, 0, 0) do
Citizen.Wait(100)
end
-- Loading animation dictionary
RequestAnimDict(animationDictionary)
while not HasAnimDictLoaded(animationDictionary) do
Citizen.Wait(100)
end
-- Playing the animation
TaskPlayAnim(ped, animationDictionary, animationName, animationSpeed, -1, -1, 50, 0, false, false, false)
RemoveAnimDict(animationDictionary)
end
-- Assuming you have a ped and a vehicle entity
local ped = ... -- Replace this with your ped entity
local vehicle = ... -- Replace this with your vehicle entity
-- Call the function with the ped, vehicle, and desired animation properties
PedWalkAndPlayAnimation(ped, vehicle, "anim@amb@clubhouse@tutorial@bkr_tut_ig3@", "machinic_loop_mechandplayer", 2.0) -- 2.0 is the animation speed
The function PedWalkAndPlayAnimation first calculates the front position of the vehicle and then makes the ped walk to that position. Once the ped has reached the destination, it will load and play the specified animation.