Author Topic: More basic questions about coding - creating a function/effect  (Read 731 times)

Legacy_Imperator

  • Full Member
  • ***
  • Posts: 128
  • Karma: +0/-0


               

So I'm trying to create a function/new effect which will have a set duration based on the caster's caster level.


 


The effect will basically recast the same spell on the caster every six seconds while the effect lasts. The thing is I'm such a novice coder that I don't know how to go about doing this. :S And I'm very unfamiliar with making my own functions.


 


I'm modifying invisibility spells so that, when under certain conditions(Character has illusion spell focus feats), the spell will add this second effect, and automatically recast itself unless of course purged or dispelled.



               
               

               
            

Legacy_Imperator

  • Full Member
  • ***
  • Posts: 128
  • Karma: +0/-0
More basic questions about coding - creating a function/effect
« Reply #1 on: April 23, 2016, 02:21:48 am »


               

This is basically what I made so far..  it's very clunky, and doesn't even seem to work that effectively the first time I cast it (invis doesn't reapply) but it does seem to work with a second casting >.> ...


 


Can anyone help me to optimize this so it works properly and less clunkily?


 


 


 



#include "x2_inc_spellhook"

void RecastInvisSphere();

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 including Area of Effect Object

    effect eAOE = EffectAreaOfEffect(AOE_PER_INVIS_SPHERE);

    int nDuration = GetCasterLevel(OBJECT_SELF);

    int nMetaMagic = GetMetaMagicFeat();



    //Make sure duration does no equal 0

    if (nDuration < 1)

    {

        nDuration = 1;

    }

    //Check Extend metamagic feat.

    if (nMetaMagic == METAMAGIC_EXTEND)

    {

       nDuration = nDuration *2;    //Duration is +100%

    }

    //Create an instance of the AOE Object using the Apply Effect function

    ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eAOE, OBJECT_SELF, TurnsToSeconds(nDuration));



    //************************* NEW CODE 4/22/2016******************************

    int HasSFIlu = GetHasFeat(FEAT_SPELL_FOCUS_ILLUSION, OBJECT_SELF);

    int HasGSFIlu = GetHasFeat(FEAT_GREATER_SPELL_FOCUS_ILLUSION, OBJECT_SELF);

    int HasESFIlu = GetHasFeat(FEAT_EPIC_SPELL_FOCUS_ILLUSION, OBJECT_SELF);



    effect eMarker = EffectCurse(0, 0, 0, 0, 0, 0);

    int HasMarker = GetHasEffect(EFFECT_TYPE_CURSE, OBJECT_SELF);


    if(HasSFIlu && HasGSFIlu && HasESFIlu)

    {

    ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eMarker, OBJECT_SELF, TurnsToSeconds(nDuration));

        if(HasMarker == TRUE)

        {

        RecastInvisSphere();

        }

    }

   //************************* NEW CODE 4/22/2016******************************


}





    //************************* NEW CODE 4/22/2016******************************

void RecastInvisSphere()

{


    effect eAOE = EffectAreaOfEffect(AOE_PER_INVIS_SPHERE);

    int nDuration = GetCasterLevel(OBJECT_SELF);

    effect eInvis = EffectInvisibility(EFFECT_TYPE_INVISIBILITY);



    ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eInvis, OBJECT_SELF, TurnsToSeconds(nDuration));

    ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eAOE, OBJECT_SELF, TurnsToSeconds(nDuration));



int HasMarker = GetHasEffect(EFFECT_TYPE_CURSE, OBJECT_SELF);


if(HasMarker == TRUE)

    {

    DelayCommand(6.0, RecastInvisSphere());

    }


}

    //************************* NEW CODE 4/22/2016******************************

 



               
               

               
            

Legacy_Terrorble

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
More basic questions about coding - creating a function/effect
« Reply #2 on: April 23, 2016, 05:41:52 am »


               

I don't have a complete answer but a few comments.


 


 





 
#include "x2_inc_spellhook"

void RecastInvisSphere();

void main()

{
/*
//effect EffectAreaOfEffect(int nAreaEffectId, string sOnEnterScript="", string sHeartbeatScript="", string sOnExitScript="")

This function creates a invisibility sphere AOE and defines what scripts
fire when you enter/exit it - unless you specify otherwise.

nw_s0_invspha & nw_s0_invsphb determine what happens when you enter/exit
an invis sphere.
So later you don't have to apply your own invis effect 
because the OnEnter script applies invis when the AOE is recreated.
*/ 

    effect eAOE = EffectAreaOfEffect(AOE_PER_INVIS_SPHERE);

    int nDuration = GetCasterLevel(OBJECT_SELF);

    int nMetaMagic = GetMetaMagicFeat();



    if (nDuration < 1)

    {

        nDuration = 1;

    }

    if (nMetaMagic == METAMAGIC_EXTEND)

    {

       nDuration = nDuration *2;

    }

    ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eAOE, OBJECT_SELF, TurnsToSeconds(nDuration));



    //************************* NEW CODE 4/22/2016******************************

    int HasSFIlu = GetHasFeat(FEAT_SPELL_FOCUS_ILLUSION, OBJECT_SELF);

    int HasGSFIlu = GetHasFeat(FEAT_GREATER_SPELL_FOCUS_ILLUSION, OBJECT_SELF);

    int HasESFIlu = GetHasFeat(FEAT_EPIC_SPELL_FOCUS_ILLUSION, OBJECT_SELF);

