Author Topic: Baby's first custom spell. guess how that went...................  (Read 377 times)

Legacy_Roddish

  • Jr. Member
  • **
  • Posts: 82
  • Karma: +0/-0


               hello, thought i'd try something easy, but it turns out i was wrong.

using a modified version of the spells_Cure funtion that i could pass oTarget to rather than have the function select it, i tried to make a "cure party" spell that would heall all players and associates in the caster's party that are in the same area as the caster.

so i started with this.

 

[quote]
void DDB_spells_PartyCure(int nDamage, int nMaxExtraDamage, int nMaximized, int vfx_impactHurt, int vfx_impactHeal, int nSpellID)
{
    object oTarget=GetFirstPC(); object oAssoc; int nAssoc;  float fDelay;
    while (GetIsObjectValid(oTarget))
    {
      if (GetArea(OBJECT_SELF)==GetArea(oTarget))
      {
        nAssoc=1; oAssoc=GetAssociate(ASSOCIATE_TYPE_ANIMALCOMPANION,oTarget);
        while (GetIsObjectValid(oAssoc))
        {
           fDelay = GetRandomDelay(0.4, 1.1);
           DelayCommand(fDelay,DDB_spells_Cure( nDamage,  nMaxExtraDamage,  nMaximized,  vfx_impactHurt,  vfx_impactHeal,  nSpellID,  oAssoc));
           nAssoc++;
           oAssoc=GetAssociate(ASSOCIATE_TYPE_ANIMALCOMPANION,oTarget,nAssoc);

        }
        nAssoc=1; oAssoc=GetAssociate(ASSOCIATE_TYPE_DOMINATED,oTarget);
        while (GetIsObjectValid(oAssoc))
        {
           fDelay = GetRandomDelay(0.4, 1.1);
           DelayCommand(fDelay,DDB_spells_Cure( nDamage,  nMaxExtraDamage,  nMaximized,  vfx_impactHurt,  vfx_impactHeal,  nSpellID,  oAssoc));
           nAssoc++;
           oAssoc=GetAssociate(ASSOCIATE_TYPE_DOMINATED,oTarget,nAssoc);

        }
        nAssoc=1; oAssoc=GetAssociate(ASSOCIATE_TYPE_FAMILIAR,oTarget);
        while (GetIsObjectValid(oAssoc))
        {
           fDelay = GetRandomDelay(0.4, 1.1);
           DelayCommand(fDelay,DDB_spells_Cure( nDamage,  nMaxExtraDamage,  nMaximized,  vfx_impactHurt,  vfx_impactHeal,  nSpellID,  oAssoc));
           nAssoc++;
           oAssoc=GetAssociate(ASSOCIATE_TYPE_FAMILIAR,oTarget,nAssoc);

        }
        nAssoc=1; oAssoc=GetHenchman(oTarget);
        while (GetIsObjectValid(oAssoc))
        {
           fDelay = GetRandomDelay(0.4, 1.1);
           DelayCommand(fDelay,DDB_spells_Cure( nDamage,  nMaxExtraDamage,  nMaximized,  vfx_impactHurt,  vfx_impactHeal,  nSpellID,  oAssoc));
           nAssoc++;
           oAssoc=GetHenchman(oTarget,nAssoc);

        }
        nAssoc=1; oAssoc=GetAssociate(ASSOCIATE_TYPE_SUMMONED,oTarget);
        while (GetIsObjectValid(oAssoc))
        {
           fDelay = GetRandomDelay(0.4, 1.1);
           DelayCommand(fDelay,DDB_spells_Cure( nDamage,  nMaxExtraDamage,  nMaximized,  vfx_impactHurt,  vfx_impactHeal,  nSpellID,  oAssoc));
           nAssoc++;
           oAssoc=GetAssociate(ASSOCIATE_TYPE_SUMMONED,oTarget,nAssoc);

        }
        fDelay = GetRandomDelay(0.4, 1.1);
        DelayCommand(fDelay,DDB_spells_Cure( nDamage,  nMaxExtraDamage,  nMaximized,  vfx_impactHurt,  vfx_impactHeal,  nSpellID,  oTarget));

      }

      oTarget=GetNextPC();
    }

}



