object oPC;

void BleedingContinues()
{
  DelayCommand(6.0,ExecuteScript("playerbleeding", oPC));
}

void main()
{
  oPC = OBJECT_SELF;
  if ((GetCurrentHitPoints(oPC) > 0) || GetCurrentHitPoints(oPC) <= -10)
    return;
  int nRecovering = GetLocalInt(oPC,"recovering");
  if (nRecovering == TRUE)
  // recovering
    ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectHeal(1),oPC);
  else
  // not recovering yet
  {
    int nStabilize = d10();
    if (nStabilize == 10)
    // just stabilized
    {
      SetLocalInt(oPC,"recovering",TRUE);
      PlayVoiceChat (VOICE_CHAT_LAUGH, oPC);
      SendMessageToPC(oPC,"You have stabilized.");
    }
    else
    // not stabilized, bleeding to death
    {
      effect eDamage = EffectDamage(1,DAMAGE_TYPE_MAGICAL,DAMAGE_POWER_PLUS_FIVE);
      ApplyEffectToObject(DURATION_TYPE_INSTANT,eDamage,oPC);
      int nPainMsg = d6();
      switch(nPainMsg)
      {
        case 1:
          PlayVoiceChat (VOICE_CHAT_PAIN1, oPC);
          break;
        case 2:
          PlayVoiceChat (VOICE_CHAT_PAIN2, oPC);
          break;
        case 3:
          PlayVoiceChat (VOICE_CHAT_PAIN3, oPC);
          break;
        case 4:
          PlayVoiceChat (VOICE_CHAT_HEALME, oPC);
          break;
        case 5:
          PlayVoiceChat (VOICE_CHAT_NEARDEATH, oPC);
          break;
        case 6:
          PlayVoiceChat (VOICE_CHAT_HELP, oPC);
          break;
      }
    }
  }
  BleedingContinues();
}
