Author Topic: Magic Circle against Chaos  (Read 288 times)

Legacy_Ralthis

  • Jr. Member
  • **
  • Posts: 90
  • Karma: +0/-0
Magic Circle against Chaos
« on: May 21, 2011, 05:51:40 pm »


               Hi everyone,

I'm trying to script the chaos- and law-protection spells Bioware started scripting, but never finished. I've successfully modified the tlk and 2da files so that when a spellcaster chooses, say, Protection from Alignment they have the subradials for Chaos and Law protection in addition to the standard Good and Evil. So far, I have managed to get my Protection from Alignment spell to work perfectly. It's the Magic Circle against Alignment spell that's being frustrating.

I've essentially copied the code for the Magic Circle spells for Good and Evil, and modified them for Chaos to look like this:
//::///////////////////////////////////////////////
//:: Magic Circle Against Chaos
//:: NW_S0_CircChaos.nss
//:://////////////////////////////////////////////
//:: [Description of File]
//:://////////////////////////////////////////////
//:: Created By: [Your Name]
//:: Created On: [date]
//:://////////////////////////////////////////////

#include "x2_inc_spellhook"

void main()
{

/*
  Spellcast Hook Code
  Added 2003-06-23 by GeorgZ
  If you want to make changes to all spells,
  check x2_inc_spellhook.nss to find out more

*/

    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_MOB_CIRCGOOD, "nw_s0_circchaosa", "", "nw_s0_circchaosb");
    effect eVis = EffectVisualEffect(VFX_DUR_PROTECTION_GOOD_MINOR);
    effect eDur = EffectVisualEffect(VFX_DUR_CESSATE_POSITIVE);
    effect eVis2 = EffectVisualEffect(VFX_IMP_GOOD_HELP);

    effect eLink = EffectLinkEffects(eAOE, eVis);
    eLink = EffectLinkEffects(eLink, eDur);

    object oTarget = GetSpellTargetObject();
    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%
    }
    //Fire cast spell at event for the specified target
    SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, SPELL_MAGIC_CIRCLE_AGAINST_EVIL, FALSE));

    //Create an instance of the AOE Object using the Apply Effect function
    ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis2, oTarget);
    ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eLink, oTarget, HoursToSeconds(nDuration));
}

where the two sub-codes, nw_s0_circchaosa and nw_s0_circchaosb are given by:
//::///////////////////////////////////////////////
//:: Magic Cirle Against Chaos
//:: NW_S0_CircChaosA
//:://////////////////////////////////////////////
/*
    Add basic protection from chaos effects to
    entering allies.
*/
#include "NW_I0_SPELLS"

#include "x2_inc_spellhook"

void main()
{




    object oTarget = GetEnteringObject();
    if(GetIsFriend(oTarget, GetAreaOfEffectCreator()))
    {
        //Declare major variables
        int nDuration = GetCasterLevel(OBJECT_SELF);
        //effect eVis = EffectVisualEffect(VFX_IMP_GOOD_HELP);
        effect eLink = CreateProtectionFromAlignmentLink(ALIGNMENT_CHAOTIC);
        //Fire cast spell at event for the specified target
        SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, SPELL_MAGIC_CIRCLE_AGAINST_EVIL, FALSE));

        //Apply the VFX impact and effects
        ApplyEffectToObject(DURATION_TYPE_PERMANENT, eLink, oTarget);
     }
}

and

//::///////////////////////////////////////////////
//:: Magic Cirle Against Chaos
//:: NW_S0_CircChaosB
//:://////////////////////////////////////////////
/*
    Add basic protection from chaos effects to
    entering allies.
*/
//:://////////////////////////////////////////////
//:: Created On: Nov 20, 2001
//:://////////////////////////////////////////////
#include "NW_I0_SPELLS"


#include "x2_inc_spellhook"

void main()
{


    //Declare major variables
    //Get the object that is exiting the AOE
    object oTarget = GetExitingObject();
    int bValid = FALSE;
    effect eAOE;
    if(GetHasSpellEffect(SPELL_MAGIC_CIRCLE_AGAINST_EVIL, oTarget))
    {
        //Search through the valid effects on the target.
        eAOE = GetFirstEffect(oTarget);
        while (GetIsEffectValid(eAOE))
        {
            if (GetEffectCreator(eAOE) == GetAreaOfEffectCreator())
            {
                //If the effect was created by the AOE then remove it
                if(GetEffectSpellId(eAOE) == SPELL_MAGIC_CIRCLE_AGAINST_EVIL)
                {
                    RemoveEffect(oTarget, eAOE);
                }
            }
            //Get next effect on the target
            eAOE = GetNextEffect(oTarget);
        }
    }
}

I've tried messing around with the nw_s0_circchaos code so that it uses AOE_MOB_CIRCCHAOS, but the script for that doesn't work in that when you move, the magical circle literally disappears. I've also tried changing the SignalEvent option to SPELL_MAGIC_CIRCLE_AGAINST_CHAOS, with no luck there (I'm not even sure what the signal event does, but I had to keep it as SPELL_PROTECTION_FROM_GOOD/EVIL in my Protection from Alignment script in order for the latter to work).

Does anyone have any experience with these functions, or see any errors in the code?
Thanks!
               
               

               
            

Legacy_the.gray.fox

  • Full Member
  • ***
  • Posts: 214
  • Karma: +0/-0
Magic Circle against Chaos
« Reply #1 on: May 21, 2011, 06:17:21 pm »


               Hello.

The circle disappears as if the spell expired?
That is an old issue, and it affect all mobile AOE spells.
The game engine is at fault -- not you.

Solutions exist.

One solution is to prevent the problem from manifesting.
In this regard, read the Lag Busting page in the Lexicon 1.69.
Here is the path: Lexicon -> Lyceum -> Tutorial -> Toolset -> Lag Busting - How to make your server run more smoothly.
Recommended.


Another solution is to cure the problem as it manifests (I do so in my [Fox Spells] package).
But this is a last resort (to be used only if Lag Busting is not an option), and if your goal is to just reinstate a pair of spells this implies way more work than you asked for.
Not recommended.

-fox
               
               

               


                     Modifié par the.gray.fox, 21 mai 2011 - 05:32 .
                     
                  


            

Legacy_Ralthis

  • Jr. Member
  • **
  • Posts: 90
  • Karma: +0/-0
Magic Circle against Chaos
« Reply #2 on: May 21, 2011, 06:32:52 pm »


               Thanks Fox. I'll try out your system, and see how it goes!
               
               

               
            

Legacy_the.gray.fox

  • Full Member
  • ***
  • Posts: 214
  • Karma: +0/-0
Magic Circle against Chaos
« Reply #3 on: May 21, 2011, 06:36:47 pm »


               You are quite welcome.
But, did I say << Not recommended >>?
You are in for a ton of work if you wish to replicate what I implemented. Beware.

On a side note, the Law and Chaos variants are already implemented in Fox Spells.
I even drew new icons for them.

-fox
               
               

               


                     Modifié par the.gray.fox, 21 mai 2011 - 05:38 .