void DDB_spells_Cure(int nDamage, int nMaxExtraDamage, int nMaximized, int vfx_impactHurt, int vfx_impactHeal, int nSpellID, object oTarget)
{
    //Declare major variables

    int nHeal;
    int nMetaMagic = GetMetaMagicFeat();
    effect eHeal, eDam;

    int nExtraDamage = GetCasterLevel(OBJECT_SELF); // * figure out the bonus damage
    if (nExtraDamage > nMaxExtraDamage)
    {
        nExtraDamage = nMaxExtraDamage;
    }
    // * if low or normal difficulty is treated as MAXIMIZED
    if(GetIsPC(oTarget) && GetGameDifficulty() < GAME_DIFFICULTY_CORE_RULES)
    {
        nDamage = nMaximized + nExtraDamage;
    }
    else
    {
        nDamage = nDamage + nExtraDamage;
    }


    //Make metamagic checks
    if (nMetaMagic == METAMAGIC_MAXIMIZE)
    {
        // 04/06/2005 CraigW - We should be using the maximized value here instead of 8.
        nDamage = nMaximized + nExtraDamage;
        // * if low or normal difficulty then MAXMIZED is doubled.
        if(GetIsPC(OBJECT_SELF) && GetGameDifficulty() < GAME_DIFFICULTY_CORE_RULES)
        {
            nDamage = nDamage + nExtraDamage;
        }
    }
    if (nMetaMagic == METAMAGIC_EMPOWER || GetHasFeat(FEAT_HEALING_DOMAIN_POWER))
    {
        nDamage = nDamage + (nDamage/2);
    }


    if (GetRacialType(oTarget) != RACIAL_TYPE_UNDEAD)
    {
        //Figure out the amount of damage to heal
        //nHeal = nDamage;  -- this line seemed kinda pointless
        //Set the heal effect
        eHeal = EffectHeal(nDamage);
        //Apply heal effect and VFX impact
        ApplyEffectToObject(DURATION_TYPE_INSTANT, eHeal, oTarget);
        effect eVis2 = EffectVisualEffect(vfx_impactHeal);
        ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis2, oTarget);
        //Fire cast spell at event for the specified target
        SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, nSpellID, FALSE));


    }
    //Check that the target is undead
    else
    {
        int nTouch = TouchAttackMelee(oTarget);
        if (nTouch > 0)
        {
            if(!GetIsReactionTypeFriendly(oTarget))
            {
                //Fire cast spell at event for the specified target
                SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, nSpellID));
                if (!MyResistSpell(OBJECT_SELF, oTarget))
                {
                    eDam = EffectDamage(nDamage,DAMAGE_TYPE_POSITIVE);
                    //Apply the VFX impact and effects
                    DelayCommand(1.0, ApplyEffectToObject(DURATION_TYPE_INSTANT, eDam, oTarget));
                    effect eVis = EffectVisualEffect(vfx_impactHurt);
                    ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oTarget);
                }
            }
        }
    }
}



[/quote]

all that happens when i activate the spell is that the caster heals. so, i tried something else. i thought i read somewhere that "player" is a faction, so i tried to catch it that way too.

[quote]
void DDB_spells_PartyCure2(int nDamage, int nMaxExtraDamage, int nMaximized, int vfx_impactHurt, int vfx_impactHeal, int nSpellID)
{
    object oTarget=GetFirstFactionMember(OBJECT_SELF,FALSE);  float fDelay;
    while (GetIsObjectValid(oTarget))
    {
         fDelay = GetRandomDelay(0.4, 1.1);
         DelayCommand(fDelay,DDB_spells_Cure( nDamage,  nMaxExtraDamage,  nMaximized,  vfx_impactHurt,  vfx_impactHeal,  nSpellID,  oTarget));
         oTarget=GetNextFactionMember(OBJECT_SELF,FALSE);
    }

}
[/quote]


....which had exactly the same result. i must be overlooking something simple here......

please halp! its getting to the point where i'm considering throwing in the towel, selling all my belongings and running off to join the circus
               
               

               
            

Legacy_Xardex

  • Sr. Member
  • ****
  • Posts: 414
  • Karma: +0/-0
Baby's first custom spell. guess how that went...................
« Reply #1 on: August 28, 2011, 11:03:30 am »


               Try setting the faction to loop through PC's only and then check for associates with GetAssociate() function.

Get__FactionMember(OBJECT_SELF,FALSE);
I remember discussing this function with someone... There was something shady about it.
               
               

               
            

Legacy_Alex Warren

  • Sr. Member
  • ****
  • Posts: 326
  • Karma: +0/-0
Baby's first custom spell. guess how that went...................
« Reply #2 on: August 28, 2011, 11:12:09 am »


               Personally I would go with:
