Author Topic: [resolved] item-triggered script not working  (Read 501 times)

Legacy_Tyreska

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
[resolved] item-triggered script not working
« on: February 20, 2011, 10:54:12 pm »


               Hi there, I've been experimenting with unique powers and tag-based scripting, checking out what I can do with it for later mods.

Currently I have a something that is supposed to be an AOE damage spell, activated by an item tagged "spellstorm". However, it isn't firing; when I attempt to use it in my testing mod, nothing happens. Strangely, when I then pick up or drop the item that activates my other test power (a single-damage spell), THAT spell fires on the object I tried to use Spellstorm on.

So I tried Spellstorm on a crate, nothing happens, I pick up the wand of Slaying, and suddenly the Slaying spell triggers on the crate.

The script names are identical to the corresponding item's tag, and I for sure have tag-based scripting set up in the test mod. I have both items activated through the Activate Item (Long Range) spell due to, well, the extra range. Here's the code of the Spellstorm spell:

// SPELLSTORM - Artifact Power
//
//   Creates a colossal explosion of magical energy
//   Deals 2d4/level magical damage to all targets
//   Minimum 30d4 damage / Maximum damage 50d4
//   Knockdown for 3 seconds, no saving throw, immunity applies
//   Fortitude Save DC48 to avoid being Stunned for 2 rounds
//

void main()
{
    object oTarget;
    object oPC = GetItemActivator();
    effect eDamage;
    location lTarget = GetItemActivatedTargetLocation();

    // Limit level range to between 15-25
    // Multiply by 2 to conform with damage formula
    int nLevel = GetHitDice(oPC)*2;
    if (nLevel < 30)
    { nLevel = 30; }
    else if (nLevel > 50)
    { nLevel = 50; }

    // Great Thunderclap VFX at target location
    ApplyEffectAtLocation(DURATION_TYPE_INSTANT,EffectVisualEffect(VFX_FNF_MYSTICAL_EXPLOSION),lTarget);
    ApplyEffectAtLocation(DURATION_TYPE_INSTANT,EffectVisualEffect(VFX_FNF_ELECTRIC_EXPLOSION),lTarget);

    // Large sphere radius, LOS not required, targets creatures placeables and doors
    oTarget = GetFirstObjectInShape(SHAPE_SPHERE,RADIUS_SIZE_COLOSSAL,lTarget,FALSE,OBJECT_TYPE_CREATURE | OBJECT_TYPE_DOOR | OBJECT_TYPE_PLACEABLE);

    while (GetIsObjectValid(oTarget))
    {
        if(GetIsEnemy(oTarget,oPC) == TRUE && oTarget != oPC)
        {
            // 2d4 Magical damage per caster level, minimum 30d4, maximum 50d4. Bypasses resistances and immunities
            eDamage = EffectDamage(d4(nLevel),DAMAGE_TYPE_MAGICAL,DAMAGE_POWER_ENERGY);

            // Knocks down targets for 3 seconds unless immune, similar to Hellball
            ApplyEffectToObject(DURATION_TYPE_TEMPORARY, EffectKnockdown(), oTarget, 3.0f);

            // Fortitude Save DC 48 to avoid being Stunned for 2 rounds
            if (FortitudeSave(oTarget, 48, SAVING_THROW_TYPE_SPELL, OBJECT_SELF) == 0)
            {
                ApplyEffectToObject(DURATION_TYPE_TEMPORARY, EffectStunned(), oTarget, RoundsToSeconds(2));
            }

            // Power Word Stun VFX on each target
            ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_PWSTUN), oTarget);

            // Apply damage
            ApplyEffectToObject(DURATION_TYPE_INSTANT, eDamage, oTarget);

            // Cycle to next target
            oTarget = GetNextObjectInShape(SHAPE_SPHERE,RADIUS_SIZE_COLOSSAL,lTarget,FALSE,OBJECT_TYPE_CREATURE | OBJECT_TYPE_DOOR | OBJECT_TYPE_PLACEABLE);
        }
    }
}



I don't know what the problem is (being a newbie to NWN scripting though not programming)... Could anyone shed some light on the issue? ':blink:'

======= EDIT ========
Okay, for some reason the script decided to just start working. Hooray '<img'> 

I have one more issue though: how do I make it so the spell shows the player how much damage was done to each target? As it is now, the damage is never shown... (and was only shown when it hits the player)
               
               

               


                     Modifié par Tyreska, 21 février 2011 - 05:03 .
                     
                  


            

Legacy_TSMDude

  • Hero Member
  • *****
  • Posts: 1515
  • Karma: +0/-0
[resolved] item-triggered script not working
« Reply #1 on: February 21, 2011, 02:15:15 am »


               Read this little bit by Axe Murderer and it will solve some of your problems.



http://members.cox.n.../nwn/tbi_2.html
               
               

               
            

Legacy_Tyreska

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
[resolved] item-triggered script not working
« Reply #2 on: February 21, 2011, 03:09:11 am »


               Thanks for the link! Very helpful info - wouldn't have thought of using the switch structure yet.



The current issue still stands though. I don't know of a way to make it so the damage effect is applied by the item's user rather than "Someone" (it denies experience gain and messes with variable changes from OnDeath scripts)
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
[resolved] item-triggered script not working
« Reply #3 on: February 21, 2011, 04:24:13 am »


               

Tyreska wrote...
 
The current issue still stands though. I don't know of a way to make it so the damage effect is applied by the item's user rather than "Someone" (it denies experience gain and messes with variable changes from OnDeath scripts)


 I will try to explain the problem you are having with your effects. 

Every time an effect is created it contains a data slot for the effect creator. The effect creator will be what ever object the effect was created on.  This creator of the effect will also be given any credit for damage done by the effect.  

Since the script you are currently using is a modular event the script is being ran by the module and the effects you are creating have the module as the effect creator. 

To fix the problem you will need to create the effects on the object that you want to get credit for the damage/kill

AssignCommand( oPC , ApplyEffectToObject(DURATION_TYPE_INSTANT,
                                                                                       EffectDamage(d4(nLevel),
                                                                                       DAMAGE_TYPE_MAGICAL,DAMAGE_POWER_ENERGY),
                                                                                        oTarget));
  
note:  That that effect is created after it is assigned to the PC.
               
               

               
            

Legacy_Tyreska

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
[resolved] item-triggered script not working
« Reply #4 on: February 21, 2011, 04:41:31 am »


               Ahh, works perfectly. Thanks a bunch!
I had thought about using AssignCommand, but I didn't realize I could put ApplyEffect in there. '^_^' Now to figure out why my teleport script suddenly broke...

Edit: Was a timing issue - increasing a delay by 0.2f worked. '<img'>
               
               

               


                     Modifié par Tyreska, 21 février 2011 - 05:03 .