Aller au contenu

Photo

A very efficient way to disable ambient NPC activity when PC is not in area.


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

#1
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
I have one area that has a moderate amount of ambience and I want to turn it off when the PC is not there.  The script runs from the heartbeat of a single creature in the area.  I was thinking I would just put in some code to check if the PC is in the same area as the creature and if FALSE, then return, otherwise, run the script.

Is there a better or safer way?  Or do you think this will be okay?

#2
Shallina

Shallina
  • Members
  • 1 011 messages
heartbat from blueprint are not runned if the area isn't the activ area I think.

heartbat from the area /module are running all the time.

Modifié par Shallina, 24 février 2011 - 09:31 .


#3
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
That's what I thought too, but when I was testing, and left the area with the ambient HB script, I started getting debug messages about action queue overflow for the objects which are affected by the HB script. This makes me think that perhas the script is running, giving commands, but the creatures are not executing them. It really didn't affect performance, but the PC's dialogue box was full of debug messages and it was messy. This is what I'm trying to fix.

#4
MasterChanger

MasterChanger
  • Members
  • 686 messages
The creature heartbeat script (nw_c2_default1) has an immediate check for  AI_LEVEL_VERY_LOW. I haven't been able to figure out where this flag is set on creatures, but I've found through testing that within one-two rounds of a PC exiting an area, all creatures in that area get this flag. This check is essentially an implementation derived from the same principle you mention above (no PC being in the area).

You mention that the script runs from an HB script of a single creature. For some reason, default1 is one of the few creature event scripts that doesn't check for a string var and ExecuteScript. I recommend creating an override version of default1 that does have this call. If you aren't using default1 and your HB script doesn't have the AI check I mentioned above, you could run into problems, as you've found.

#5
_Knightmare_

_Knightmare_
  • Members
  • 643 messages
Many of the other default NPC scripts have a check that will return out if the AI is VERY_LOW. So, OnPerception scripts won't run (for example) unless there is a PC in the area - which then elevates the AI to above VERY_LOW. Area HB scripts fire even if there is no PC in the area at the time. Add in your "if PC not in area return out" check to the Area HB script if you have one.

I had a situation where I wanted NPCs to be moving about in another area that the PC wasn't currently in. Had to periodically force their AI to a higher level to make them do stuff.

#6
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
Thanks for the responses. I'm using a custom HB script and I put in the check, but I still periodically get. Action queue overflow for two specific objects. I added in a line of code to clear their actions if PC is not in the area. Haven't tested it yet.

#7
Kaldor Silverwand

Kaldor Silverwand
  • Members
  • 1 598 messages
Usually I do the GetAILevel(OBJECT_SELF) == AI_LEVEL_VERY_LOW check in the heartbeat event (1001) section of the ud script. Seems like it should work in either place though.

#8
M. Rieder

M. Rieder
  • Members
  • 2 530 messages

Kaldor Silverwand wrote...

Usually I do the GetAILevel(OBJECT_SELF) == AI_LEVEL_VERY_LOW check in the heartbeat event (1001) section of the ud script. Seems like it should work in either place though.


I'm not familiar with the UD script. 

#9
Kaldor Silverwand

Kaldor Silverwand
  • Members
  • 1 598 messages
User defined script. In the spawn script of a creature you specify which events should fire for that creature (or use a local variable to specify). The standard events have assigned numbers (heartbeat is 1001) but you also create your own. Then in the ud script assigned to the creature you handle all of the events. It is an alternative way to handle events rather than having a set of event scripts.



Regards

#10
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
Oh, I understand. That sounds quite useful. Thanks!

#11
PJ156

PJ156
  • Members
  • 2 986 messages

M. Rieder wrote...

Oh, I understand. That sounds quite useful. Thanks!


Hmmm, wish I did Image IPB

#12
Morbane

Morbane
  • Members
  • 1 883 messages
UD scripts give me trouble. I dont like them and they dont like me.

#13
Kaldor Silverwand

Kaldor Silverwand
  • Members
  • 1 598 messages
A little more explanation.



When you spawn a creature it can be set to listen for certain events in its spawnscript. The heartbeat is one of the events a creature can listen for. The standard event values range from 1001-1008 and include Heartbeat, Perceive, Combat Round, Dialogue, Attack, Damaged, Death, and Disturbed. These are flags in the spawnscript that control whether these events are heard by the creature or not. There is a variable you can set on the creature that the standard spawnscript will use, but I prefer to use my own more readable variable names and a custom spawn script (bb_setspawnflags_sp in King's Festival).



If a creature is listening for these events then a ud script can be used to respond to the events. So basically, instead of having a heartbeat script and a death script for a creature you can have a single ud script that contains the code for handling both events.



More useful though is that you can also send your own user-defined events and trap them with the ud script. So, as an example, in my area heartbeat scripts at nightfall and daybreak the local NPCs are sent a unique event code 2999 which their ud script handles by making them take out a torch or put one away. It is just a coding alternative to having the time checking logic in each NPC heartbeat script.



Regards