Author Topic: Applying damage immunities OnRest, OnClientEnter and OnLevelUp  (Read 339 times)

Legacy_Terrorble

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
Applying damage immunities OnRest, OnClientEnter and OnLevelUp
« on: December 16, 2013, 06:59:02 am »


                I want to add some class specific damage immunities/vulnerabilities (e.g. I moved fire immunity for RDD class to level20 and give them 5% fire immunity per level), but I am experiencing some unexpected stacking.  

When I log out/in or rest, I find that the damage immunity has been added twice.  At level9 RDD, I should have 45% fire immunity.  When I first log in, this is true - I resist 4 out of 10 fire damage.  If I rest, or log out/in, I'll have 90%.  If I do it again, I'll have >100%.  I cannot figure out why my script is not removing the effects before applying them again. Or, more importantly, how to do this correctly.  Am I misusing GetEffectCreator()?

So, in my  OnClientEnter, OnRest (REST_FINISHED_EVENT), OnLevelUp events I include this:

ExecuteScript("classbonuses",oPC);

In "classbonuses" I have this:

void main()
{
  object oPC = OBJECT_SELF;
  object oCB = GetObjectByTag("CLASSBONUS");//placeable in the mod marked as plot and usable

  //Before applying any new effects, clear the previous ones  
  effect e = GetFirstEffect(oPC);

  while( GetIsEffectValid(e) )
   {
        if( GetEffectCreator(e) == oCB ) {           //I should add, I never see this message, but I can't see what I'm doing wrong
            SendMessageToPC(oPC,"class bonus effect removed");//DEBUG
            RemoveEffect(oPC,e);
        }
    e = GetNextEffect(oPC);   
  }

int nRDD = GetLevelByClass(CLASS_TYPE_DRAGONDISCIPLE,oPC);
if( nRDD > 0  && nRDD < 20 )
{
            eFire = EffectDamageImmunityIncrease(DAMAGE_TYPE_FIRE,nRDD*5);
 
          AssignCommand(oCB,ApplyEffectToObject(DURATION_TYPE_PERMANENT,eFire,oPC));
}
}
               
               

               
            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
Applying damage immunities OnRest, OnClientEnter and OnLevelUp
« Reply #1 on: December 16, 2013, 10:36:34 am »


               That code wouldn't even compile -- eFire is never actually declared as an effect.

Second, can you try changing


eFire = EffectDamageImmunityIncrease(DAMAGE_TYPE_FIRE,nRDD*5);
 
          AssignCommand(oCB,ApplyEffectToObject(DURATION_TYPE_PERMANENT,eFire,oPC));

to

AssignCommand(oCB,ApplyEffectToObject(DURATION_TYPE_PERMANENT,
  EffectDamageImmunityIncrease(DAMAGE_TYPE_FIRE,nRDD*5),oPC));

and see what happens?
               
               

               


                     Modifié par MagicalMaster, 16 décembre 2013 - 10:36 .
                     
                  


            

Legacy_Terrorble

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
Applying damage immunities OnRest, OnClientEnter and OnLevelUp
« Reply #2 on: December 16, 2013, 03:58:33 pm »


               

MagicalMaster wrote...

That code wouldn't even compile -- eFire is never actually declared as an effect.


Oops, somewhere in formatting the post I deleted "effect".

Second, can you try changing


eFire = EffectDamageImmunityIncrease(DAMAGE_TYPE_FIRE,nRDD*5);
 
          AssignCommand(oCB,ApplyEffectToObject(DURATION_TYPE_PERMANENT,eFire,oPC));

to

AssignCommand(oCB,ApplyEffectToObject(DURATION_TYPE_PERMANENT,
  EffectDamageImmunityIncrease(DAMAGE_TYPE_FIRE,nRDD*5),oPC));

and see what happens?


Thanks, Magical Master!  Moving the effect creation inside the AssignCommand() fixed it.  I see now, that declaring the effect outside of the AssignCommand() makes the effect creator whoever is calling the script, not the placeable.  I had read as much, but apparently did not appreciate the significance of it.
               
               

               
            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
Applying damage immunities OnRest, OnClientEnter and OnLevelUp
« Reply #3 on: December 16, 2013, 10:04:12 pm »


               Yeah.  Alternatively, for a more complex effect, something like this works...

void DoBuff(int nRDD, object oPC);

void main()
{
    object oPC = OBJECT_SELF;
    object oCB = GetObjectByTag("CLASSBONUS");//placeable in the mod marked as plot and usable

    //Before applying any new effects, clear the previous ones
    effect e = GetFirstEffect(oPC);

    while( GetIsEffectValid(e) )
    {
        if( GetEffectCreator(e) == oCB ) {
            //I should add, I never see this message, but I can't see what I'm doing wrong
            SendMessageToPC(oPC,"class bonus effect removed");//DEBUG
            RemoveEffect(oPC,e);
        }
        e = GetNextEffect(oPC);
    }

    int nRDD = GetLevelByClass(CLASS_TYPE_DRAGONDISCIPLE,oPC);
    if( nRDD > 0  && nRDD < 20 )
    {
        AssignCommand(oCB,DoBuff(nRDD, oPC));
    }
}

void DoBuff(int nRDD, object oPC)
{
    effect eFire = EffectDamageImmunityIncrease(DAMAGE_TYPE_FIRE,nRDD*5);
    ApplyEffectToObject(DURATION_TYPE_PERMANENT,eFire,oPC);
}

And if you changed the line from

AssignCommand(oCB,DoBuff(nRDD, oPC));

to

AssignCommand(oCB,DoBuff(nRDD, OBJECT_SELF));

then the effect would be applied to oCB -- since it becomes OBJECT_SELF within the AssignCommand.