[1.1.88] script-created projectiles don't attribute damage to the specified source
Posted: Mon Aug 14, 2023 9:01 pm
I am trying to make a sort of automatic rocket launcher ability. I expect that setting the "source" of the created rocket projectile entity to the player character should attribute the rocket's damage to the character, however in the on_entity_died event, the cause is missing.
Steps to reproduce:
1. launch base game, no mods.
2. start a new save, all default settings.
3. run the below command in chat console:
4. go walk near a biter base and look at chat as the enemies die.
5. Since the source of the rocket projectile is set as the player character, I would expect the character to be the source of the damage when an enemy dies, but instead it is always "unknown" (event.cause is nil).
Steps to reproduce:
1. launch base game, no mods.
2. start a new save, all default settings.
3. run the below command in chat console:
Code: Select all
/c script.on_nth_tick(10, function()
local player = game.players[1]
local surface = player.surface
local enemy = surface.find_nearest_enemy{
position = player.position,
max_distance = 50,
force = player.force,
}
if not enemy then return end
local rocket = surface.create_entity{
name = "rocket",
position = player.position,
direction = player.character.direction,
force = player.force,
target = enemy,
source = player.character,
speed = 1/25,
max_range = 50,
player = player,
character = player.character,
}
end)
script.on_event(defines.events.on_entity_died, function(event)
game.print(event.entity.name .. " killed by " .. ((event.cause and event.cause.name) or "unknown"))
end)
5. Since the source of the rocket projectile is set as the player character, I would expect the character to be the source of the damage when an enemy dies, but instead it is always "unknown" (event.cause is nil).