I've got a rather long delay to setup. 15 minutes to be exact.
I know it's good advice to keep DelayCommands to a minimal, and short times.
What's my other options? And would someone be kind enough to show me an example?
I've got a rather long delay to setup. 15 minutes to be exact.
I know it's good advice to keep DelayCommands to a minimal, and short times.
What's my other options? And would someone be kind enough to show me an example?
If you run a pseudoheartbeat to do this, the load will be much worse than for a simple DelayCommand. The best way to do this, if it can be made to work for your situtation, is a variant of the above suggestion by Proleric. Set up a timestamping system in the module heartbeat - basically, an 'uptime' counter that increments every module heartbeat. You can add 6 to the count if you want it roughly in seconds, otherwise you can just increment by 1 for number of rounds.
When you have something you want to timestamp - that is, mark for expiration of a time period - just:
1 ) get the current uptime on the module, stored in that variable
2) store either the start of the expiry period time, or the end time you want it to expire, in terms of uptime
3) find an event that will fire before that expiry time needs to be checked, and check it there
This is a lot simpler than it sounds. Take, for example, a despawn script that clears the area, and respawns it on a delay. Let's say we don't like those delays, and want to eliminate them (they're about an hour long, and there's one for each placeable). This is a perfect sitation for a timestamp.
Why? Because we don't care about exactly when the items respawn - we just care that they respawn the next time a player enters the area, if an hour has passed. So, we use the timestamp system above, and check the timestamp on area entry. If the required amount of time has passed, we respawn right then - no delays involved - and wipe the variable indicating a respawn is due after x time.
If you can't use a timestamping setup, because there's no event to fire, just stick with simple delaycommands - they're far less intensive than using heartbeats for each delayed event.
Funky
So, just to make sure I understand...
On your heartbeat you can create a single variable on the module that increments each heartbeat. Such as like 'nRounds++' or something.
Then when I need to check one length of time against another I can, at the first interval, get the current value of nRounds, and later check in an event check that value against itself, + how many rounds have passed until I want it to happen.
Pretty elegant solution.
That's what I'm suggesting, yup. The way we do it is a bit more complicated - we check uptime against database time, for increased accuracy. It works out basically the same in terms of checking durations, though.
Take a look at this snippet for how we do this. It's the uptime variable we're dealing with here (we use the others for more esoteric purposes, like a cross-server player listing, and tracking of boot times of different instances we use to confirm who was on what server when it crashed):
hg_mod_heartbeat snippet (full code is much longer)
Funky