oTarget = GetFirstObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_COLOSSAL, GetLocation(OBJECT_SELF));
    while(GetIsObjectValid(oTarget))
    {
        if(GetIsReactionTypeFriendly(oTarget) || GetFactionEqual(oTarget))
        {
DDB_spells_Cure(...)
        }
        oTarget = GetNextObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_COLOSSAL, GetLocation(OBJECT_SELF));
    }

I can't see the whole code and I can't tell what's wrong with your script, sorry
               
               

               
            

Legacy_Roddish

  • Jr. Member
  • **
  • Posts: 82
  • Karma: +0/-0
Baby's first custom spell. guess how that went...................
« Reply #3 on: August 28, 2011, 11:18:53 am »


               i considered using GetFirstObectInShape() wwhen i saw it in the Bless script, but that wouldn't work on all members in the area, would it?
               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Baby's first custom spell. guess how that went...................
« Reply #4 on: August 28, 2011, 11:30:53 am »


               This isn't for a healing spell, as the name of it shows, but it does do the same thing that you're asking about. That is, to find everyone in the PCs party in that area.

//  Party in area kill takes place get kill reward XP
void GiveXPToPartyinArea (object oPC, int nXPReward)
{
 object oArea=GetArea(oPC);
 object oTarget=GetFirstFactionMember(oPC, FALSE);
 while (GetIsObjectValid(oTarget))
    {
     if (GetArea (oTarget) == oArea) FB_GiveXP (oTarget, nXPReward);
     oTarget=GetNextFactionMember(oPC, FALSE);
    }
return;
}

Obviously, you'd want to set it up something like:

void HealParty (object oPC, int nDice, int nBonus)
{
 object oArea=GetArea(oPC);

 object oTarget=GetFirstFactionMember(oPC, FALSE);
 while (GetIsObjectValid(oTarget))
    {
     if (GetArea (oTarget) == oArea)  {} // Feed Healing Dice and bonus into your script here.
     oTarget=GetNextFactionMember(oPC, FALSE);
    }
return;
}

Or even just have the loop checked within the spell itself.  Less variables need to be passed along to other routines that way.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Baby's first custom spell. guess how that went...................
« Reply #5 on: August 28, 2011, 03:41:14 pm »


               ..
               
               

               


                     Modifié par Lightfoot8, 28 août 2011 - 02:42 .
                     
                  


            

Legacy_Roddish

  • Jr. Member
  • **
  • Posts: 82
  • Karma: +0/-0
Baby's first custom spell. guess how that went...................
« Reply #6 on: August 28, 2011, 07:14:21 pm »


               Thanks people. and thank you very much Failed.Bard.

I tried your way bard, and it worked a charm. still puzzling over why though, as far as i could see, i hadn't done that much different from yourself, save the "return". but then they were obviously different, because yours worked and mine didn't '<img'>

nice one
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Baby's first custom spell. guess how that went...................
« Reply #7 on: August 28, 2011, 07:36:52 pm »


               The return would not make the differance.   I think the main problem in your was in jumping out of the direct excution path of the cast spell event, With the use of the delayed command.   I just havent had time to trace down the exsact cause.
               
               

               
            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Baby's first custom spell. guess how that went...................
« Reply #8 on: August 29, 2011, 02:20:55 pm »


               Why not just copy the "Healing Circle" script, and adjust the amount of healing amount to your taste?  Seems like it would be a whole lot easier to me. '<img'>

You could even adjust the radius of the spell or sphere, to be HUGE, that way all "Friendlies" even remotely close to the caster get's fixed up. '<img'>
               
               

               


                     Modifié par _Guile, 29 août 2011 - 01:23 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Baby's first custom spell. guess how that went...................
« Reply #9 on: August 29, 2011, 05:10:13 pm »


               

_Guile wrote...

Why not just copy the "Healing Circle" script, and adjust the amount of healing amount to your taste?  Seems like it would be a whole lot easier to me. '<img'>

You could even adjust the radius of the spell or sphere, to be HUGE, that way all "Friendlies" even remotely close to the caster get's fixed up. '<img'>


Roddish wrote...

....all players and associates in the caster's party that are in the same area as the caster


Roddish wrote...

i considered using GetFirstObectInShape() wwhen i saw it in the Bless
script, but that wouldn't work on all members in the area, would it?


'<img'>
               
               

               


                     Modifié par GhostOfGod, 29 août 2011 - 04:10 .