Aller au contenu

Photo

Disalbe all encounters in an area...


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

#1
Cursed Eclipse

Cursed Eclipse
  • Members
  • 70 messages

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?



#2
Terrorble

Terrorble
  • Members
  • 194 messages

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);



#3
Cursed Eclipse

Cursed Eclipse
  • Members
  • 70 messages

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?



#4
Terrorble

Terrorble
  • Members
  • 194 messages
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.