Aller au contenu

Photo

I've always been kinda dumb with looping


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

#1
Orion7486

Orion7486
  • Members
  • 161 messages
Could anyone point out why this script doesn't loop through the objects?

void main()
{
 object oPC = GetEnteringObject();
 int nEffect = 1;
 object oEffect = GetNearestObjectByTag("01_wp_gariuseffect", oPC, nEffect);
 location lEffect = GetLocation(oEffect);
 effect eEffect = EffectNWN2SpecialEffectFile("ajoc_12_fx_gariusshadow", oEffect);
 
 if (!GetIsPC(oPC)) return;
 int DoOnce = GetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF));
 if (DoOnce==TRUE) return;
 SetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF), TRUE);
 while(GetIsObjectValid(oEffect))
 {
     ApplyEffectAtLocation(2, eEffect, lEffect);
     oEffect = GetNearestObjectByTag("01_wp_gariuseffect", oPC,  nEffect++);
 }
}
All help is appreciated.

#2
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
Try it like this:

void main()
{
    object oPC = GetEnteringObject();
    if (!GetIsPC(oPC)) return;
    int DoOnce = GetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF));
    if (DoOnce==TRUE) return;

    int nEffect = 1;
    object oEffect = GetNearestObjectByTag("01_wp_gariuseffect", oPC, nEffect);
    location lEffect = GetLocation(oEffect);
    effect eEffect = EffectNWN2SpecialEffectFile("ajoc_12_fx_gariusshadow", oEffect);

    SetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF), TRUE);
    while(GetIsObjectValid(oEffect))
    {
        ApplyEffectAtLocation(2, eEffect, lEffect);
        nEffect++;
        oEffect = GetNearestObjectByTag("01_wp_gariuseffect", oPC, nEffect);
    }
}


You want to advance nEffect before you redefine oEffect. Also it is a good habbit to put your return statements in before declaring all your major variables. No sense in putting them into memory if you don't need to.

Hope it helps. Good luck.

#3
Orion7486

Orion7486
  • Members
  • 161 messages
Thanks for the response, but it still is placing the effect on only one object.

#4
Shallina

Shallina
  • Members
  • 1 011 messages
GetNearestObjectByTag("01_wp_gariuseffect", oPC, nEffect);will always give you the same object I am afraid.

#5
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
Actually I think its because the location is never getting changed. I was thinking object. Try it like so and see if it helps:


void main()
{
    object oPC = GetEnteringObject();
    if (!GetIsPC(oPC)) return;
    int DoOnce = GetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF));
    if (DoOnce==TRUE) return;

    int nEffect = 1;
    object oEffect = GetNearestObjectByTag("01_wp_gariuseffect", oPC, nEffect);
    location lEffect;
    effect eEffect;

    SetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF), TRUE);
    while(GetIsObjectValid(oEffect))
    {
        eEffect = EffectNWN2SpecialEffectFile("ajoc_12_fx_gariusshadow", oEffect);
        lEffect = GetLocation(oEffect);
        ApplyEffectAtLocation(2, eEffect, lEffect);
        nEffect++;
        oEffect = GetNearestObjectByTag("01_wp_gariuseffect", oPC, nEffect);
    }
}

P.S. I don't normally script for NWN2 so Im not familiar with that type of effect you are using. I see its asking for an object parameter. Hopefully that is not messing things up.

Modifié par GhostOfGod, 02 février 2011 - 12:25 .


#6
Orion7486

Orion7486
  • Members
  • 161 messages
That's got it. Defining the location within the loop makes it work. Thank you.