Author Topic: Despawn-spawn script?  (Read 1074 times)

Legacy_Who said that I

  • Hero Member
  • *****
  • Posts: 931
  • Karma: +0/-0
Despawn-spawn script?
« on: May 01, 2016, 08:21:02 pm »


               

Is there a despawn spawn script? Or would anyone be willing to write one for me? Basically I want a script that despawns a spawned encounter after 5 minutes. Just so the module will not be so strained by all the spawned that will be spawned by sneakers, runners, etc


 


thanks beforehand guys '<img'> 


 



               
               

               
            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
Despawn-spawn script?
« Reply #1 on: May 01, 2016, 10:40:43 pm »


               

Ooo - Brain ache '<img'> . Would you care to break that down into simple steps of what you want to achieve and when you want it please. Hint just think of it like telling a teacher/lecturer the answer to "how do you do that?" where you have to assume the teacher/lecturer is an idiot just to get a pass mark.


 


TR



               
               

               
            

Legacy_KMdS!

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +0/-0
Despawn-spawn script?
« Reply #2 on: May 02, 2016, 12:05:25 am »


               


Ooo - Brain ache '<img'> . ....


 


TR




ROFL..... ':lol:'


 


Anyway,


I believe I have an old spawn/despawner a friend of mine, Interslayer, created many, many years ago. It was a relatively simple but powerfully effective system. I don't think it exists anywhere anymore...... will post it when I find it. It is not on the machine I am on right now. Sometime tonight.


 


I don't use it as I have my own more developed system, but it was a very good system, and still is.



               
               

               
            

Legacy_LoA_Tristan

  • Jr. Member
  • **
  • Posts: 64
  • Karma: +0/-0
Despawn-spawn script?
« Reply #3 on: May 02, 2016, 02:28:00 am »


               Replace nw_c2_default1 with this. Oh Cruel World

 
void main()
{
   if (GetIsEncounterCreature())
   {
      int nAge = GetLocalInt(OBJECT_SELF, "MY_AGE");
      if (nAge < 300) SetLocalInt(OBJECT_SELF, "MY_AGE", nAge+1);
      else DestroyObject(OBJECT_SELF);
   }
}

               
               

               
            

Legacy_KMdS!

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +0/-0
Despawn-spawn script?
« Reply #4 on: May 02, 2016, 03:24:25 am »


               

@LoA_Tristan


 


Will that despawn the creatures whether there players are in the area or not? Some sort of check for players in the area might be needed?



               
               

               
            

Legacy_Who said that I

  • Hero Member
  • *****
  • Posts: 931
  • Karma: +0/-0
Despawn-spawn script?
« Reply #5 on: May 02, 2016, 05:19:34 am »


               


Ooo - Brain ache '<img'> . Would you care to break that down into simple steps of what you want to achieve and when you want it please. Hint just think of it like telling a teacher/lecturer the answer to "how do you do that?" where you have to assume the teacher/lecturer is an idiot just to get a pass mark.


 


TR




 


wHAT DO i WANT:


 


1)Character spawns encounter


 


2) Encounter will wait 5 minutes before it will despawn due to inactivity from action/battle


 


When do I want it:


yesterday? '<img'>


               
               

               
            

Legacy_KMdS!

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +0/-0
Despawn-spawn script?
« Reply #6 on: May 02, 2016, 05:26:35 am »


               

If it is as simple as that, then LoA_Tristan's code will work. I wouldn't necessarily replace nw_c2_default1, rather put it in a seperate script and perform an EXECITESCRIPT on the OBJECT_SELF from within nw_c2_default1 or merge the code.



               
               

               
            

Legacy_LoA_Tristan

  • Jr. Member
  • **
  • Posts: 64
  • Karma: +0/-0
Despawn-spawn script?
« Reply #7 on: May 02, 2016, 03:13:54 pm »


               @KMdS

I wonder if area heartbeats are regarded as less resource intensive for these encounter systems?
pros: not as many heartbeats, sensitive to player location
cons: more expensive heartbeats, always active