/* 
If you use henchmen the AI might try to repeatedly try to cast restoration
or remove curse to fix your negative effect.

I've never tried using a curse as a marker but I know acid arrow tracks
a VFX for validity to determine if it should continue running. Seems okay
*/
    effect eMarker = EffectCurse(0, 0, 0, 0, 0, 0);

    int HasMarker = GetHasEffect(EFFECT_TYPE_CURSE, OBJECT_SELF);



    if(HasSFIlu && HasGSFIlu && HasESFIlu)

    {

    ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eMarker, OBJECT_SELF, TurnsToSeconds(nDuration));
/* 
You don't need to check the marker here because the only way you
RecastInvisSphere() is if you have all the spell focus feats.

So apply the marker and call the recast function but leave out the
if-statement.
*/ 
    if(HasMarker == TRUE)

        {

        RecastInvisSphere();

        }

    }

   //************************* NEW CODE 4/22/2016******************************



}









    //************************* NEW CODE 4/22/2016******************************

void RecastInvisSphere()

{



    effect eAOE = EffectAreaOfEffect(AOE_PER_INVIS_SPHERE);

    int nDuration = GetCasterLevel(OBJECT_SELF);

    effect eInvis = EffectInvisibility(EFFECT_TYPE_INVISIBILITY);


/*
Every 6 seconds you apply this effect for caster level turns.
So the duration never goes down until the curse effect finally expires.
I think you want to apply it for 6 seconds each time while the curse
effect exists. Applying eInvis is extraneous unless you aren't using nw_s0_invspha
*/
    ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eInvis, OBJECT_SELF, TurnsToSeconds(nDuration));

    ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eAOE, OBJECT_SELF, TurnsToSeconds(nDuration));





int HasMarker = GetHasEffect(EFFECT_TYPE_CURSE, OBJECT_SELF);



if(HasMarker == TRUE)

    {

    DelayCommand(6.0, RecastInvisSphere());

    }



}

    //************************* NEW CODE 4/22/2016******************************




Reapplying an invis effect every 6 seconds is quite good against anything that can't see invis.  I toyed with it once as a short duration phase spell.  If I cast this on myself and attack someone I'll break invis when I make my first attack.  After a round I'll become invis again until my first attack breaks the invis effect. If the opponent can't see invis they will go flat footed each time.



               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
More basic questions about coding - creating a function/effect
« Reply #3 on: April 23, 2016, 08:04:40 am »


               

Apply an AOE on the caster if they have the proper focus, and have that reapply the invis effect in the AOEs HB script.  It's far more efficient that way than a pseudo-HB, and still allows for the effect to be dispelled normally.



               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
More basic questions about coding - creating a function/effect
« Reply #4 on: April 23, 2016, 10:41:23 am »


               


Apply an AOE on the caster if they have the proper focus, and have that reapply the invis effect in the AOEs HB script.  It's far more efficient that way than a pseudo-HB, and still allows for the effect to be dispelled normally.




It is not actually. AOEs are causing lot of lags. They doesn't move with owner realiably and more.


 


Its better to use pseudo HB.


               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
More basic questions about coding - creating a function/effect
« Reply #5 on: April 23, 2016, 08:29:08 pm »


               


Reapplying an invis effect every 6 seconds is quite good against anything that can't see invis.  I toyed with it once as a short duration phase spell.  If I cast this on myself and attack someone I'll break invis when I make my first attack.  After a round I'll become invis again until my first attack breaks the invis effect. If the opponent can't see invis they will go flat footed each time.




 


 


Why not just use INVISIBILITY_TYPE_IMPROVED (not the spell improved invisibility)?  This will keep you continually invisible.


               
               

               
            

Legacy_Terrorble

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
More basic questions about coding - creating a function/effect
« Reply #6 on: April 24, 2016, 01:15:28 am »


               


It is not actually. AOEs are causing lot of lags. They doesn't move with owner realiably and more.


 


Its better to use pseudo HB.




I saw once where someone stored the aura AOE object on the player and every few seconds had a pseudo-HB check if the location of the aura AOE object and the player were the same, if they weren't it would move the aura to the player's location.  But at the time I didn't think it worked very well.  What's the best way to keep the aura with the player?


 




Why not just use INVISIBILITY_TYPE_IMPROVED (not the spell improved invisibility)?  This will keep you continually invisible.




Honestly, I had no idea that that's what that invis type did.  I assumed it meant you retained concealment after breaking invis.  Neat!