Aller au contenu

Photo

Script to activate while inside a trigger?


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

#1
Xeneize

Xeneize
  • Members
  • 133 messages

As the title says, I am wondering how I can make a script to activate should some conditions be met while inside a trigger (not when first entering it).

 

What I am looking to do is for a script that will first verify if someone has a certain journal entry, and THEN if he has a certain item.

 

If these conditions are met, a new journal entry will be added.

 

Any help with this would be appreciated :)



#2
Tchos

Tchos
  • Members
  • 5 063 messages

Put a script that checks those conditions in the trigger's On Heartbeat slot.



#3
Kaldor Silverwand

Kaldor Silverwand
  • Members
  • 1 598 messages
Make sure your script only does its update once.

Regards

#4
Psionic-Entity

Psionic-Entity
  • Members
  • 195 messages

Is there a possibility of acquiring the item and/or journal entry while inside the trigger?

 

if not: Write an on entry script for the trigger that checks the journal and item ownership.

 

If it's only possible to acquire the item while in the trigger: Write an item on acquire script that uses the GetFirstSubArea/GetNextSubArea loop to check whether you're in the trigger.

 

If it's only possible to get the journal entry while in the trigger: Same thing as above but hook on to the initial journal entry.

 

If there are too many possibilities to use the above: Write one script that checks the journal entry and item, and use it in the trigger's heartbeat. If you prefer an instant method, write a single script that checks for the trigger (using the sub area loop), the journal entry, and the item, and have it run on the item acquire, on the trigger entry, and on the journal update. That way you're sure to hit it instantly when the conditions are met.



#5
rjshae

rjshae
  • Members
  • 4 497 messages

The thing to avoid is any unnecessary overhead being generated by a heartbeat script. It should only have to do the check while the target is actually in the area.



#6
Tchos

Tchos
  • Members
  • 5 063 messages

As I understand it, a trigger's heartbeat doesn't run continuously -- only while someone is within the trigger.

 

Ignore that.



#7
Psionic-Entity

Psionic-Entity
  • Members
  • 195 messages

Trigger heartbeats run continuously, you can put whatever you want in them. Standard practice is a loop over the people inside, though.



#8
Tchos

Tchos
  • Members
  • 5 063 messages

You're right.  I was mistaken.



#9
rjshae

rjshae
  • Members
  • 4 497 messages

I might do something like set a flag variable in the On Enter script when the first target enters and only then start looping through the people inside with the heartbeat script. Once there's nobody left, the flag gets cleared and the looping stops. That way the work done is minimized.



#10
Psionic-Entity

Psionic-Entity
  • Members
  • 195 messages

Checking a local flag isn't going to save you much. The "GetFirstObjectInSubArea" scripts are efficient, basically as fast as checking a local integer on the sub area.



#11
rjshae

rjshae
  • Members
  • 4 497 messages

Checking a local flag isn't going to save you much. The "GetFirstObjectInSubArea" scripts are efficient, basically as fast as checking a local integer on the sub area.

 

A routine to check whether there is an object in an area is going to have to cycle through the available objects, then check the position against the bounding box. That's much more costly compute-wise than checking an integer value. Granted, you're not going to notice much of a difference on a modern machine... unless you have many such regions in your areas, with many creatures, and the regions are all running similar heartbeat scripts.



#12
Psionic-Entity

Psionic-Entity
  • Members
  • 195 messages

Doesn't work like that, they keep a list of objects that have triggered the enter event but not the exit one.


  • rjshae aime ceci