// Module : OnPlayerDying by Brian "spilth" Kelly
// For Neverwinter Nights - Bleeding Tutorial

#include "bleeding_config"

void main() {
    object oPC = GetLastPlayerDying();

    // Let the module know somebody is not alive
    object oModule = GetModule();
    SetLocalInt(oModule, "EverybodyAlive", FALSE);

    // Check if they stablized, disconnected and then reconnected...
    if (GetLocalInt(oPC, "PlayerHealth") != PC_HEALTH_STABLE) {
        int iCurrentHitPoints = GetCurrentHitPoints(oPC);

        // How bad is it doc?
        if (iCurrentHitPoints == 0) {
            SetLocalInt(oPC, "PlayerHealth", PC_HEALTH_DISABLED);

        } else {
            // Flag them as dying.  We make them bleed in the module's OnHeartbeat script
            SetLocalInt(oPC, "PlayerHealth", PC_HEALTH_DYING);

        }

        // Save their hit points in case they disconnect
        SetLocalInt(oPC, "LastHitPoints", iCurrentHitPoints);

    } else {
        // Do nothing.  Heartbeat will take care of prompting the player

    }

}

