Page 1 of 1

[1.1.59] on_player_driving_changed_state no longer fired when vehicle destroyed

Posted: Thu May 26, 2022 3:33 pm
by Stringweasel
What
The on_player_driving_changed_state event no longer fires when a vehicle is destroyed and the driver kicked out. This used to be the case before, and changed somewhere since 1.1.42.

It might be a regression after 100122. It's the only thing I could find in the changelogs that seems relevant.
Reproduction
Start any game, paste the following command to print out a message when the driving_state_changed event fires.

Code: Select all

/c
script.on_event(defines.events.on_player_driving_changed_state,
    function (event) game.print("Changed state") end
)
Get into a vehicle (tested with car and spidertron), and see the event fire. Wait a second, and then destroy the vechicle without killing the player (no nukes :P). Easiest, select the vehicle and paste the following command:

Code: Select all

/c game.player.character.vehicle.die()
See no event firing in 1.1.59.
Or, see the event firing in 1.1.42 (which is the older version I tested with).
Impact
Previously this event could be used as absolute truth for when a player gets in a vehicle, or out of a vehicle, no matter in what way. This is no longer the case, and might break mods that rely on this. For example, my mod Demolision Derby used this mechanism to determine which players are still alive in the "minigame", and now this mechanism doesn't function anymore.

Re: [1.1.59] on_player_driving_changed_state not fired when vehicle destroyed

Posted: Thu May 26, 2022 11:57 pm
by Pi-C
Stringweasel wrote: Thu May 26, 2022 3:33 pm Get into a vehicle (tested with car and spidertron), and see the event fire. Wait a second, and then destroy the vechicle without killing the player (no nukes :P). Easiest, select the vehicle and paste the following command:

Code: Select all

/c game.player.character.vehicle.die()
This also applies to

Code: Select all

/c game.player.character.vehicle.destroy()
/c game.player.character.vehicle.destroy({raise_destroy = true})
Impact
Previously this event could be used as absolute truth for when a player gets in a vehicle, or out of a vehicle, no matter in what way. This is no longer the case, and might break mods that rely on this.
I'm currently working on GCKI again. IIRC, vehicle.destroy() and vehicle.die() would trigger the event in the past, and testing confirmed that it doesn't work now. It definitely would be nice if the old behavior could be restored! :-)

Re: [1.1.59] on_player_driving_changed_state not fired when vehicle destroyed

Posted: Fri May 27, 2022 4:41 pm
by Rseding91
Thanks for the report however this is intended. There are a few cases where ejecting the player from a vehicle force does not send the event because mods can not be trusted to not invalidate the game state during the transition.

Example:

1. The vehicle is alive and is about to die
2. The player is ejected from the vehicle
3. A mod listens to the event and puts him back into the vehicle
4. Either the game crashes here or goes back to 2

In either case when 4 is reached the only option is to exit the game. That is not wanted so instead this case does not send the event. You can listen to the entity-died event for the vehicle to handle this case.

Re: [1.1.59] on_player_driving_changed_state not fired when vehicle destroyed

Posted: Fri May 27, 2022 4:46 pm
by Stringweasel
Rseding91 wrote: Fri May 27, 2022 4:41 pm Thanks for the report however this is intended.
I understand, it is quite the edge case, although it's odd not to have been mentioned in the changelogs since it's a significant change to how and when the event fires.

I'll work around it using entity destroyed then. Thanks for the look into it!