Player body abduction


When a player is killed, the body may be abducted by the enemy and taken to somewhere else.

Content
12 days ago
1.1 - 2.0
995
Enemies

b Crash when destroyed character was not connected to a player

1 year, 1 month ago
(updated 1 year, 1 month ago)

While checking out Multiple Characters, I've created some new character entities, then killed one. This resulted in the following crash:

 318.700 Error MainLoop.cpp:1395: Exception at tick 546307: The mod Player body abduction (0.1.2) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event player_body_abduction::on_post_entity_died (ID 136)
__player_body_abduction__/control.lua:117: attempt to index local 'player' (a nil value)
stack traceback:
  __player_body_abduction__/control.lua:117: in function <__player_body_abduction__/control.lua:108>

I've added two logging commands to your function on_post_entity_died:

function on_post_entity_died(event)
local prototype = event.prototype
if prototype then
        local corpses = event.corpses
        if (corpses and corpses[1] and corpses[1].valid ) then
                local corpse = corpses[1]
log("corpse.character_corpse_player_index: "..serpent.line(corpse.character_corpse_player_index))
                if corpse.character_corpse_player_index  then --and  corpse.get_item_count()>50
                        local player = game.players[corpse.character_corpse_player_index]
log("player: "..serpent.line(player and player.valid and player.name))
                        local dying_player = global.dying_player[player.name]

You've already tried to assure that corpse.character_corpse_player_index exists. However, it has an unexpected value if no player was connected to the character, so the wrong code path will be used:

 735.108 Script @__player_body_abduction__/control.lua:114: corpse.character_corpse_player_index: 65536
 735.108 Script @__player_body_abduction__/control.lua:117: player: nil
 735.108 Error MainLoop.cpp:1395: Exception at tick 541036: The mod Player body abduction (0.1.2) caused a non-recoverable error.
Please report this error to the mod author.
1 year, 1 month ago

fixed. thanks for the report

1 year, 1 month ago

Thanks for the quick fix! :-)

New response