[1.1.59] on_player_driving_changed_state no longer fired when vehicle destroyed

Bugs that are actually features.
Post Reply
User avatar
Stringweasel
Filter Inserter
Filter Inserter
Posts: 315
Joined: Thu Apr 27, 2017 8:22 pm
Contact:

[1.1.59] on_player_driving_changed_state no longer fired when vehicle destroyed

Post 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.
Last edited by Stringweasel on Fri May 27, 2022 5:23 pm, edited 1 time in total.
Alt-F4 Author | Factorio Modder
Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby

Pi-C
Smart Inserter
Smart Inserter
Posts: 1647
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: [1.1.59] on_player_driving_changed_state not fired when vehicle destroyed

Post 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! :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Rseding91
Factorio Staff
Factorio Staff
Posts: 13202
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [1.1.59] on_player_driving_changed_state not fired when vehicle destroyed

Post 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.
If you want to get ahold of me I'm almost always on Discord.

User avatar
Stringweasel
Filter Inserter
Filter Inserter
Posts: 315
Joined: Thu Apr 27, 2017 8:22 pm
Contact:

Re: [1.1.59] on_player_driving_changed_state not fired when vehicle destroyed

Post 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!
Alt-F4 Author | Factorio Modder
Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby

Post Reply

Return to “Not a bug”