Author Topic: Chain Lightning (similar script) and Line of Sight Vectors  (Read 405 times)

Legacy_MrPencilpusher

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
Chain Lightning (similar script) and Line of Sight Vectors
« on: October 29, 2011, 09:54:46 pm »


               Hello friends,

I like making unique boss fights in NWN. And for one of my ideas, I have a boss that spawns bomblings that run at you and detonate (damaging you). Once they detonate, they spawn a placeable on the ground. The boss will randomly cast an 'ultimate' type ability where he charges up electricity and sends out a chain lightning across all the bombling placeables on the ground. All of this has been scripted and works perfectly, but I was wondering if NWN has a collision system, either directly built in or if it is possible to create one by using LineOfSightObject/Vector functions. 

-I was wondering if it is possible to make it so that if a person is standing inside a chain lightning link, that they take damage.
-If this is impossible, I'll most likely just have the placeables 'overcharge' and cause AoE damage (less exciting, but still fun).
-My boss fights are much like WoW, focusing on positioning and risk/rewards systems.

X-------PC----------X

Chain Lightning code (derived from nw_s0_chlightn):
               
               

               
            

Legacy_MrPencilpusher

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
Chain Lightning (similar script) and Line of Sight Vectors
« Reply #1 on: October 29, 2011, 09:55:19 pm »


                
#include "x0_I0_SPELLS"
#include "x2_inc_spellhook"

void main()
{
    if (!X2PreSpellCastCode())   
{   
// If code within the PreSpellCastHook (i.e. UMD) reports FALSE, do not run this spell       
return;   
}
// End of Spell Cast Hook

    //Declare major variables

    int nDamStrike;   
int nNumAffected = 0;   
int nMetaMagic = GetMetaMagicFeat();    //Declare lightning effect connected the casters hands   
effect eLightning = EffectBeam(VFX_BEAM_LIGHTNING, OBJECT_SELF, BODY_NODE_HAND);;   
effect eVis  = EffectVisualEffect(VFX_IMP_LIGHTNING_S);   
effect eDamage;   
object oFirstTarget = OBJECT_SELF;   
object oHolder;   
object oTarget;   
location lSpellLocation;

//------------------------------------------------------------------------------------------------------
        SignalEvent(oFirstTarget, EventSpellCastAt(OBJECT_SELF, SPELL_CHAIN_LIGHTNING));


 ApplyEffectToObject(DURATION_TYPE_INSTANT,eDamage,oFirstTarget);                ApplyEffectToObject(DURATION_TYPE_INSTANT,eVis,oFirstTarget);
                    if (oTarget == GetObjectByTag("BomblingHeart"))                   
                    {                   
                    ExecuteScript("dropactivate", oFirstTarget);                   
                    }


    //Apply the lightning stream effect to the first target, connecting it with the caster    ApplyEffectToObject(DURATION_TYPE_TEMPORARY,eLightning,oFirstTarget,0.5);

    //Reinitialize the lightning effect so that it travels from the first target to the next target   
eLightning = EffectBeam(VFX_BEAM_LIGHTNING, oFirstTarget, BODY_NODE_CHEST);

    float fDelay = 0.2;    int nCnt = 0;

// *   
// * Secondary Targets   
// *

    //Get the first target in the spell shape   
oTarget = GetFirstObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_COLOSSAL, GetLocation(oFirstTarget), TRUE, OBJECT_TYPE_PLACEABLE);   

