Checking if ped already has task?

Hey there folks,

I’m in the process of having peds go to specific locations based off criteria, however because this “go to coords” function is being called every second, it seems to cause the ped to stop and jitter while heading to the location, rather than simply walking along smoothly.

Is there any particular way i might check if the ped already has a certain task, or check if they’ve already been programmed to head to a specific location?

I’m sure there’s workarounds like “well if the distance to the waypoint is getting less, so they MUST be walking there”, but that seems far too messy.

So I searched it up and found some natives that may work, keep in mind I didn’t test these but they might work.

GetIsTaskActive() > https://runtime.fivem.net/doc/natives/#_0xB0760331C7AA4155
GetScriptTaskStatus() > https://runtime.fivem.net/doc/natives/#_0x77F1BEB8863288D5

If the only thing you want to do is making the ped walk to a certain coord (with no other tasks) you could just make a boolean like for example:

local IsGoing = false

Citizen.CreateThread(function()
     while true do
         Citizen.Wait(7)
         if not IsGoing then
               TaskGoStraightToCoord() -- change ur stuff here
               IsGoing = true
               -- may use a return as well if you want to break the loop
         end
     end
end)
1 Like