Issue with culling radius and server side entities

Client

Using canary? Yes
Windows version: 10.0.19042 Build 19042
System specifications:
Processor: i7-6700k
Video card: GTX 1070
Memory: 16GB

Server

Operating system: Same as client
Artifact version: FXServer-master SERVER v1.0.0.5562
IP address: local host
Resources:
System specifications:

Incident

Summary: When spawning a vehicle and a ped server side, in case there are more than 1 player in the server, the ped has strange behaviour
Expected behavior: The ped should spawn inside the vehicle, and start driving around
Actual behavior:

Steps to reproduce:

  1. Creating the entities (server side)
    local vehicle = CreateVehicle(
        cargoRobberyData.data.vehicleModel,
        startingCoords.x +.0, startingCoords.y+.0, startingCoords.z+.0,
        startingHeading+.0, true, true
    )

    if(not Utils.isServerEntityReady(vehicle)) then return end -- This will just wait until the entity exists
    SetEntityDistanceCullingRadius(vehicle, 30000.0) -- So this entity will be visible by all clients at any distance
    Citizen.Wait(2000)

    local ped = CreatePedInsideVehicle(vehicle, 0, cargoRobberyData.data.driverModel, -1, true, true)
        
    if(not Utils.isServerEntityReady(ped)) then return end -- This will just wait until the entity exists
    SetEntityDistanceCullingRadius(ped, 30000.0) -- So this entity will be visible by all clients at any distance
    Citizen.Wait(2000)
  1. Making the network owner to force the ped to drive

(server side anywhere)

    while isDrivingRandomly do
        TriggerClientEvent(Utils.eventsPrefix .. ":cargo:driveRandomly", NetworkGetEntityOwner(ped), pedNetId, vehicleNetId, cargoRobberyData.data.maxSpeed)

        Citizen.Wait(20000)
    end

(client side)

RegisterNetEvent(Utils.eventsPrefix .. ":cargo:driveRandomly", function(pedNetId, vehicleNetId, maxSpeed) 
    if(not NetworkDoesNetworkIdExist(pedNetId)) then return end
    if(not NetworkDoesNetworkIdExist(vehicleNetId)) then return end

    local ped = NetworkGetEntityFromNetworkId(pedNetId)
    local vehicle = NetworkGetEntityFromNetworkId(vehicleNetId)

    TaskVehicleDriveWander(ped, vehicle, maxSpeed + .0, 187)
    SetPedKeepTask(ped, true)
end)

Server/Client? Entities are created server side, the driving task is client side (done on the network owner of the ped)
Files for repro (if any):
Error screenshot (if any):
.dmp files/report IDs:

Any additional info:
When both vehicle and ped are owned by person A, and the person B doesn’t see the vehicle (when it’s distant from the vehicle spawn point) until the person A teleports in the current vehicle position as well

As I know, distance culling is not supported.

1 Like

Damn I didn’t know it, so I suppose there is no way to control driving NPC from anywhere distant in the map? Especially if there are more than 1 player, when the network owner can change

I thought it was supported because it was documented
immagine

and for a couple messages from @nta


This mismatch should not ever happen in the first place. However, the issue discovered with culling radius (and which wasn’t known at first) is that without the owning players being known to all remote players, ownership migration will still act up.

I’m not sure if there’s any viable fix for this, which is why current consensus is to not use overrides.

As said in another topic, to make a persistently wandering ped, you could ‘fake out’ some positions if nothing is nearby using raw path node data.

In fact it seemed very strange

This makes sense :+1:

Mmh, can be a good idea, I tried to get the nodes from coords X to coords Y (to fake a driver path in future), by using GetNthClosestVehicleNodeFavourDirection native, unfortunately without much success. I’m not sure if you were referring to this

This is the code I tried

Citizen.CreateThread(function() 
    local initialCoords = vector3(649.52, -250.88, 42.55) -- Random point on the highway
    local finalCoords = vector3(1268.44, 797.71, 104.50) -- Random point outside the highway

    local startBlip = AddBlipForCoord(initialCoords)
    SetBlipSprite(startBlip, 358)
    SetBlipColour(startBlip, 2) -- Green blip

    local endBlip = AddBlipForCoord(finalCoords)
    SetBlipSprite(endBlip, 358)
    SetBlipColour(endBlip, 1) -- Red blip

    local lastCoords = initialCoords

    -- This loop would be replaced with a different loop with a condition which checks if the last node found was enough close to the final coords
    for i=1, 50 do
        local found, coords, heading = GetNthClosestVehicleNodeFavourDirection(lastCoords.x, lastCoords.y, lastCoords.z, finalCoords.x, finalCoords.y, finalCoords.z, 3, 1, 0x40400000, 0)

        if(found) then
            local nextNodeBlip = AddBlipForCoord(coords)
            SetBlipScale(nextNodeBlip, 0.5)
            
            lastCoords = coords
        end
    end
end)

This is the result:

By the way thank you for your answer, I love working with server side logic with peds and tasks, but it’s a bit tricky :wink: