View Single Post
Old 04-17-2005, 06:03 AM   #4
Legolas
Jack Burton
 

Join Date: March 31, 2001
Location: The zephyr lands beneath the brine.
Age: 40
Posts: 5,459
There are a few ways to do that, but loops will of course have an effect on your module's performance.

One method is using the DelayCommand(10.0,ExecuteScript("scriptname")); command at the end of your script. This makes it fire 10.0 seconds after it last ran. You can change the value of course.
The danger here is that the script may keep running even when there are no players in the area, so you'd have to build in a check that stops the script when the player leaves. This could be on (a trigger by) the area's exit, or a check of PCs in the area. The latter is less efficient, but the OnAreaExit script does not run when a player logs off in the area so it may be necessary depending on whether the mod is single- or multiplayer, and if you're telling a story or creating a world for player characters to 'live' in and pick their own directions.

A second method is using the area's or the creature's heartbeat script. This makes the script fire every, roughly, 6 seconds but only if a player is in the area. You can script it not to fire every other turn of course, making it every 12 seconds if that's more convenient.

A third is delaying commands within the script and using a 'while' condition. This also comes with a built-in safety in that you can set the script not to loop more than, say, 50 or 100 times. In the other cases, it's the player leaving that terminates the operation.

You might also set up a series of triggers, each of them firing the script, which make the wizard retry as the player draws closer. That might give trouble with players running vs walking though, or standing still for that matter.

Short of the latter, heartbeat would likely be your best choice

Something else to take into account is that multiple players entering can start the script off several times, when you only want it to run once per howevermany seconds. Check for that too.
Finally, don't make the script run if the wizard is dead.

[ 04-17-2005, 06:04 AM: Message edited by: Legolas ]
Legolas is offline   Reply With Quote