while (GetIsObjectValid(oTarget))   
{
            //Connect the new lightning stream to the older target and the new target           
DelayCommand(fDelay, ApplyEffectToObject(DURATION_TYPE_TEMPORARY,eLightning,oTarget,0.5));
            //Fire cast spell at event for the specified target           
SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, SPELL_CHAIN_LIGHTNING));           
//Do an SR check           
if (!MyResistSpell(OBJECT_SELF, oTarget, fDelay))           
{
                    DelayCommand(fDelay, ApplyEffectToObject(DURATION_TYPE_INSTANT,eVis,oTarget));                    oHolder = oTarget;
                    if (oTarget == GetObjectByTag("BomblingHeart"))                   
{                   
DelayCommand(fDelay, ExecuteScript("dropactivate", oTarget));                   
}


            //change the currect holder of the lightning stream to the current target           
if (GetObjectType(oTarget) == OBJECT_TYPE_PLACEABLE)               
{               
eLightning = EffectBeam(VFX_BEAM_LIGHTNING, oHolder, BODY_NODE_CHEST);               
}           
else               
{               
// * April 2003 trying to make sure beams originate correctly               
effect eNewLightning = EffectBeam(VFX_BEAM_LIGHTNING, oHolder, BODY_NODE_CHEST);                if(GetIsEffectValid(eNewLightning))                   
{                   
eLightning =  eNewLightning;                   
}               
}
            fDelay = fDelay + 0.1f;       
}

            //Count the number of targets that have been hit.           
if(GetObjectType(oTarget) == OBJECT_TYPE_PLACEABLE)           
{           
nCnt++;           
}
        //Get the next target in the shape.       
oTarget = GetNextObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_COLOSSAL, GetLocation(oFirstTarget), TRUE, OBJECT_TYPE_PLACEABLE);                           
if (oTarget == GetObjectByTag("BomblingHeart"))                   
{                   
DelayCommand(fDelay, ExecuteScript("dropactivate", oTarget));                   
}     
}
 }

BomblingHeart script is just the activation of whatever I decide to do once the chain reaches a placeable.
               
               

               


                     Modifié par MrPencilpusher, 29 octobre 2011 - 09:12 .
                     
                  


            

Legacy_Xardex

  • Sr. Member
  • ****
  • Posts: 414
  • Karma: +0/-0
Chain Lightning (similar script) and Line of Sight Vectors
« Reply #2 on: October 29, 2011, 10:36:00 pm »


               If by collision you are thinking about something like sending a fireball that will explode when it collides with something, no, that isn't possible. (But then again you are talking about lightning so im a bit confused)

If you want to damage things between point A and B, check out this function:
http://www.nwnlexico...ectinshape.html

nShape you will want to use would be SHAPE_SPELLCYLINDER and for fSize use GetDistanceBetween. You might also want to check out the script for the spell "lightning bolt."
               
               

               


                     Modifié par Xardex, 29 octobre 2011 - 09:37 .
                     
                  


            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Chain Lightning (similar script) and Line of Sight Vectors
« Reply #3 on: October 31, 2011, 01:34:53 pm »


               

Xardex wrote...

If by collision you are thinking about something like sending a fireball that will explode when it collides with something, no, that isn't possible. (But then again you are talking about lightning so im a bit confused)

If you want to damage things between point A and B, check out this function:
http://www.nwnlexico...ectinshape.html

nShape you will want to use would be SHAPE_SPELLCYLINDER and for fSize use GetDistanceBetween. You might also want to check out the script for the spell "lightning bolt."



Using exactly what Xardex has said, you can modify Fireball to use SHAPE_SPELLCYLINDER

Have it use the GetFirstObjectInShape, then if that function returns a npc or character, in the line of sight, update the target of the fireball, with the new location of the npc/player.

so, in effect

You target point b from A

A----------->       Player ----------------->  B

but once the cylinder returns that it found Player,
it updates B to be the location of Player.

                           B
A------------->  Player


This is actually a good idea - I might update my own fireball code to include this.
Of course, this wont account for Geometry of the environment - but could account for placeables, creatures, players etc.

Eg - Player is behind a bookshelf - instead of going through the bookshelf, the fireball instead detonates ON the bookshelf.
               
               

               
            

Legacy_Xardex

  • Sr. Member
  • ****
  • Posts: 414
  • Karma: +0/-0
Chain Lightning (similar script) and Line of Sight Vectors
« Reply #4 on: November 01, 2011, 11:34:13 am »


               But once you send the fireball VFX, you can't change its target to my knowledge.
               
               

               
            

Legacy_MrPencilpusher

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
Chain Lightning (similar script) and Line of Sight Vectors
« Reply #5 on: November 02, 2011, 02:03:45 am »


               Thanks for the input, fellas. I'll have to give it a try.