Author Topic: Need to Verify Area Clean Script is Good  (Read 779 times)

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
Need to Verify Area Clean Script is Good
« on: July 22, 2010, 06:14:40 pm »


               I use to use the old script "ag_area_clean" created by Allen Guile on the old Paths of Ascension Module, however, I felt like it was outdated, because sometimes, when a PC logged out the area would stay spawned...  (Major Lagg!)

So, I created a new area clean script specifically for hostile areas (or Areas Where Monsters Spawn)


This Script goes on the OnEnter Event of an Area... (make sure this is good)

//scriptname: check_area_oe
///////////////////////////////////////////
//Created by: Genisys (Guile)
//Created On: 7/18/2010
///////////////////////////////////////////
/*          ///NOTES///
 When a PC enters an area, this script will
 check to see first if the area has been
 cleaned (empty), if not, it will start
 checking every X minutes (Set Below)
 to verify the area is in fact clean,
 IF NO PCs are Present ONLY!
*/
///////////////////////////////////////////
//////IMPORTANT SETTING//////////
//Set this to how often you wish the
//script to fire to check the area..
//This script refires itself (While active)
float CHECK_INTERVAL = 60.0;  //Default = 60.0 (60 seconds / or 1 Minute)
//////////////////////////////////////////
//Main Script
void main()
{
 object o = GetEnteringObject();
 object oArea = GetArea(o);
 int nCheck = GetLocalInt(oArea, "CLEAN_CHECK");
//
 if(!GetIsPC(o) || GetIsDM(o) || GetIsDMPossessed(o))
 { return; } //Stop the whole script if it's NOT a Player entering..
//
  if(nCheck != TRUE) //If this is our first time checking the area...
  {
   SetLocalInt(oArea, "CLEAN_CHECK", TRUE); //Set that we are checking the area
   //Start the checking process now..
   DelayCommand(CHECK_INTERVAL, ExecuteScript("check_area_spawn", oArea));
  }
//
//
//End Void Main Script
}


And This script is the script that is fired by the above script (On the area that started the firing of this script)

(Please make sure there are no errors in this script either, to verify we have a great script to use, all of us)

