Author Topic: Aura Heartbeat Script  (Read 1020 times)

Legacy_Imperator

  • Full Member
  • ***
  • Posts: 128
  • Karma: +0/-0
Aura Heartbeat Script
« on: April 28, 2016, 06:10:41 pm »


               

I'm trying to make a script which will shoot lightning out at nearby targets.. the closer they are the more likely it'll fire.


 


<= 5 meters is 100%


<=10 meters is 50%


<=20 meters is 20%


 


object oZap_c = GetNearestObject(OBJECT_TYPE_PLACEABLE, OBJECT_SELF, 1);

object oZap_p = GetNearestObject(OBJECT_TYPE_CREATURE, OBJECT_SELF, 1);


eVFX = EffectVisualEffect(VFX_BEAM_LIGHTNING);


ApplyEffectToObject(DURATION_TYPE_INSTANT, eVFX, oZap_c);


ApplyEffectToObject(DURATION_TYPE_INSTANT, eVFX, oZap_p);


 


can anyone help me out so it'll find targets as it moves? I don't necessarily need any help with the distances/ifs/frequencies.



               
               

               
            

Legacy_KMdS!

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +0/-0
Aura Heartbeat Script
« Reply #1 on: April 28, 2016, 06:30:06 pm »


               

Will this need to check for all targets within range so as to fire upon all that fail the check (muliple bolts possible) or are you running this so that only one bolt will strike out per hb cycle and therefore search only until a single target fails or no bole occurs that specific iteration?



               
               

               
            

Legacy_Imperator

  • Full Member
  • ***
  • Posts: 128
  • Karma: +0/-0
Aura Heartbeat Script
« Reply #2 on: April 28, 2016, 06:34:53 pm »


               

Actually, the first sounds like a good idea. and I'll only have it be a 5 meter radius, multiple bolts hitting every object within that area.



               
               

               
            

Legacy_Imperator

  • Full Member
  • ***
  • Posts: 128
  • Karma: +0/-0
Aura Heartbeat Script
« Reply #3 on: April 28, 2016, 11:19:46 pm »


               

Also, is it possible to get a random location with in a certain area around an object to strike lightning at?



               
               

               
            

Legacy_Imperator

  • Full Member
  • ***
  • Posts: 128
  • Karma: +0/-0
Aura Heartbeat Script
« Reply #4 on: April 28, 2016, 11:27:54 pm »


               

Nevermind, I figured it out haha. At least the first question, not the second one just above '<img'>



               
               

               
            

Legacy_KMdS!

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +0/-0
Aura Heartbeat Script
« Reply #5 on: April 29, 2016, 01:38:54 am »


               

Without any NW materials on hand at the moment, here is what you might need to do to get a random location within 5m of your bolt caating object.



    //OBJECT_SELF should be the bolt creating object
    vector vVector = GetPosition(OBJECT_SELF);
    // Will generate a value for x anf y between -5.00 to 5.00
    // a Value of 0.0, 0.0 should occur only once in a million
    float fX = IntToFloat(Random(1001)-500);
    float fY = IntToFloat(Random(1001)-500);
 
    // This is the new random vector for the strike location up to 5m away and one meter high.
    vector vNew = (vVector.x +fX, vVector.y +fY, 1.0);


               
               

               
            

Legacy_Imperator

  • Full Member
  • ***
  • Posts: 128
  • Karma: +0/-0
Aura Heartbeat Script
« Reply #6 on: April 29, 2016, 02:24:52 am »


               

Thank you for the reply. I'm trying to think how I could use the locations created though.. since I can't use something like "GetNextLocationInShape." I guess I could if I scripted that but I dunno how. '<img'>


 


Would it be possible for those locations to also create a temporary object/waypoint so it could be incorporated into this script?


 


 


// Aura for lightning Azer, onHeartbeat

void main()

{

effect eVFX;

location lSelf = GetLocation(OBJECT_SELF);

{

object oZap = GetFirstObjectInShape(SHAPE_SPHERE, 5.0, lSelf , TRUE,OBJECT_TYPE_ALL);

eVFX = EffectVisualEffect(VFX_BEAM_LIGHTNING);

ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eVFX, oZap, 1.0);



while(GetIsObjectValid(oZap) &&

GetDistanceToObject(oZap) <= 5.0)

{

oZap = GetNextObjectInShape(SHAPE_SPHERE, 5.0, lSelf , TRUE, OBJECT_TYPE_ALL);

ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eVFX, oZap, 1.0);

effect eElectric = EffectDamage(d6(2), DAMAGE_TYPE_ELECTRICAL, DAMAGE_POWER_NORMAL);

ApplyEffectToObject(DURATION_TYPE_INSTANT, eElectric, oZap);

}

}

}

 


               
               

               
            

