Interesting Timer problem.

Posted by David Berthiaume on Mon 06 Feb 2006 11:59 AM — 2 posts, 13,821 views.

#0
I use oneshot timers a lot in my scripting. Telling me when mobs repop, when it's safe to log out, things like that.

Being who I am, I was wondering if there was a way to make a timer that when there was 5 seconds left would output a count down?

Say it's a 2 minute timer, I'd like some kind of warning that the timer is about to finish.

Without having to do multiple timers to cound down the last 5 seconds, which would make for 6 timers.
#1
You could set it up with a case statement. You'd need a single variable, and of course the case statement itself. First, dim the variable (V, for simplicity) as a short. When the trigger is fired, give V the value of 120(as the number of seconds) Since you want it to do something with every second, you'll have to seperate out the seconds individually. This is where the case statement comes in. You have it select case V > 5 and have the only bit of code in there as V-=1. This is exactly the same as a do loop, until you get to the point where you need the code to act differently, hence the select case. You'd then give it a second case of V > 5 AND V < 0, and give this portion a script that displays a message on your screen, plus the value of V before doing another V-=1. Finally, V=0 or for posterity, v<1 would contain the real script you wanted it to follow, plus the command to turn off the timer so that it doesn't keep firing. It's all really simple. Now that I've said all that, here's more or less what the case system would look like in the timer. (In VB, please bear with me)


        Select Case V
            Case V > 5
                'everything above 5 seconds
                V -= 1
            Case V < 6 And V > 0
                'Your countdown (cstr is there for posterity, it's normally not needed)
                note "Time remaining: " + cstr(V)
                V -= 1
            Case V < 1
                'running the effect, and turning off the countdown
                runeffect()
                enabletimer "countdown", False
        End Select


and your trigger should have something to this effect:

setvariable "V" 120
enabletimer "countdown", true
resettimer "countdown"