Author Topic: Custom Spell Creation - but how to award XP?  (Read 362 times)

Legacy_Ivanovich

  • Full Member
  • ***
  • Posts: 142
  • Karma: +0/-0
Custom Spell Creation - but how to award XP?
« on: May 03, 2011, 08:52:21 pm »


               Hi there.  Was wondering if I might get a meeting of the minds to answer this quandry.

I've created a custom spell using a blank scroll (use item).  Effects and damage are delivered just fine to creatures within the shape of the area specified by the script.  The only problem is, creatures that die do not give XP to the caster of the spell.  I am assuming this is because the game is not attributing the caster as the killer of the creature.  This is further confirmed when another PC is in the area and it says "someone damages so-and-so..."

Can anyone offer advice on where this is located and how this is done?

Much obliged. 
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Custom Spell Creation - but how to award XP?
« Reply #1 on: May 03, 2011, 09:32:36 pm »


               You are correct in your assumtions. 

Now it is time for my assunptions.  I assume that you are creating an effect to do the damage from the spell. 

All code from scripts in NWN run on an object.  When an effect kills a creature the object that created the effect is given credit for the kill.   The Effect creator is object the code was running on when the effect was created. 


Let me use a TagBasedScript as an example;  Now this first script is the wrong way to do it. 

This script is flawed and gives no xp to the PC if they kill the NPC.

 #include "x2_inc_switches"

void main()
{
    object oPC;
    object oItem;
    object oTarget;
    effect eEffect;
    int nEvent = GetUserDefinedItemEventNumber();
    switch (nEvent)
    {
        case X2_ITEM_EVENT_ACTIVATE:
            oPC   = GetItemActivator();
            oItem = GetItemActivated();
            oTarget =GetItemActivatedTarget();

            eEffect = EffectDamage(50);
            ApplyEffectToObject(DURATION_TYPE_INSTANT,eEffect,oTarget);

        break;
    }
}
 


The script look good and does what you would expect it to do.  When used by the PC it does 50 points of damage to the target.  However since the code that created the effect was running on the module, the module is the creator of the effect and will get the credit for anything the effect kills.  in order for the PC to get the credit for the kill the code need to be running on them when the effect is created that can be done this way. 


#include "x2_inc_switches"

void main()
{
    object oPC;
    object oItem;
    object oTarget;

    int nEvent = GetUserDefinedItemEventNumber();
    switch (nEvent)
    {
        case X2_ITEM_EVENT_ACTIVATE:
            oPC   = GetItemActivator();
            oItem = GetItemActivated();
            oTarget =GetItemActivatedTarget();

            AssignCommand(oPC,ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectDamage(50),oTarget));

        break;
    }
}
  

In this script the PC will get the credit for the kill.  Even though the script is still running on the module.  The code that creates the effect is not ran untill after it is assigned to the PC.  
               
               

               
            

Legacy_Ivanovich

  • Full Member
  • ***
  • Posts: 142
  • Karma: +0/-0
Custom Spell Creation - but how to award XP?
« Reply #2 on: May 03, 2011, 09:56:33 pm »


               This makes perfect sense.  I was unaware a PC could apply an effect to an object.  I will try this at once.  Thank you for your help!