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



#include "bleeding_config"
void main() {

  object oPC = GetLastPlayerDied();

/*************************************************************

   object oPC = GetLastPlayerDied();

   // The DeathGUI automatically re-pops up when you're dead
    // So no need to make OnHeartbeat do any work
    SetLocalInt(oPC, "PlayerHealth", PC_HEALTH_DEAD);

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


  // *** Added to fix faction bug

  /*
    location lPClocation = GetLocation(oPC);
    object oInvItem = GetFirstItemInInventory(oPC);
    object oLootBag = CreateObject(OBJECT_TYPE_PLACEABLE, "pclootbag", lPClocation);
    int nYes;
    string sItemTag;

    while (GetIsObjectValid(oInvItem) == TRUE)
    {
        nYes = 0;
        sItemTag = "";
        sItemTag = GetTag(oInvItem);
        if(sItemTag == "FalseMark")
          nYes = 1;

        if(nYes == 1) {
          AssignCommand(oLootBag, ActionTakeItem(oInvItem, oPC));
        }

        oInvItem = GetNextItemInInventory(oPC);
    }
  */


    if (GetStandardFactionReputation(STANDARD_FACTION_COMMONER, oPC) <= 10)
    {   SetLocalInt(oPC, "NW_G_Playerhasbeenbad", 10); // * Player bad
        SetStandardFactionReputation(STANDARD_FACTION_COMMONER, 80, oPC);
    }
    if (GetStandardFactionReputation(STANDARD_FACTION_MERCHANT, oPC) <= 10)
    {   SetLocalInt(oPC, "NW_G_Playerhasbeenbad", 10); // * Player bad
        SetStandardFactionReputation(STANDARD_FACTION_MERCHANT, 80, oPC);
    }
    if (GetStandardFactionReputation(STANDARD_FACTION_DEFENDER, oPC) <= 10)
    {   SetLocalInt(oPC, "NW_G_Playerhasbeenbad", 10); // * Player bad
        SetStandardFactionReputation(STANDARD_FACTION_DEFENDER, 80, oPC);
    }

    AssignCommand(oPC, ClearAllActions());
    DelayCommand(2.5, PopUpDeathGUIPanel(oPC, TRUE, TRUE, 0, sDeathGUIMessage));

}
