Aller au contenu

Photo

Spawn Cleaning Script not actually destroying creatures?


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

#1
lluewhyn

lluewhyn
  • Members
  • 17 messages

I've been having frustrations with a spawn cleaning script that's not actually been working. I've included a message to try to debug it, but it's still not working! After 10 minutes of leaving an area, I'll get a message from every encounter creature there that they have been destroyed, but nothing actually is happening to them! It's also not completing, because ten minutes later, the script is firing again.

 

Obviously, the function I've created is triggering, but the Destroy Object part is not. Can anyone tell me what I'm doing wrong? Since it's only destroying Encounter Creatures, any other objects in the area are probably keeping the script looping, but that isn't explaining why things aren't dying. Also, please let me know the shortcut for putting the following script in its own textbox on the forum /nwscript or whatever:

 

void CleanSpawn(object oArea =OBJECT_SELF)
    {
    if(GetIsPCInArea( oArea))
        {
        return;
        }

    object oObject = GetFirstObjectInArea( oArea);
    while( GetIsObjectValid( oObject))
     {
        if( GetIsEncounterCreature( oObject) && !GetPlotFlag( oObject) && !GetImmortal( oObject))
             {
             string sName =GetName(oObject);
             DestroyObject( oObject, 0.1f);
             SendMessageToAllDMs(sName+" has been destroyed by the Spawn Cleaner!");
             }
     oObject = GetNextObjectInArea( oArea);
     }
    }
// Area OnExit main function.
void main()
{
  object oExiting = GetExitingObject();
  object oExplore= OBJECT_SELF;
  //if( !GetIsObjectValid( oExiting)) return;
  // Schedule the area cleaner.
  ExploreAreaForPlayer(oExplore, oExiting); 
  DelayCommand(610.0, CleanSpawn());


}



#2
JediMindTrix

JediMindTrix
  • Members
  • 283 messages

According to the lexicon, the timer for DestroyObject doesn't start ticking until the script it is called from is finished. If it is somehow looping, as you say, this might be why.



#3
Proleric

Proleric
  • Members
  • 2 354 messages
The formatting tags are (code) ... (/code) with square brackets. The (spoiler) ... (/spoiler) tags can be used to improve legibility by hiding the code detail.

#4
Proleric

Proleric
  • Members
  • 2 354 messages
Are the creatures destroyable?

http://www.nwnlexico...e=DestroyObject
  • Squatting Monk aime ceci

#5
lluewhyn

lluewhyn
  • Members
  • 17 messages

JediMindTrix, this is the conclusion I came up with as well, that the loop is somehow never finishing. I'll try a few things to fix it. If that doesn't work, does anyone have an existing encounter spawn cleaner that will do the trick?



#6
JediMindTrix

JediMindTrix
  • Members
  • 283 messages

I would add some SendMessageToPC commands after each seperate command, with different messages, to see exactly what is happening. This will how far the script is going, if it's even triggering, if it's stuck in a loop, etc.


  • Squatting Monk aime ceci

#7
meaglyn

meaglyn
  • Members
  • 811 messages

The script is not stuck in a loop.  NWN protects itself against that by limiting the number of instruction any script execution can run. You'll get a TMI  (too many instructions) error and the script will end.  

 

As Proleric was asking, if the SendMessageToAllDMs is going off, then the creature should be destroyed unless it's not destroyable.

 

You may want to limit the code in your onExit main routine to only run for PCs:

if (!GetIsPC(oExiting))  return;

instead of the commented out GetIsObjectValid line, for example.


  • Squatting Monk aime ceci

#8
lluewhyn

lluewhyn
  • Members
  • 17 messages

Thanks, I'll try that. Here is the code now (by the way, the ExploreAreaForPlayer is a piggyback function to help mark that a player has fully explored an area once they've left it).

 

 
void CleanSpawn(object oArea =OBJECT_SELF)
    {
    if(GetIsPCInArea( oArea))
        {
        return;
        }

    object oObject = GetFirstObjectInArea( oArea);
    while( GetIsObjectValid( oObject))
     {
        if( GetIsEncounterCreature( oObject) && !GetPlotFlag( oObject) && !GetImmortal( oObject))
             {
             string sName =GetName(oObject);
             SetIsDestroyable(TRUE,FALSE, FALSE);
             DestroyObject( oObject, 0.1f);
             SendMessageToAllDMs(sName+" has been destroyed by the Spawn Cleaner!");
             }
     oObject = GetNextObjectInArea( oArea);
     }
    }
// Area OnExit main function.
void main()
{
  object oExiting = GetExitingObject();
  object oExplore= OBJECT_SELF;
  if( !GetIsPC( oExiting)) return;
  // Schedule the area cleaner.
  ExploreAreaForPlayer(oExplore, oExiting); 
  DelayCommand(610.0, CleanSpawn());


}


#9
Krevett

Krevett
  • Members
  • 104 messages

Here's the code I was using a while ago

Spoiler