Author Topic: Yet Another Item Problem  (Read 402 times)

Legacy_JerrodAmolyan

  • Full Member
  • ***
  • Posts: 175
  • Karma: +0/-0
Yet Another Item Problem
« on: August 11, 2013, 12:00:36 am »


                So this time the problem is repeating(Stacking) goodies when you use something. 

I'm using MJ's global weather system, and I'm trying to make items that can ward you from the intense heat penalties. So I figured I'll make a nice water bottle item, you keep drinking and you won't get blinded dazed and whatnot. But the point... yes there is one, I need help with this script, how can I get it to do the fortitude save increase once so it won't go up forever when you drink more potions ?
               
               

               


                     Modifié par JerrodAmolyan, 10 août 2013 - 11:01 .
                     
                  


            

Legacy_JerrodAmolyan

  • Full Member
  • ***
  • Posts: 175
  • Karma: +0/-0
Yet Another Item Problem
« Reply #1 on: August 11, 2013, 12:01:51 am »


               #include "x2_inc_switches"
#include "weather_inc"

void main()
{

   object oPC;

   // Abort if we're not activating the item
   if (GetUserDefinedItemEventNumber() != X2_ITEM_EVENT_ACTIVATE)
       return;

       oPC = GetItemActivator();

       object oTarget;
       oTarget = oPC;

       effect eEffect;
       eEffect = EffectSavingThrowIncrease(SAVING_THROW_FORT, 2, SAVING_THROW_TYPE_ALL);

       eEffect = SupernaturalEffect(eEffect);

       ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eEffect, oTarget, 400.0f);

           effect eLoop=GetFirstEffect(oPC);
           while (GetIsEffectValid(eLoop))
           {
           if (GetEffectType(eLoop)==EFFECT_TYPE_BLINDNESS)
              RemoveEffect(oPC, eLoop);
           if (GetEffectType(eLoop)==EFFECT_TYPE_CONFUSED)
              RemoveEffect(oPC, eLoop);
           if (GetEffectType(eLoop)==EFFECT_TYPE_ABILITY_DECREASE)
              RemoveEffect(oPC, eLoop);

              eLoop=GetNextEffect(oPC);
 }
}
               
               

               
            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Yet Another Item Problem
« Reply #2 on: August 11, 2013, 12:44:37 am »


               Have you tested it and confirmed it's stacking bonuses? The Lexicon gives the impression that script-applied saving throw bonuses don't stack.
               
               

               


                     Modifié par Squatting Monk, 10 août 2013 - 11:48 .
                     
                  


            

Legacy_JerrodAmolyan

  • Full Member
  • ***
  • Posts: 175
  • Karma: +0/-0
Yet Another Item Problem
« Reply #3 on: August 11, 2013, 12:52:04 am »


               Yep, Tested and it grants bonuses forever, which is not what I had in mind. '<img'>
               
               

               
            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Yet Another Item Problem
« Reply #4 on: August 11, 2013, 01:15:05 am »


               The simplest solution that comes to mind is setting a local int when the effect is applied, checking for it before applying effects, and deleting it at the time the effect expires:


#include "x2_inc_switches"

void main()
{
        // Abort if we're not activating the item
        if (GetUserDefinedItemEventNumber() != X2_ITEM_EVENT_ACTIVATE)
                return;

        int    nType;
        object oPC   = GetItemActivator();
        effect eLoop = GetFirstEffect(oPC);

        while (GetIsEffectValid(eLoop))
        {
                nType = GetEffectType(eLoop);

                if (nType == EFFECT_TYPE_BLINDNESS ||
                        nType == EFFECT_TYPE_CONFUSED ||
                        nType == EFFECT_TYPE_ABILITY_DECREASE)
                        RemoveEffect(eLoop);

                eLoop = GetNextEffect(oPC);
        }

        if (!GetLocalInt(oPC, "WaterBottleBonus"))
        {
                    eEffect = EffectSavingThrowIncrease(SAVING_THROW_FORT, 2);
            eEffect = SupernaturalEffect(eEffect);
                    ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eEffect, oTarget, 400.0f);
                    SetLocalInt(oPC, "WaterBottleBonus", TRUE);
       
                    // Expire after 400 seconds
                    DelayCommand(400.0, DeleteLocalInt(oPC, "WaterBottleBonus"));
        }
}

I also had some ideas about using GetEffectCreator(), but having multiple water bottles would defeat that.
               
               

               


                     Modifié par Squatting Monk, 11 août 2013 - 12:18 .
                     
                  


            

Legacy_JerrodAmolyan

  • Full Member
  • ***
  • Posts: 175
  • Karma: +0/-0
Yet Another Item Problem
« Reply #5 on: August 11, 2013, 08:35:04 am »


               Thanks, that should do the trick. '<img'> 

And indeed, this is a normal potion item, that I wanted to grant a custom spell when you drink it, no visual effects and so. (Otherwise I'd have used Ironguts) Because the climate penalties in my module are annoying if there's no way to decrease the effect when you're outside. 
               
               

               


                     Modifié par JerrodAmolyan, 11 août 2013 - 07:40 .
                     
                  


            

Legacy_JerrodAmolyan

  • Full Member
  • ***
  • Posts: 175
  • Karma: +0/-0
Yet Another Item Problem
« Reply #6 on: August 11, 2013, 08:55:45 am »


               Actually no.

11.8.2013 10:54:40: Error. 'jer_water' did not compile.
jer_water.nss(21): ERROR: DECLARATION DOES NOT MATCH PARAMETERS
               
               

               
            

Legacy_JerrodAmolyan

  • Full Member
  • ***
  • Posts: 175
  • Karma: +0/-0
Yet Another Item Problem
« Reply #7 on: August 11, 2013, 09:23:24 am »


               Ok, discovered the problems

#include "x2_inc_switches"

void main()
{
   // Abort if we're not activating the item
   if (GetUserDefinedItemEventNumber() != X2_ITEM_EVENT_ACTIVATE)
       return;

   int nType;
   object oPC = GetItemActivator();
   effect eLoop = GetFirstEffect(oPC);
   object oTarget; //Was missing targets
   oTarget = oPC;

   while (GetIsEffectValid(eLoop))
   {
       nType = GetEffectType(eLoop);

       if (nType == EFFECT_TYPE_BLINDNESS ||
           nType == EFFECT_TYPE_CONFUSED ||
           nType == EFFECT_TYPE_ABILITY_DECREASE)
           RemoveEffect(oPC, eLoop);

       eLoop = GetNextEffect(oPC);
   }

   if (!GetLocalInt(oPC, "WaterBottleBonus"))
   {
           effect eEffect; //And was missing this effect variable
           eEffect = SupernaturalEffect(eEffect);
           eEffect = EffectSavingThrowIncrease(SAVING_THROW_FORT, 2);
           ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eEffect, oTarget, 400.0f);//<-targets
           SetLocalInt(oPC, "WaterBottleBonus", TRUE);

           // Expire after 400 seconds
           DelayCommand(400.0, DeleteLocalInt(oPC, "WaterBottleBonus"));
   }
}