Author Topic: Spawn Cleaning Script not actually destroying creatures?  (Read 429 times)

Legacy_lluewhyn

  • Newbie
  • *
  • Posts: 34
  • Karma: +0/-0
Spawn Cleaning Script not actually destroying creatures?
« on: August 09, 2015, 04:42:21 pm »


               

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



}



               
               

               
            

Legacy_JediMindTrix

  • Sr. Member
  • ****
  • Posts: 383
  • Karma: +0/-0
Spawn Cleaning Script not actually destroying creatures?
« Reply #1 on: August 09, 2015, 06:42:48 pm »


               

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.



               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Spawn Cleaning Script not actually destroying creatures?
« Reply #2 on: August 09, 2015, 10:35:50 pm »


               The formatting tags are (code) ... (/code) with square brackets. The (spoiler) ... (/spoiler) tags can be used to improve legibility by hiding the code detail.
               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Spawn Cleaning Script not actually destroying creatures?
« Reply #3 on: August 09, 2015, 10:42:58 pm »


               Are the creatures destroyable?


http://www.nwnlexico...e=DestroyObject
               
               

               
            

Legacy_lluewhyn

  • Newbie
  • *
  • Posts: 34
  • Karma: +0/-0
Spawn Cleaning Script not actually destroying creatures?
« Reply #4 on: August 10, 2015, 12:14:44 am »


               

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?



               
               

               
            

Legacy_JediMindTrix

  • Sr. Member
  • ****
  • Posts: 383
  • Karma: +0/-0
Spawn Cleaning Script not actually destroying creatures?
« Reply #5 on: August 10, 2015, 01:22:53 pm »


               

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.



               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Spawn Cleaning Script not actually destroying creatures?
« Reply #6 on: August 10, 2015, 01:54:14 pm »


               

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.



               
               

               
            

Legacy_lluewhyn

  • Newbie
  • *
  • Posts: 34
  • Karma: +0/-0
Spawn Cleaning Script not actually destroying creatures?
« Reply #7 on: August 11, 2015, 01:31:05 am »


               

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


}


               
               

               
            

Legacy_Krevett

  • Full Member
  • ***
  • Posts: 203
  • Karma: +0/-0
Spawn Cleaning Script not actually destroying creatures?
« Reply #8 on: August 11, 2015, 09:11:53 am »


               

Here's the code I was using a while ago



   Spoiler