Aller au contenu

Photo

Yet Another Item Problem


  • Veuillez vous connecter pour répondre
7 réponses à ce sujet

#1
JerrodAmolyan

JerrodAmolyan
  • Members
  • 89 messages
 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 .


#2
JerrodAmolyan

JerrodAmolyan
  • Members
  • 89 messages
#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);
}
}

#3
Squatting Monk

Squatting Monk
  • Members
  • 446 messages
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 .


#4
JerrodAmolyan

JerrodAmolyan
  • Members
  • 89 messages
Yep, Tested and it grants bonuses forever, which is not what I had in mind. :P

#5
Squatting Monk

Squatting Monk
  • Members
  • 446 messages
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 .


#6
JerrodAmolyan

JerrodAmolyan
  • Members
  • 89 messages
Thanks, that should do the trick. :) 

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 .


#7
JerrodAmolyan

JerrodAmolyan
  • Members
  • 89 messages
Actually no.

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

#8
JerrodAmolyan

JerrodAmolyan
  • Members
  • 89 messages
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"));
}
}