@Who said that I
When you start talking about inactivity you might need scripts in extra places like CombatRound in addition to heartbeat, on every creature spawned in the module
here's what an area hb could look like.
// EVERY AREA'S HEARTBEAT
void PurgeHeretics(object oArea);
void main()
{
     object oArea = OBJECT_SELF;
     object oPC = GetFirstPC();  // if one of the PCs is in the area, stop
     while GetIsObjectValid(oPC)
     {
          if (GetArea(oPC) == oArea)
          {
               SetLocalInt(oArea, "IDLE", 0);
               return;
          }
          oPC = GetNextPC();
     }
     int nIdle = GetLocalInt(oArea, "IDLE"); // otherwise check area's idle rounds
     if (nIdle < 50) SetLocalInt(oArea, "IDLE", nIdle+1); // either increment # rounds,
     else PurgeHeretics(oArea); // or delete encounter creatures
}
void PurgeHeretics(object oArea)
{
     SetLocalInt(oArea, "IDLE", 0);
     object oGuy = GetFirstObjectInArea(oArea);
     while (GetIsObjectValid(oGuy))
     {
          if (GetIsEncounterCreature(oGuy)) DestroyObject(oGuy);
          oGuy = GetNextObjectInArea(oArea);
     }
}

               
               

               
            

Legacy_KMdS!

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +0/-0
Despawn-spawn script?
« Reply #8 on: May 02, 2016, 04:37:59 pm »


               

@LoA_Tristan


 


Since hb event fires no matter what. What impacts the server is having to perform extensive and or repetitive work. Since some work must always be done, or nothing would ever change ant there would be no game, what you want to do is make sure that that any process required is performe as neatly and in as few instances as possible.


 


That said, the area events would be the most efficient place to create a code to perform the duty requested.


 


Here is a layout of what you need to do.


  • On the area enter event, script a variable that gets incremented every time a pc enters.

  • On the Exit area event have the variable decremented.

  • Have the area HB event run a time for x number of heartbeats where it checks to see if any pc's are in the area by checking the variable set in the enter/exit events...no looping searches.

  • If a pc enters the area before the termination timer executes, have the counter reset cause we can keep the spawns if a pc is there. 

  • Otherwise, despawn all spawns and have the timer reset.

There are a few more things you can put in for checking the system, and also an additional variable could be set to stop the timer after a despawn until needed again, a pc reenters an area. Also you should run a check at long intervals on the hb event top perform a loop to verify that the variable for pc's in the area is correct.


 


This would mean that only one set of events would process the work, not multiple events like on individual spawns using the default_1



               
               

               
            

Legacy_Who said that I

  • Hero Member
  • *****
  • Posts: 931
  • Karma: +0/-0
Despawn-spawn script?
« Reply #9 on: May 03, 2016, 07:42:39 am »


               

From what I read the PC should have left the area cause the HB script is checking if the PC is still in the area. Personally was just looking for a script that does not search the entire area but just stops but then that might just be my very limited understanding of scripting....and also why I asked someone to help me with this.



               
               

               
            

Legacy_KMdS!

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +0/-0
Despawn-spawn script?
« Reply #10 on: May 03, 2016, 09:10:56 pm »


               

Ok, had a moment and crated a simple despawner. you could easily use this as a template to include an area cleanup. You can merge this into your own area hb, enter, exit event scripts, or you can just place and ExecuteScript on the area.


 


Here they are.


// k_on_area_enter.nss
 
void main()
{
    int nPCCount = GetLocalInt(OBJECT_SELF, "PC_COUNT");
    object oObject = GetEnteringObject();
    if(GetIsPC(oObject))
        SetLocalInt(OBJECT_SELF, "PC_COUNT", ++nPCCount);
}
 

// k_on_area_exit.nss
 
void main()
{
    int nPCCount = GetLocalInt(OBJECT_SELF, "PC_COUNT");
    object oObject = GetExitingObject();
    if(GetIsPC(oObject))
        SetLocalInt(OBJECT_SELF, "PC_COUNT", --nPCCount);
}
 

// k_area_hb.nss
 
