Yeah, the self object value is set when a new thread group is created. It's null at the start of map scripts, it's the player whose state file is being called if you create one there, it's whatever you want if you define it in a script, etc... For example:
$player thread GiveWeapon
This will assign $player as the self object in GiveWeapon and thus creates a new thread group here. So if you wanted to create another thread inside GiveWeapon that does something to the same player, you don't need to define the self object again, just:
thread GiveGrenades
Unless of course you wanted to create a new thread group. The group object is assigned to the current thread group of each thread:
group.variable1
This can be accessed from the entire group of threads, so is contained there.
For your problem, could you use the max_health trick to check for player deaths? So no spawn event checks needed (if that is buggy) and no loops needed.
if (self.max_health == 100)
{
self.max_health = 100.01
self heal (0.01 * 0.01) // give the player the 0.01 extra health (as a fraction of 1.0 for heal function)
//your code here
}
max_health is reset on death automatically by the game.
But of course, if the killed event is fine then just do your checks there instead as that is superior.