on_player_died not working with other mods

Topics and discussion about specific mods
Post Reply
mattie112
Burner Inserter
Burner Inserter
Posts: 7
Joined: Fri Jan 28, 2022 3:39 pm
Contact:

on_player_died not working with other mods

Post by mattie112 »

I have a small mod that write some evens to a file so that I can use it to post it to Discord (https://mods.factorio.com/mod/FactoriGO ... -companion)

One of the things is player death messages:

Code: Select all

script.on_event(
    defines.events.on_player_died,
    function(event)
        local player_index = event.player_index
        local player_name = game.get_player(player_index).name
        local cause = event.cause
        if event.cause then
            cause = event.cause.name
        else
            cause = ""
        end

        if cause == "character" then
            cause = event.cause.player.name
        end

        local count, total = getAndStoreDeathCount(player_name, cause)

        log_message("[PLAYER_DIED:" .. player_name .. ":" .. cause .. ":" .. count .. ":" .. total .. "]")
    end
)
This all works fine but with my latest playthrough I notices it no longer works. When I disable all mods (except mine) it works again. I can only guess that some other mod is 'blocking' this call? Is that possible? Can I still have my code being executed? I have to many mods to go and disable them one by one (it takes a minute for the game to load) so I hope there is a better way.

Mods that I have enabled:

Code: Select all


{
  "mods": 
  [
    
    {
      "name": "base",
      "enabled": true
    },
    
    {
      "name": "aai-industry",
      "enabled": true
    },
    
    {
      "name": "aai-programmable-vehicles",
      "enabled": true
    },
    
    {
      "name": "aai-signal-transmission",
      "enabled": true
    },
    
    {
      "name": "aai-signals",
      "enabled": true
    },
    
    {
      "name": "AfraidOfTheDark",
      "enabled": true
    },
    
    {
      "name": "air-filtering",
      "enabled": true
    },
    
    {
      "name": "Aircraft",
      "enabled": true
    },
    
    {
      "name": "alien-biomes",
      "enabled": true
    },
    
    {
      "name": "alien-biomes-hr-terrain",
      "enabled": true
    },
    
    {
      "name": "ArmouredBiters",
      "enabled": true
    },

    {
      "name": "bobinserters",
      "enabled": true
    },
     
    {
      "name": "Bottleneck",
      "enabled": true
    },
    
    {
      "name": "bullet-trails",
      "enabled": true
    },
    
    {
      "name": "combat-mechanics-overhaul",
      "enabled": true
    },
    
    {
      "name": "deadlock-beltboxes-loaders",
      "enabled": true
    },
    
    {
      "name": "DiscoScience",
      "enabled": true
    },
    
    {
      "name": "Early-3x3-Electric-Furnaces",
      "enabled": true
    },
    
    {
      "name": "EditorExtensions",
      "enabled": true
    },
    
    {
      "name": "even-distribution",
      "enabled": true
    },
    
    {
      "name": "EvoGUI",
      "enabled": true
    },
    
    {
      "name": "FactoriGOChatBot-companion",
      "enabled": true
    },
    
    {
      "name": "far-reach",
      "enabled": true
    },
    
    {
      "name": "flib",
      "enabled": true
    },
    
    {
      "name": "Flow Control",
      "enabled": true
    },
    
    {
      "name": "FluidMustFlow",
      "enabled": true
    },
    
    {
      "name": "FNEI",
      "enabled": true
    },
    
    {
      "name": "Hovercrafts",
      "enabled": true
    },

    {
      "name": "informatron",
      "enabled": true
    },

    {
      "name": "jetpack",
      "enabled": true
    },

    {
      "name": "Krastorio2",
      "enabled": true
    },
    
    {
      "name": "Krastorio2Assets",
      "enabled": true
    },
    
    {
      "name": "LightedPolesPlus",
      "enabled": true
    },
    
    {
      "name": "RecipeBook",
      "enabled": true
    },
    
    {
      "name": "researched-what",
      "enabled": true
    },
    
    {
      "name": "reverse-factory",
      "enabled": true
    },
    
    {
      "name": "robot_attrition",
      "enabled": true
    },
    
    {
      "name": "shield-projector",
      "enabled": true
    },
    
    {
      "name": "space-exploration",
      "enabled": true
    },
    
    {
      "name": "space-exploration-graphics",
      "enabled": true
    },
    
    {
      "name": "space-exploration-graphics-2",
      "enabled": true
    },
    
    {
      "name": "space-exploration-graphics-3",
      "enabled": true
    },
    
    {
      "name": "space-exploration-graphics-4",
      "enabled": true
    },
    
    {
      "name": "space-exploration-graphics-5",
      "enabled": true
    },
    
    {
      "name": "space-exploration-postprocess",
      "enabled": true
    },

    {
      "name": "spidertrontiers-circulardependency",
      "enabled": true
    },
    
    {
      "name": "Squeak Through",
      "enabled": true
    },
    
    {
      "name": "StatsGui",
      "enabled": true
    },
    
    {
      "name": "stdlib",
      "enabled": true
    },
        
    {
      "name": "VehicleSnap",
      "enabled": true
    },
    
    {
      "name": "vtk-armor-plating",
      "enabled": true
    },
    
    {
      "name": "Waterfill_v17",
      "enabled": true
    }
  ]
}

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

Re: on_player_died not working with other mods

Post by Pi-C »

mattie112 wrote:
Sat May 07, 2022 8:51 am
I have a small mod that write some evens to a file so that I can use it to post it to Discord (https://mods.factorio.com/mod/FactoriGO ... -companion)

One of the things is player death messages:

Code: Select all

script.on_event(
    defines.events.on_player_died,
    function(event)
        local player_index = event.player_index
        local player_name = game.get_player(player_index).name
        local cause = event.cause
        if event.cause then
            cause = event.cause.name
        else
            cause = ""
        end

        if cause == "character" then
            cause = event.cause.player.name
        end

        local count, total = getAndStoreDeathCount(player_name, cause)

        log_message("[PLAYER_DIED:" .. player_name .. ":" .. cause .. ":" .. count .. ":" .. total .. "]")
    end
)
This all works fine but with my latest playthrough I notices it no longer works. When I disable all mods (except mine) it works again. I can only guess that some other mod is 'blocking' this call?
If I remember correctly, it was loot left by killed entities I was having trouble with: When my event handler was run, some other mod running before mine already had removed the loot from the event, so I had nothing to work with. I guess something similar could be the case here.
Is that possible? Can I still have my code being executed?
Move your code from on_player_died to on_pre_player_died. It also has the cause of death in its event data, so everything should still work.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

User avatar
Silari
Filter Inserter
Filter Inserter
Posts: 489
Joined: Sat Jan 27, 2018 10:04 pm
Contact:

Re: on_player_died not working with other mods

Post by Silari »

As Pi-C said pre_player_died should work fine for what you're using it for.

My first guess at the cause would be Space Exploration. It has to do some things when the player dies so it can show a menu to respawn either on the homeworld, nearest landing pad, or nearest spaceship. A quick check shows my SE game also never fires player_died, but does fire pre_player_died.

Post Reply

Return to “Mods”