[1.1.88] script-created projectiles don't attribute damage to the specified source

This subforum contains all the issues which we already resolved.
asher_sky
Long Handed Inserter
Long Handed Inserter
Posts: 58
Joined: Sun Oct 18, 2020 7:13 pm
Contact:

[1.1.88] script-created projectiles don't attribute damage to the specified source

Post by asher_sky »

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:

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)
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).
Attachments
factorio-current.log
(7.12 KiB) Downloaded 62 times
Rseding91
Factorio Staff
Factorio Staff
Posts: 14627
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [1.1.88] script-created projectiles don't attribute damage to the specified source

Post by Rseding91 »

Thanks for the report. It's now fixed for the next release.
If you want to get ahold of me I'm almost always on Discord.
asher_sky
Long Handed Inserter
Long Handed Inserter
Posts: 58
Joined: Sun Oct 18, 2020 7:13 pm
Contact:

Re: [1.1.88] script-created projectiles don't attribute damage to the specified source

Post by asher_sky »

Amazing, thank you!
Post Reply

Return to “Resolved Problems and Bugs”