Author Topic: Help with "simple" death system  (Read 363 times)

Legacy_SuperFly_2000

  • Hero Member
  • *****
  • Posts: 1292
  • Karma: +0/-0
Help with "simple" death system
« on: November 02, 2010, 09:43:03 am »


               I would like to do something like this:

- When player dies he loses 100 xp per level if he respawns (This is the only one I know how to set).
(I will not be using a fugue system...actually if it did scripting easier I could...)
- If a player gets raised he is supposed to loose 66 xp per level
- If he is resurected he only loses 33 xp per level.

Also if the player is above level 10 this should apply
- 150 xp per level for respawn
- raised 100 xp/lvl
- resurected 50 xp/lvl

The raising and resurecting will be done by other players on the site.
               
               

               


                     Modifié par SuperFly_2000, 02 novembre 2010 - 09:46 .
                     
                  


            

Legacy_SuperFly_2000

  • Hero Member
  • *****
  • Posts: 1292
  • Karma: +0/-0
Help with "simple" death system
« Reply #1 on: November 02, 2010, 09:45:23 am »


               Oh yeah...for the raise dead scroll to work the PC has to have an an object called "Balm of raising dead" and for resurecting "Balm of resurection" in his inventory. This object will be used up when the player casts the spell or uses the scroll...
               
               

               


                     Modifié par SuperFly_2000, 02 novembre 2010 - 10:03 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Help with "simple" death system
« Reply #2 on: November 02, 2010, 06:37:48 pm »


               You need to modify your raise dead and ressurection spells to accomplish this. You may be able to do this with a spell hook also but I'm not very familiar with spell hooking.

The default raise dead script for example is "nw_s0_raisdead"

Here is my raise dead spell mixed with what you wanted.


//::///////////////////////////////////////////////
//:: [Raise Dead]
//:: [NW_S0_RaisDead.nss]
//:: Copyright © 2000 Bioware Corp.
//:://////////////////////////////////////////////
//:: Brings a character back to life with 1 HP.
//:://////////////////////////////////////////////
//:: Created By: Preston Watamaniuk
//:: Created On: Jan 31, 2001
//:://////////////////////////////////////////////
//:: Last Updated By: Preston Watamaniuk, On: April 11, 2001
//:: VFX Pass By: Preston W, On: June 22, 2001

#include "x2_inc_spellhook"

void ReplaceItem(string sResRef, object oTarget, int iStack);

void main()
{

/*
  Spellcast Hook Code
  Added 2003-06-20 by Georg
  If you want to make changes to all spells,
  check x2_inc_spellhook.nss to find out more

*/

    if (!X2PreSpellCastCode())
    {
    // If code within the PreSpellCastHook (i.e. UMD) reports FALSE, do not run this spell
        return;
    }

// End of Spell Cast Hook

    object oBalm = GetItemPossessedBy(OBJECT_SELF, "RAISE_BALM");
    object oTarget = GetSpellTargetObject();
    object oSpellItem = GetSpellCastItem();
    string sResRef = GetResRef(oSpellItem);
    
    if (!GetIsDead(oTarget))
    {
        if (GetIsObjectValid(oSpellItem))
            {
                DelayCommand(1.0, ReplaceItem(sResRef, OBJECT_SELF, 1));
            }
        SendMessageToPC(OBJECT_SELF, "Your target is not dead.");
        return;
    }
    
    if (!GetIsObjectValid(oBalm))
    {
        if (GetIsObjectValid(oSpellItem))
        {
            DelayCommand(1.0, ReplaceItem(sResRef, OBJECT_SELF, 1));
        }
        SendMessageToPC(OBJECT_SELF, "You do not possess the required item to raise the dead.");
        return;
    }

    //Fire cast spell at event for the specified target
    SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, SPELL_RAISE_DEAD, FALSE));
    if(GetIsDead(oTarget))
    {
        effect eRaise = EffectResurrection();
        effect eVis = EffectVisualEffect(VFX_IMP_RAISE_DEAD);
        int iTargetLevel = GetHitDice(oTarget);
        int iXPTake;
        if (iTargetLevel <= 10)
        {
            iXPTake = iTargetLevel * 66;
            SetXP(oTarget, GetXP(oTarget) - iXPTake);
        }
        if (iTargetLevel > 10)
        {
            iXPTake = iTargetLevel * 100;
            SetXP(oTarget, GetXP(oTarget) - iXPTake);
        }
        //Apply raise dead effect and VFX impact
        ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eVis, GetLocation(oTarget));
        ApplyEffectToObject(DURATION_TYPE_INSTANT, eRaise, oTarget);
        DestroyObject(oBalm);
    }
}

void ReplaceItem(string sResRef, object oTarget, int iStack)
{
    CreateItemOnObject(sResRef, oTarget, iStack);
}


This one has been altered to give a scroll back to a person if they use it on a living player or, now in your case, if they don't have the raise dead balm. The reason I originaly did this was that I often accidentally used my only raise dead scroll on one of the living players instead of the dead one and then you waste the scroll. Grrr.

Make sure on the line "object oBalm = GetItemPossessedBy(OBJECT_SELF, "RAISE_BALM");" you plug in the correct tag of your balm.

Hope this helps. I'll alter the Ressurection spell to if you need. the default for it is "nw_s0_resserec".
               
               

               


                     Modifié par GhostOfGod, 02 novembre 2010 - 06:40 .
                     
                  


            

Legacy_SuperFly_2000

  • Hero Member
  • *****
  • Posts: 1292
  • Karma: +0/-0
Help with "simple" death system
« Reply #3 on: November 02, 2010, 07:30:18 pm »


               Woo...this looks good thanks!



