Skip to content

Fix destroyed vehicles not taking time of death into account - #1299

Open
DignitySAMP wants to merge 1 commit into
openmultiplayer:masterfrom
DignitySAMP:fix/vehicle-respawn-after-death
Open

DignitySAMP wants to merge 1 commit into
openmultiplayer:masterfrom
DignitySAMP:fix/vehicle-respawn-after-death

Conversation

@DignitySAMP

Copy link
Copy Markdown

Vehicle that get destroyed respawn right away instead of respecting game.vehicle_respawn_time. When nobody has been in a vehicle for longer than game.vehicle_respawn_time, OnVehicleSpawn gets called on the same tick as OnVehicleDeath.

This is the cause:

auto& deathData = vehicle->getDeathData();
if (deathData.time != TimePoint())
{
vehicle->setTimeOfDeath(TimePoint());
vehicle->setLastOccupiedTime(std::max(deathData.time, lastOccupied));

This is easily reproducable on a clean script:

public OnVehicleDeath(vehicleid, killerid)
{
    printf("death %d", GetTickCount());
    return 1;
}

public OnVehicleSpawn(vehicleid)
{
    printf("spawn %d", GetTickCount());
    return 1;
}

With this code above, drive a vehicle, get out, wait longer than game.vehicle_respawn_time and blow it up.

Expected: spawn 10 seconds after death
Actual: both on the same tick

deathData is a reference which setTimeOfDeath clears the same time that std::max is called (the immediate next line). So it never updated the last occupied time and instantly passed the respawn check right below it. This was changed at 661adf4 so this PR restores the original logic prior to that commit by reading the time of death into a local before it gets cleared.

With the fix death triggers at 5036 ms and spawn at 15032 ms after I set it on fire. Before it was 5035 ms for both. I also tested this with vehicles that die with the driver still inside and the normal respawn delay of vehicles that aren't destroyed, which were fine.

This PR now forces a wreck to always wait the full respawn time counted from the death. Previously it only took the timestamp of exiting the vehicle into account.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant