[1.1.72] on_trigger_created_entity has no last_user when player.character is destroyed before the entity is created
Posted: Tue Nov 15, 2022 6:48 pm
When a projectile is created via LuaSurface.create_entity() with the parameter “player” set, but the player.character is destroyed before the projectile has time to trigger the “on_trigger_created_entity” event, the variable last_user in the created event.entity is nil.
The issue can be reproduced by using a projectile with spawns an entity and has the property “trigger_created_entity” set to true. If the projectile is created via the method create_entity() of the LuaSurface right before the player.character is destroyed, the entity in the event “on_trigger_created_entity() will have no last_user.
I was able to reproduce this issue by using my mod “Combat Robots Overhaul” multiple times. Using one of the new combat units, I spawned one unit via capsule and immediately destroyed my character while the projectile was flying. (Since there is only a limited timeframe to achieve this, I used the mod “speed control” to slow down the sim speed) When the entity spawned, it had no last_user set which caused the mod to crash.
The reason why I think this is a bug, is because of the parameter “player” for the method create_entity() of the class LuaSurface. This parameter has the type “playerIdentification” which includes “LuaPlayer”. Since LuaPlayer is not the same prototype as the player character (which is LuaEntity), the destruction of the character should have no influence over last_user. Instead, I expect the parameter last_user to correctly refer to the LuaPlayer Class of a player.
If I’m wrong feel free to ignore this thread. If you need more information or would like a save to replicate the issue let me know.
Thanks for all the amazing work you do.
The issue can be reproduced by using a projectile with spawns an entity and has the property “trigger_created_entity” set to true. If the projectile is created via the method create_entity() of the LuaSurface right before the player.character is destroyed, the entity in the event “on_trigger_created_entity() will have no last_user.
I was able to reproduce this issue by using my mod “Combat Robots Overhaul” multiple times. Using one of the new combat units, I spawned one unit via capsule and immediately destroyed my character while the projectile was flying. (Since there is only a limited timeframe to achieve this, I used the mod “speed control” to slow down the sim speed) When the entity spawned, it had no last_user set which caused the mod to crash.
The reason why I think this is a bug, is because of the parameter “player” for the method create_entity() of the class LuaSurface. This parameter has the type “playerIdentification” which includes “LuaPlayer”. Since LuaPlayer is not the same prototype as the player character (which is LuaEntity), the destruction of the character should have no influence over last_user. Instead, I expect the parameter last_user to correctly refer to the LuaPlayer Class of a player.
If I’m wrong feel free to ignore this thread. If you need more information or would like a save to replicate the issue let me know.
Thanks for all the amazing work you do.