Skip to content

Vehicles Persisting After Server-Side Deletion #2256

Description

@Tynopia

Problem

I'm facing an issue in FiveM related to the Entity Owner and the deletion of entities. Even though I clearly remove vehicles on the server-side and the DoesEntityExist function reports that they no longer exist, these vehicles persist and do not get deleted. The vehicles are spawned in a different routing bucket (where the entity lockdown is set to "inactive").

Server-Side Script

Here is my server-side script in TypeScript, which sets the routing bucket and removes previous vehicles:

onNet("tynopia:garage:server:enter", async (floor: number = 1) => {
    const source = global.source;
    const sourceString = source.toString();
    
    // ...

    if (playerPedId) {
        const bucket = routingBucket + source;

        for (const vehicle of GetAllVehicles()) {
            let count = 0

            if (GetEntityRoutingBucket(vehicle) === bucket) {
                do {
                    DeleteEntity(vehicle);
                    await Delay(50);
                    console.log("Try Delete: " + count++)
                } while (DoesEntityExist(vehicle))
            }
        }

        // ...

        SetPlayerRoutingBucket(sourceString, bucket);
        SetRoutingBucketPopulationEnabled(bucket, false);
        SetRoutingBucketEntityLockdownMode(bucket, "inactive");

        // ...
    }
})
export function exitGarage(source: string, playerPedId?: number, coords?: Vector3): void {
    SetPlayerRoutingBucket(source, 0);
    // ...
}

Client-Side Code

This is my client-side code where I create the vehicle:

// ...
await requestModel(model);
const entity = CreateVehicle(model, coords[0], coords[1], coords[2], coords[3], true, true);
await delayEntityExist(entity);
SetModelAsNoLongerNeeded(model);
// ...
export async function requestModel(model: number | string) {
    RequestModel(model)

    while (!HasModelLoaded(model)) {
        await Delay(50);
    }
}
export async function delayEntityExist(entity: number): Promise<void> {
    while (!DoesEntityExist(entity)) {
        await Delay(50);
    }
}

Issue Video

2023-10-29.02-53-12.mp4
2023-10-29.02-54-15.mp4
2023-10-29.11-22-28.mp4
Unbenannt.mp4

Expected Behavior

When I delete vehicles on the server-side, they should be removed entirely, and there should be no old vehicles persisting when new vehicles are spawned in a different routing bucket.

Actual Behavior

Old vehicles persist and do not get deleted even when the server-side logic indicates that they have been removed and DoesEntityExist reports that they no longer exist.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions