Fix ped cars stopping in middle of road when you're the only car?

Okay… I think we can all agree this is ridiculous… and hilarious… :rofl: however… for a realistic experience, this should not happen where you’re the only car and they all stop and honk at you like you’re the problem… :face_with_raised_eyebrow:

Developers who might have a little more knowledge on the subject then me, any idea how you would go about… well, making the peds a little less stupid? lol! I think we can agree this would be a great resource to have in any server!

Cheers!

  • Dan
1 Like

The way I would do it is with the entityCreated event. Basically, you check every f*cking ped, see if they are drivers (but not players), and modify their behavior using SetDriveTaskDrivingStyle - FiveM Natives @ Cfx.re Docs (although I’m not sure if this will change the ped’s existing driving task).

1 Like

Actually, doubling down on this because I kinda want to do it too. So I made this driving style:
1000000101110111111 - 265151

I tries to respect all driving rules, while also avoiding everthing in it’s way. If there is an obstacle on the road, it likes to break a bit, before avoiding it. It likes to switch lanes if it can, but that’s not always needed.

From my testing, it tends to be… a bit based. It will avoid obstacles, but sometimes that means hitting other obstacles.

Here’s how I did it:

server-side:

--lua
AddEventHandler('entityCreated', function(handle)
    if DoesEntityExist(handle) and GetEntityType(handle) == 1 then --entity is a ped
        local ped = handle
        Citizen.Wait(100) --arbritary wait for ped to receive an owner
        if DoesEntityExist(ped) then --if they don't exist anymore, we don't care
            local owner = NetworkGetEntityOwner(ped)
            if owner ~= nil and owner > 0 then --if they don't have a player owner, we don't care.
                TriggerClientEvent('handle.ChangeTrafficStyle', owner, NetworkGetNetworkIdFromEntity(ped))
            end
        end
    end
end)

client-side:

--lua
RegisterNetEvent('handle.ChangeTrafficStyle', function(netID)
    local ped = NetToPed(netID) --we need to wait for the ped to be recognized on the client
    while not DoesEntityExist(NetToPed(netID)) do
        Citizen.Wait(100) --usually this is 0, but I hate the console warnings. Might need a way to escape this if the ped never spawns.
    end
    ped = NetToPed(netID)
    if IsPedInAnyVehicle(ped, false) then --if it's in a vehicle. Passangers tend to be rare, so I don't really check for them.
        SetDriveTaskDrivingStyle(ped, 265151)
    end
end)

example:

(gyazo mirror) Screen capture - 8e849651322db15ea756873aea43d8d3 - Gyazo

3 Likes

Absolutely amazing job!! This is JUST what we were all looking for!
I’m sure it’s trial and error to get it perfect, but this is a great starting point.

Cheers!

  • Dan
1 Like

Few fender benders in the process, but you can use Driving Style Calculator - GTA V to figure out the “driving style”.

Seems to work for the most part, but the mechanics of the game will limit the ped activity if you have too many cars driving.

and as seen from driving against traffic, they will swerve to avoid you, but still pile up behind you. most cars will swerve to a new lane, but that isn’t the case 40% of the time. need to find that sweet spot.


as you see one car decided to swerve into the other lane to get to its destination quicker, but traffic is still backed up.

Currently using #: 554172860

if anyone has a better numeric code for ```
SetDriveTaskDrivingStyle(ped, (#######) all ears! Otherwise good luck!

Cheers!

  • Dan
2 Likes