Good luck scripting this, I think it will be hard
It's already done, I use it for Oblivion.
However, due to Oblivions engine it's hard to make sure the script always runs when the player dies. So what I currently do is have my character set to Essential and when I die I can still activate my inventory, because I'm really just unconscious, and I activate an item that starts the script. Not the best solution, but it works.
There is another mod out there that handles scripting after death well, but I can't get it to work with mine.