Legacy_KMdS!

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +0/-0
Aura Heartbeat Script
« Reply #7 on: April 29, 2016, 04:30:25 am »


               

Ok, Try This. It compiles, but I haven't tested it.




// Aura for lightning Azer, onHeartbeat

 

vector RandomVector(int iMeterRadius = 5)

{

    //OBJECT_SELF should be the bolt creating object

    vector vVector = GetPosition(OBJECT_SELF);

    // Will generate a value for x anf y between -5.00 to 5.00

    // a Value of 0.0, 0.0 should occur only once in a million

    float fX = IntToFloat(Random((iMeterRadius*200)+1)-(iMeterRadius*100))/100;

    float fY = IntToFloat(Random((iMeterRadius*200)+1)-(iMeterRadius*100))/100;

 

    // This is the new random vector for the strike location up to 5m away and one meter high.

    return Vector(vVector.x +fX, vVector.y +fY, 0.0);

}

 

 

void main()

{

    effect eVFX;

    location lSelf = GetLocation(OBJECT_SELF);

    {

        int iCount=0;

        object oZap = GetFirstObjectInShape(SHAPE_SPHERE, 5.0, lSelf , TRUE, OBJECT_TYPE_ALL);

        eVFX = EffectVisualEffect(VFX_BEAM_LIGHTNING);

        while(GetIsObjectValid(oZap))

        {

            if(oZap == OBJECT_SELF)

            {

                oZap = GetNextObjectInShape(SHAPE_SPHERE, 5.0, lSelf , TRUE, OBJECT_TYPE_ALL);

                continue;

            }

            ++iCount;

            ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eVFX, oZap, 1.0);

            effect eElectric = EffectDamage(d6(2), DAMAGE_TYPE_ELECTRICAL);

            ApplyEffectToObject(DURATION_TYPE_INSTANT, eElectric, oZap);

            oZap = GetNextObjectInShape(SHAPE_SPHERE, 5.0, lSelf , TRUE, OBJECT_TYPE_ALL);

        }

        int i;

        object oRandomTarget = OBJECT_INVALID;

        for(i=0; i<(-iCount+3); i++)

        {

            oRandomTarget = CreateObject(OBJECT_TYPE_PLACEABLE, "plc_invisobj", Location(GetArea(OBJECT_SELF), RandomVector(), 0.0));

            ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eVFX, oRandomTarget, 1.0);

            SetIsDestroyable(1,0,0);

            DestroyObject(oRandomTarget, 1.0);

        }

    }

}


               
               

               
            

Legacy_KMdS!

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +0/-0
Aura Heartbeat Script
« Reply #8 on: April 29, 2016, 04:46:28 am »


               

Haha, I just tested it and realized I forgot to exclude the OBJECT SELF, I keep getting hit by the effect, hold off a bit while I fix this.


 


Edit*


 


I fixed it, works really cute, but if you want it to target everything, it will do just that. You will need to set up an exclusion set of items that won't get targeted. You'll see what I mean once you try it. ':blink:'  I set a default of up to three miscellaneous strikes should there be less than 3 bolts per heartbeat.


 


The code above is the corrected version. Have fun. '<img'>  '<img'>  '<img'>



               
               

               
            

Legacy_Imperator

  • Full Member
  • ***
  • Posts: 128
  • Karma: +0/-0
Aura Heartbeat Script
« Reply #9 on: April 29, 2016, 12:29:24 pm »


               

thank you so much!


 


coolest_thing_ever.jpg


 



That has gotta be one of the coolest things I've ever seen in nwn '<img'> I need to make a video of it! Most of the credit goes to you though, I wouldn't have been able to program that myself LOL.



               
               

               
            

Legacy_KMdS!

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +0/-0
Aura Heartbeat Script
« Reply #10 on: April 29, 2016, 02:38:49 pm »


               

HA!!! Just thought the idea was interesting. I had fun with it myself on my server and had to quit to post the work. Took an hour before I could stop.... '<img'>