Yeah...if you could edit the resurection spell I would appreciate it. I will probably just mess it up :-o





So the only thing that remains then is how to remove the 100 respectively 150 xp per level for a respawn. I guess that is a line or two in the death and/or respawn script....



I know how to remove an amount...but when the script has to differentiate if the player is higher or lower then level 10 I am kind of lost...
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Help with "simple" death system
« Reply #4 on: November 02, 2010, 08:02:29 pm »


               Something like this for your resurrection spell (default nwn script is "nw_s0_resserec"):


//::///////////////////////////////////////////////
//:: [Ressurection]
//:: [NW_S0_Ressurec.nss]
//:: Copyright © 2000 Bioware Corp.
//:://////////////////////////////////////////////
//:: Brings a character back to life with full
//:: health.
//:: When cast on placeables, you get a default error message.
//::   * You can specify a different message in
//::      X2_L_RESURRECT_SPELL_MSG_RESREF
//::   * You can turn off the message by setting the variable
//::     to -1
//:://////////////////////////////////////////////
//:: Created By: Preston Watamaniuk
//:: Created On: Jan 31, 2001
//:://////////////////////////////////////////////
//:: Last Updated By: Georg Z on 2003-07-31
//:: VFX Pass By: Preston W, On: June 22, 2001

#include "x2_inc_spellhook"

void ReplaceItem(string sResRef, object oTarget, int iStack);

void main()
{

/*
  Spellcast Hook Code
  Added 2003-06-20 by Georg
  If you want to make changes to all spells,
  check x2_inc_spellhook.nss to find out more

*/

    if (!X2PreSpellCastCode())
    {
    // If code within the PreSpellCastHook (i.e. UMD) reports FALSE, do not run this spell
        return;
    }

// End of Spell Cast Hook


    //Get the spell target
    object oBalm = GetItemPossessedBy(OBJECT_SELF, "RES_BALM");
    object oTarget = GetSpellTargetObject();
    object oSpellItem = GetSpellCastItem();
    string sResRef = GetResRef(oSpellItem);

    if (!GetIsDead(oTarget))
    {
        if (GetIsObjectValid(oSpellItem))
            {
                DelayCommand(1.0, ReplaceItem(sResRef, OBJECT_SELF, 1));
            }
        SendMessageToPC(OBJECT_SELF, "Your target is not dead.");
        return;
    }

    if (!GetIsObjectValid(oBalm))
    {
        if (GetIsObjectValid(oSpellItem))
        {
            DelayCommand(1.0, ReplaceItem(sResRef, OBJECT_SELF, 1));
        }
        SendMessageToPC(OBJECT_SELF, "You do not possess the required item to raise the dead.");
        return;
    }

    //Check to make sure the target is dead first
    //Fire cast spell at event for the specified target
    if (GetIsObjectValid(oTarget))
    {
        SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, SPELL_RESURRECTION, FALSE));
        if (GetIsDead(oTarget))
        {
            //Declare major variables
            int nHealed = GetMaxHitPoints(oTarget);
            effect eRaise = EffectResurrection();
            effect eHeal = EffectHeal(nHealed + 10);
            effect eVis = EffectVisualEffect(VFX_IMP_RAISE_DEAD);
            //Apply the heal, raise dead and VFX impact effect
            ApplyEffectToObject(DURATION_TYPE_INSTANT, eRaise, oTarget);
            ApplyEffectToObject(DURATION_TYPE_INSTANT, eHeal, oTarget);
            ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eVis, GetLocation(oTarget));
            DestroyObject(oBalm);
        }
        else
        {
            if (GetObjectType(oTarget) == OBJECT_TYPE_PLACEABLE)
            {
                int nStrRef = GetLocalInt(oTarget,"X2_L_RESURRECT_SPELL_MSG_RESREF");
                if (nStrRef == 0)
                {
                    nStrRef = 83861;
                }
                if (nStrRef != -1)
                {
                     FloatingTextStrRefOnCreature(nStrRef,OBJECT_SELF);
                }
            }
        }
    }
}

void ReplaceItem(string sResRef, object oTarget, int iStack)
{
    CreateItemOnObject(sResRef, oTarget, iStack);
}


Again make sure you plug in the correct tag for your resurrection balm.

And to alter your respawn script (if you are using the default) you could change it to look like so:
NOTE: This is not the entire respawn script. I just posted part of the beginning so you could see the change.


//::///////////////////////////////////////////////
//:: Generic On Pressed Respawn Button
//:: Copyright © 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
// * June 1: moved RestoreEffects into plot include
*/
//:://////////////////////////////////////////////
//:: Created By:   Brent
//:: Created On:   November
//:://////////////////////////////////////////////
#include "nw_i0_plot"

// * Applies an XP and GP penalty
// * to the player respawning
void ApplyPenalty(object oDead)
{
    int nXP = GetXP(oDead);
    int nPenalty;
    int nHD = GetHitDice(oDead);
    if (nHD <= 10) nPenalty = 100 * nHD;
    if (nHD > 10) nPenalty = 150 * nHD;
    // * You can not lose a level with this respawning
    int nMin = ((nHD * (nHD - 1)) / 2) * 1000;


Hope that helps. Good luck.
               
               

               
            

Legacy_SuperFly_2000

  • Hero Member
  • *****
  • Posts: 1292
  • Karma: +0/-0
Help with "simple" death system
« Reply #5 on: November 02, 2010, 11:20:17 pm »


               Thanks again!

I'll make sure to mention you in the credits regarding the deathsystem....if it works 'Image

Nice little set of scripts you got there on the vault btw...
               
               

               


                     Modifié par SuperFly_2000, 02 novembre 2010 - 11:20 .