Author Topic: What I was wondering.....  (Read 407 times)

Legacy_Who said that I

  • Hero Member
  • *****
  • Posts: 931
  • Karma: +0/-0
What I was wondering.....
« on: October 15, 2015, 05:12:08 pm »


               

okay so here is the gig I seem to try my head around...


 


I got a questline that spawns in a certain npc that helps you get further in a certain quest....so I was wondering if it was possible to add a script that would despawn the npc if no one is in the area with the questline currently active?



               
               

               
            

Legacy_MrZork

  • Hero Member
  • *****
  • Posts: 1643
  • Karma: +0/-0
What I was wondering.....
« Reply #1 on: October 15, 2015, 08:56:17 pm »


               

There are lots of ways to do this. Many servers have similar scripts to despawn enemies from areas that the PCs have left, to reduce potential lag caused by the AI for too many NPCs hanging around when there is no one there to interact with them.


 


One approach is to have a heartbeat script for the area that runs and checks whether any PCs are in the area and, if not, despawns your quest helper NPC. I tend to worry that this approach can cause lag if too many such scripts are running all the time. And, it can complicate bookkeeping if you want to customize the despawn with a delay or a check of multiple areas or whatever.


 


Another way (one that I tend to prefer) runs on the area's OnExit event. Whenever a PC leaves the area, check if any other PCs are still in the area. If not, then despawn the helper NPC. There are some caveats about this. For one thing, it's often useful to do this in two stages. First check that no PCs are in the area and, if not, set a timer to run another check after some delay (1 minute, 5 minutes, etc.) and only despawn if there are still no PCs in the area. That way, people who leave an area and come back soon after will still find the NPCs in the same places and so on. Another potential issue when removing NPCs is to make sure that no important variables are stored on them, since those variables won't be there when they are respawned. You can also expand such a scheme to check several maps before despawning the NPC. Basically, the first script checks for PCs in several areas and, if there are none, sets up the second script.



               
               

               
            

Legacy_Who said that I

  • Hero Member
  • *****
  • Posts: 931
  • Karma: +0/-0
What I was wondering.....
« Reply #2 on: October 16, 2015, 07:36:13 pm »


               


There are lots of ways to do this. Many servers have similar scripts to despawn enemies from areas that the PCs have left, to reduce potential lag caused by the AI for too many NPCs hanging around when there is no one there to interact with them.


 


One approach is to have a heartbeat script for the area that runs and checks whether any PCs are in the area and, if not, despawns your quest helper NPC. I tend to worry that this approach can cause lag if too many such scripts are running all the time. And, it can complicate bookkeeping if you want to customize the despawn with a delay or a check of multiple areas or whatever.


 


Another way (one that I tend to prefer) runs on the area's OnExit event. Whenever a PC leaves the area, check if any other PCs are still in the area. If not, then despawn the helper NPC. There are some caveats about this. For one thing, it's often useful to do this in two stages. First check that no PCs are in the area and, if not, set a timer to run another check after some delay (1 minute, 5 minutes, etc.) and only despawn if there are still no PCs in the area. That way, people who leave an area and come back soon after will still find the NPCs in the same places and so on. Another potential issue when removing NPCs is to make sure that no important variables are stored on them, since those variables won't be there when they are respawned. You can also expand such a scheme to check several maps before despawning the NPC. Basically, the first script checks for PCs in several areas and, if there are none, sets up the second script.




 


awesome, so how would I go about doing that?


               
               

               
            

Legacy_Claiming Light

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
What I was wondering.....
« Reply #3 on: October 16, 2015, 09:33:46 pm »


               

The heartbeat script is run once every six seconds, continually. Thus, the more stuff you put into the heartbeat, the more likely the module's heart is gonna get congested with fat, which will slow processing speeds. Even for small things, its always best to avoid the heartbeat script. You are not ready for its power Padawan. 


So what to do instead? I'd write a script on the AreaTransistion trigger within the door in question. Use loop statements to cycle the GetFirstPC, GetNextPC parameters and check each PC's location against GetArea(OBJECT_SELF) for the door. If any of them come back as being in that area(excluding the instigating PC), than don't do X. Otherwise, do X.


EDIT:

Lol, I somehow missed that MrZork said the same thing in his second paragraph. His idea about waiting is a cool one, though I sorta like the idea that they instantly vanish-- like old school Nintendo after you left the room.


 


EDIT2:

An easier way to do it might be to just trigger an action for the NPC to walk toward an exit door after the conversation and, instead of having him actually use the door, have him transition to an area you've set aside for holding the things you want the game to remember, but dont want the PCs to have access to.