//scriptname: check_area_spawn
///////////////////////////////////////////
//Created by: Genisys (Guile)
//Created On: 7/18/2010
///////////////////////////////////////////
/*          ///NOTES///
   This script is fired from the script
   "area_check_oe"  which basically is
   a looping script which fires this script
   every so often to verify the area is
   in fact clean, to prevent lagg!
*/
///////////////////////////////////////////
//Important Settings
//
//Set this to TRUE if you want to remove all items in
//PLACEABLE OBJECTS (Remains dropped by monsters are always cleaned)
const int nClearPlaceInv = FALSE;  //Default = FALSE (Don't clean inventories)
//
//Set the float below to the amount of time (in seconds) you want the
//Area to recheck to see if the PCs are gone.. (To begin cleaning the area)
const float CHECK_INTERVAL = 60.0; // Default = 60.0 (60 seconds or 1 minute)
//
////////////////////////////////////////
////////////////////////////////////////////////////////
//////WARNING: DON'T TOUCH ANYTHING BELOW THIS LINE!!!!
///////////////////////////////////////////////////////
///////////////////////////////////////
//Required Horse Include
#include "x3_inc_horse"
//
//Declare Prototypes
int nPC(object oArea);
void CleanArea(object oArea);
//
//Main Script
void main()
{
 object oArea = OBJECT_SELF;
 int nA = nPC(oArea); //Is a PC Present?
//
 //If no PCs are in the area, clean it!
 if(nA == FALSE)
 {
  CleanArea(oArea);
  SetLocalInt(oArea, "CLEAN_CHECK", FALSE);//Tell the first script area is clean!
 }
 else
 {
  //Otherwise continue to loop this script till area is clean..
  //This is set to 60 seconds, you can increase this..
  DelayCommand(CHECK_INTERVAL, ExecuteScript("check_area_spawn", OBJECT_SELF));
 }
//
//Main Script End
}
//
//Define Prototype
int nPC(object oArea)
{
 object oMon;
 int nType;
 int a = TRUE;  //Tell the script here is NO PC Present, clean the area!
//
 oMon = GetFirstObjectInArea(oArea);
 while(GetIsObjectValid(oMon))
 {
   if(GetIsPC(oMon))
   {
    a = FALSE; //A PC is present, DON'T CLEAN THE AREA YET!
   }
  oMon = GetNextObjectInArea(oArea);
 }
  return a; //Tell the main script what to do..
//
//Main Script End
}
//
//////////////////////////////////////////////////////////////////
//Prototype
//Custom Function for cleaning up the area, taken from ag_area_clean
//Created by Allen Guile from the AW Team from Paths of Ascension
void CleanArea(object oArea)
{
  object oTrash = GetFirstObjectInArea(oArea);
  object oInvItem;
//
   while(GetIsObjectValid(oTrash))
   {
     string sTag = GetTag(oTrash);
     string sTagPrefix = GetStringLeft(GetTag(oTrash), 15);
     // Clear remains, dropped items ALWAYS
     if(GetObjectType(oTrash)==OBJECT_TYPE_ITEM ||
        GetStringLowerCase(GetName(oTrash)) == "remains")
        {
          AssignCommand(oTrash, SetIsDestroyable(TRUE));
          if (GetHasInventory(oTrash))
          {
            oInvItem = GetFirstItemInInventory(oTrash);
            while(GetIsObjectValid(oInvItem))
            {
              DestroyObject(oInvItem,0.0);
              oInvItem = GetNextItemInInventory(oTrash);
            }
          }
          else DestroyObject(oTrash, 0.0);
      }
//
      // Clear placeable inventories(IF Set to do so at the top of script)
      if(GetObjectType(oTrash)==OBJECT_TYPE_PLACEABLE &&
         nClearPlaceInv == TRUE)
      {
        if (GetHasInventory(oTrash))
        {
          object oInvItem = GetFirstItemInInventory(oTrash);
          while(GetIsObjectValid(oInvItem))
          {
            DestroyObject(oInvItem,0.0);
            oInvItem = GetNextItemInInventory(oTrash);
          }
        }
      }
//
      else if (GetIsEncounterCreature(oTrash) ||
               sTagPrefix == "PWFSE_SPAWNERID")
      {
        AssignCommand(oTrash, SetIsDestroyable(TRUE));
        DestroyObject(oTrash, 0.0);
      }
//
      // If it's a mountable creature!
      else if (HorseGetIsAMount(oTrash))
      {
       //If the mount has no master!
       if(HorseGetOwner(oTrash)== OBJECT_INVALID)
       {
        AssignCommand(oTrash, SetIsDestroyable(TRUE));
        DestroyObject(oTrash, 0.0);
       }
      }
//
//
     oTrash = GetNextObjectInArea(oArea);
   }
//
//Prototype End
}

Thanks a bunch 4 your help.   'Posted


EDITED: Revised 7_23_2010 = Finished & Tested Script  'Posted
               
               

               


                     Modifié par Genisys, 24 juillet 2010 - 01:16 .
                     
                  


            

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
Need to Verify Area Clean Script is Good
« Reply #1 on: July 22, 2010, 09:40:53 pm »


               I found an error on my part...



When the PC enters the area, they despawn the monster spawned (if they leave and come back or a new pc enters the area)



Anyone have a suggestion how I should go about fixing this?
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Need to Verify Area Clean Script is Good
« Reply #2 on: July 23, 2010, 02:57:50 am »


               use rather OnExit for cleaning purposes, + like 2minutes delay before despawning monsters

I mean when last PC exits area, clean remains/etc and then run 2minutes delayed function which checks if there is no PC around and if not, it will despawn monsters actually



Another suggestion is to not despawn monsters, but while there are no players, set them AI to AI_LOW, its said it helps but its not proofed.



Or before cleaning them, set their HP and position (maybe feats as well but that would be heavy) and when first player came into area recreate them again, damage to get them to desired HP and decrease their feat/spell count if you like.
               
               

               
            

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
Need to Verify Area Clean Script is Good
« Reply #3 on: July 24, 2010, 02:11:28 am »


               The problem ShaDoOow is, as I stated above, sometimes people log out, and the "OnExit" event doesn't fire for some reason, so using OnExit is an issue...  (Don't know why, sorry)



The revised script above works accurately, I've been testing it, so I'm happy with the OnEnter event rather than the OnExit, because of that one issue...