Author Sticky: Post Working Scripts Here
Ranthalas Posted: Sunday, 30 June 05:56AM
Script Names: dl_on_death & dl_respawn & teleport_respawn
What they do: Track PC Death Location and respawn in different location with ability to be sent back to spot of death

I have stolen from other scripts here, including some from the basic module. The dl_respawn script was written by a community member here with some minor mods from me.

OnDeath script, place in module OnDeath event:

NWScript:
//::///////////////////////////////////////////////

//:: Death Script

//:: NW_O0_DEATH.NSS

//:: Copyright (c) 2001 Bioware Corp.

//:://////////////////////////////////////////////

/*

    This script handles the default behavior

    that occurs when a player dies.

    Modification included to track location of death

    and to remove some elements that are official 

    compaign specific.

*/

//:://////////////////////////////////////////////

//:: Created By: Brent Knowles

//:: Created On: November 6, 2001

//:://////////////////////////////////////////////

 /*

void ClearAllFactionMembers(object oMember, object oPlayer)

{

//    AssignCommand(oMember, SpeakString("here"));

    AdjustReputation(oPlayer, oMember, 100);

    SetLocalInt(oPlayer, "NW_G_Playerhasbeenbad", 10); // * Player bad

    object oClear = GetFirstFactionMember(oMember, FALSE);

    while (GetIsObjectValid(oClear) == TRUE)

    {

        ClearPersonalReputation(oPlayer, oClear);

        oClear = GetNextFactionMember(oMember, FALSE);

    }

}   */

void Raise(object oPlayer)

{

        effect eVisual = EffectVisualEffect(VFX_IMP_RESTORATION);

        effect eBad = GetFirstEffect(oPlayer);

        ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectResurrection(),oPlayer);

        ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectHeal(GetMaxHitPoints(oPlayer)), oPlayer);

        //Search for negative effects

        while(GetIsEffectValid(eBad))

        {

            if (GetEffectType(eBad) == EFFECT_TYPE_ABILITY_DECREASE ||

                GetEffectType(eBad) == EFFECT_TYPE_AC_DECREASE ||

                GetEffectType(eBad) == EFFECT_TYPE_ATTACK_DECREASE ||

                GetEffectType(eBad) == EFFECT_TYPE_DAMAGE_DECREASE ||

                GetEffectType(eBad) == EFFECT_TYPE_DAMAGE_IMMUNITY_DECREASE ||

                GetEffectType(eBad) == EFFECT_TYPE_SAVING_THROW_DECREASE ||

                GetEffectType(eBad) == EFFECT_TYPE_SPELL_RESISTANCE_DECREASE ||

                GetEffectType(eBad) == EFFECT_TYPE_SKILL_DECREASE ||

                GetEffectType(eBad) == EFFECT_TYPE_BLINDNESS ||

                GetEffectType(eBad) == EFFECT_TYPE_DEAF ||

                GetEffectType(eBad) == EFFECT_TYPE_PARALYZE ||

                GetEffectType(eBad) == EFFECT_TYPE_NEGATIVELEVEL)

                {

                    //Remove effect if it is negative.

                    RemoveEffect(oPlayer, eBad);

                }

            eBad = GetNextEffect(oPlayer);

        }

        //Fire cast spell at event for the specified target

        SignalEvent(oPlayer, EventSpellCastAt(OBJECT_SELF, SPELL_RESTORATION, FALSE));

        ApplyEffectToObject(DURATION_TYPE_INSTANT, eVisual, oPlayer);

}

void main()

{

    object oPlayer = GetLastPlayerDied();

    // Next two lines help store death location:

    location lLoc = GetLocation(oPlayer);

    SetLocalLocation(oPlayer, "DL_L_DEATHLOC", lLoc);

    // * make friendly to Each of the 3 common factions

    AssignCommand(oPlayer, ClearAllActions());

    // * Note: waiting for Sophia to make SetStandardFactionReptuation to clear all personal reputation

    if (GetStandardFactionReputation(STANDARD_FACTION_COMMONER, oPlayer) <= 10)

    {   SetLocalInt(oPlayer, "NW_G_Playerhasbeenbad", 10); // * Player bad

        SetStandardFactionReputation(STANDARD_FACTION_COMMONER, 80, oPlayer);

    }

    if (GetStandardFactionReputation(STANDARD_FACTION_MERCHANT, oPlayer) <= 10)

    {   SetLocalInt(oPlayer, "NW_G_Playerhasbeenbad", 10); // * Player bad

        SetStandardFactionReputation(STANDARD_FACTION_MERCHANT, 80, oPlayer);

    }

    if (GetStandardFactionReputation(STANDARD_FACTION_DEFENDER, oPlayer) <= 10)

    {   SetLocalInt(oPlayer, "NW_G_Playerhasbeenbad", 10); // * Player bad

        SetStandardFactionReputation(STANDARD_FACTION_DEFENDER, 80, oPlayer);

    }

    DelayCommand(2.5, PopUpGUIPanel(oPlayer,GUI_PANEL_PLAYER_DEATH));

}



OnRespawn script added to module OnRespawn event:
Added code to respawn somewhere other than where PC died
Original code taken from database on nwn.lyoness.com

NWScript:
#include "nw_i0_plot"



void main()

{

    object oDead = GetLastRespawnButtonPresser();

    //Next line sets the point to respawn at:

    location lLoc = GetLocation(GetObjectByTag("IOTLH_RESPAWN"));

    int nXP = GetXP(oDead);

    int nPenalty = 50 * GetHitDice(oDead);

    int nHD = GetHitDice(oDead);

    int nMin = ((nHD * (nHD - 1)) / 2) * 1000;

    int nNewXP = nXP - nPenalty;

    if (nNewXP < nMin)

       nNewXP = nMin;

    SetXP(oDead, nNewXP);

    int nGoldToTake =    FloatToInt(0.10 * GetGold(oDead));

    if (nGoldToTake > 10000)

    {

        nGoldToTake = 10000;

    }

    AssignCommand(oDead, TakeGoldFromCreature(nGoldToTake, oDead, TRUE));

    DelayCommand(4.0, FloatingTextStrRefOnCreature(58299, oDead, FALSE));

    DelayCommand(4.8, FloatingTextStrRefOnCreature(58300, oDead, FALSE));

    ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectResurrection(),oDead);

ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectHeal(GetMaxHitPoints(oDead))

, oDead);

    // Next line moves character to the respawn point

    AssignCommand(oDead,ActionJumpToLocation(lLoc));

    //RemoveEffects(oDead);

}



SendtoDeathLocation script placed in conversation file with NPC:

NWScript:
#include "nw_i0_generic"

#include "nw_o2_coninclude"

void main()

{

    object oPC = GetPCSpeaker();

    location lLoc = GetLocalLocation(oPC, "DL_L_DEATHLOC");

    AssignCommand(oPC, ActionJumpToLocation(lLoc));

}



I hope that this helps someone. I've tested it and it works like a charm. Some modifications, you could put a series of if-then-else statements in to change the respawn point depending on the area that you died in if you wanted to have different respawn points for different areas.

[ Edited By Ranthalas: Sunday, 30 June 05:58AM (GMT) ]