Author Topic: Disalbe all encounters in an area...  (Read 347 times)

Legacy_Cursed Eclipse

  • Full Member
  • ***
  • Posts: 132
  • Karma: +0/-0
Disalbe all encounters in an area...
« on: March 29, 2014, 06:43:51 pm »


               

Disalbe all encounters in an area......i've found a function able to do this work.


My goal is to disable ALL the encounters present in an area when certain conditions occur.



void DisableEncountersInArea(object oArea)
    {
     object oEncounter = GetFirstInPersistentObject(oArea, OBJECT_TYPE_ENCOUNTER);
     while (GetIsObjectValid(oEncounter))
        {
         SetEncounterActive(TRUE, oEncounter);
         oEncounter = GetNextInPersistentObject(oArea, OBJECT_TYPE_ENCOUNTER);
        }
    }
//here my code:
void main()
{
if (GetIsPC(GetEnteringObject()))
  {
  object area = GetArea(OBJECT_SELF);
  DisableEncountersInArea(area);
  }
}

(Like Lexicon suggest, the encounter is set to single shoot)


 


 


i put that script on enter of a generic trigger ,but didn't work.

Then,i tried with OnEnter of an area,but also this attempt was a failure.


 


so I tried to change a bit:



void main()
{
object oPC = GetEnteringObject();
object area = GetArea(oPC);
DisableEncountersInArea(area);
}


but it does not work the same. The encounters were still disabled.


 


 


 


I know there are other methods to activate-disable encounters,but i was pretty sure that the function is correct .Where i'm wrong?



               
               

               
            

Legacy_Terrorble

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
Disalbe all encounters in an area...
« Reply #1 on: April 02, 2014, 06:57:45 pm »


               

Rather than use GetFirstInPersistentObject(), use GetFirstObjectInArea() and GetNextObjectInArea().


 


Also, inside your "while" statement, make sure the object you have is an encounter before trying to set it active.


 


Like this:


 


if( GetObjectType(oEncounter) == OBJECT_TYPE_ENCOUNTER ) 


{


then set it active


}


oEncounter = GetNextObjectInArea(oArea);



               
               

               
            

Legacy_Cursed Eclipse

  • Full Member
  • ***
  • Posts: 132
  • Karma: +0/-0
Disalbe all encounters in an area...
« Reply #2 on: April 02, 2014, 09:00:21 pm »


               

Thx for the tips



void main()
{
object oArea = GetArea(OBJECT_SELF);
object oEncounter = GetFirstObjectInArea(oArea);
 if( !GetIsObjectValid( oArea) || (GetArea( oArea) != oArea)) return;
  if (GetObjectType(oEncounter) == OBJECT_TYPE_ENCOUNTER)
   {
   SetEncounterActive(TRUE,oEncounter);
    }
    oEncounter = GetNextObjectInArea(oArea);
    }
//not tested yet




 





but I was left with the curiosity about


GetFirstInPersistentObject


what wrong with that function? is broken?



               
               

               
            

Legacy_Terrorble

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
Disalbe all encounters in an area...
« Reply #3 on: April 03, 2014, 12:20:03 am »


               
You're close with your code.  I'll retype how I typically do this sort of thing with the while loop.  As long as the GetFirst and GetNext functions pass a valid object, the while loop continues thru everything in the area.

 

void main()

{

  object oArea = GetArea(OBJECT_SELF);

  object oEncounter = GetFirstObjectInArea(oArea);

 

  while( GetIsObjectValid(oEncounter) )

  {

    if( GetObjectType(oEncounter) == OBJECT_TYPE_ENCOUNTER )

    {

      SetEncounterActive(TRUE,oEncounter);

    }

   oEncounter = GetNextObjectInArea(oArea);

  }

}

//**I typed this directly here, so hopefully it compiles and I didn't make any typographical errors.

  

 

 

// Get the first object within oPersistentObject.

// - oPersistentObject

// - nResidentObjectType: OBJECT_TYPE_*

// - nPersistentZone: PERSISTENT_ZONE_ACTIVE. [This could also take the value

//   PERSISTENT_ZONE_FOLLOW, but this is no longer used.]

// * Returns OBJECT_INVALID if no object is found.

 

GetFirstInPersistentObject() is used for AoE (area of effect) spells.  I know it seems like the area object would be classified as a persistent object, but it isn't used this way.

 

EffectAreaOfEffect() creates a persistent object.  For example, when you cast entangle, it uses this function.  Then entangle uses GetFirstInPersistentObject() to start cycling through objects within the entangle area of effect.