void main()
{
    int bPROCESS_ONLY_ENCOUNTER_SPAWNS = TRUE;
 
    string sTag = GetTag(OBJECT_SELF);
    int nIteration = GetLocalInt(OBJECT_SELF, "ITERATION_"+sTag);
    int nPCCount = GetLocalInt(OBJECT_SELF, "PC_COUNT");
    if(nPCCount==FALSE)
    {
        if(nIteration<50)
            SetLocalInt(OBJECT_SELF, "ITERATION_"+sTag, ++nIteration);
        // destroy only encounter spawns
        else if(bPROCESS_ONLY_ENCOUNTER_SPAWNS)
        {
            object oCreature = GetFirstObjectInArea();
            while(oCreature != OBJECT_INVALID)
            {
                if(GetIsEncounterCreature(oCreature))
                {
                    AssignCommand(oCreature, SetIsDestroyable(1,0,0));
                    DestroyObject(oCreature);
                }
                oCreature = GetNextObjectInArea();
            }
        }
        // destroy all creatures, not just encounter spawns
        else
        {
            object oCreature = GetFirstObjectInArea();
            while(oCreature != OBJECT_INVALID)
            {
                if(GetObjectType(oCreature) == OBJECT_TYPE_CREATURE)
                {
                    AssignCommand(oCreature, SetIsDestroyable(1,0,0));
                    DestroyObject(oCreature);
                }
                oCreature = GetNextObjectInArea();
            }
        }
    }
    //ERROR-Reset the PC count
    else if(nPCCount<0)
    {
        nPCCount = 0;
        object oPC = GetFirstPC();
        while(oPC != OBJECT_INVALID)
        {
            if(GetArea(oPC) == OBJECT_SELF)
                ++nPCCount;
            oPC = GetNextPC();
        }
        SetLocalInt(OBJECT_SELF, "PC_COUNT", nPCCount);
    }
    // PC's are in the area, reset the iteration count
    else
    {
        if(nIteration)
            SetLocalInt(OBJECT_SELF, "ITERATION_"+sTag, 0);
    }
}

               
               

               
            

Legacy_LoA_Tristan

  • Jr. Member
  • **
  • Posts: 64
  • Karma: +0/-0
Despawn-spawn script?
« Reply #11 on: May 03, 2016, 11:12:57 pm »


               

From what I read the PC should have left the area cause the HB script is checking if the PC is still in the area. Personally was just looking for a script that does not search the entire area but just stops but then that might just be my very limited understanding of scripting....and also why I asked someone to help me with this.

I don't know whether you read my two proposals but I'm not scanning through any areas. #8 checks PCs directly to see if a PC's current area matches the area calling the heartbeat.


@KMdS
regarding k_on_area_enter.nss and k_on_area_exit.nss - I hope I don't sound like a curmudgeon, but these will run on every object entering an area. That is rather involved. At least for the sake of one task. I could see implementing these events if we were setting up a system with a bunch more tasks, though.
               
               

               
            

Legacy_KMdS!

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +0/-0
Despawn-spawn script?
« Reply #12 on: May 04, 2016, 01:11:10 am »


               

Oh no, your fine. I posted this as exactly what the creator of the thread requested, but this is extremely low impact coding......super extremely low.


 


Events get called whether you run code or not. The engine just does it as part of its hard coded job. Every time something enters or exits causes the events to fire. It will loop to see if there are any event scripts for all objects having an slot for a script. The fact that something enters or spawns into the area is the main hit on the server, the additional code I posted creates a very minute additional burden.


 


You are right, though, when you state that you could see implementing these events if we were setting up a system with a bunch more tasks. I believe good code allows for expansion of possibilities. They could easily be a part of a larger spawn/despawn system.


 


On a final note, there is the good possibility that the code will need to handle a spawns loot so that it doesn't get dropped on the creatures destruction, littering up the landscape with easy pickins. It all depends on who the spawns drops are handled. If need so, just ;let me know and I can insert the needed code.



               
               

               
            

Legacy_Who said that I

  • Hero Member
  • *****
  • Posts: 931
  • Karma: +0/-0
Despawn-spawn script?
« Reply #13 on: May 07, 2016, 03:49:28 pm »


               

thanks everyone and sorry if I misunderstood anyone in the previous posts but I really do appreciate all of the input given here.  Will have a look through everything and try to get it all fixed. 


 


Thanks again for all your help guys I really do appreciate it '<img'>



               
               

               
            

Legacy_Arkshadra

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
Despawn-spawn script?
« Reply #14 on: May 09, 2016, 01:26:06 am »


               

Besie sytem is great for that.