Hello.
100% of the people I've seen coding dungeons or making time-based events of any sort handled `Time remaining` notices like this:
- when devilcatacomb_45m_left_timer.server_timer begin
- if d.select(get_server_timer_arg()) then
- d.notice(string.format(gameforge.devilcatacomb_zone._20_say, 45))
- server_timer('devilcatacomb_30m_left_timer', 60 * 15, get_server_timer_arg())
- end
- end
- when devilcatacomb_30m_left_timer.server_timer begin
- if d.select(get_server_timer_arg()) then
- d.notice(string.format(gameforge.devilcatacomb_zone._20_say, 30))
- server_timer('devilcatacomb_15m_left_timer', 60 * 15, get_server_timer_arg())
- end
- end
- when devilcatacomb_15m_left_timer.server_timer begin
- if d.select(get_server_timer_arg()) then
- d.notice(string.format(gameforge.devilcatacomb_zone._20_say, 15))
- server_timer('devilcatacomb_5m_left_timer', 60 * 10, get_server_timer_arg())
- end
- end
- when devilcatacomb_5m_left_timer.server_timer begin
- if d.select(get_server_timer_arg()) then
- d.notice(string.format(gameforge.devilcatacomb_zone._20_say, 5))
- server_timer('devilcatacomb_1m_left_timer', 60 * 4, get_server_timer_arg())
- end
- end
- when devilcatacomb_1m_left_timer.server_timer begin
- if d.select(get_server_timer_arg()) then
- d.notice(string.format(gameforge.devilcatacomb_zone._20_say, 1))
- server_timer ("devilcatacomb_0m_left_timer", 60 * 1, get_server_timer_arg())
- end
- end
- when devilcatacomb_0m_left_timer.server_timer begin
- if d.select(get_server_timer_arg()) then
- d.notice (gameforge.devilcatacomb_zone._210_dNotice)
- d.set_warp_location (65, 5914, 992)
- server_timer('devilcatacomb_exit_timer', 7, get_server_timer_arg())
- end
- end
This is not entirely their fault, sadly Webzen isn't exactly capable of setting a good example of how to do things right in Python, C++ and -of course- Lua.
This way of doing things is very limited, initializing a new timer for every notice they wanna make is not a very efficient way of dealing with the matter.
Naturally, you could implement the Official Zodiac's way of handling Time remaining, by overriding the Minimaps' interface with a new interface that has a built-in timer which works via python-quest communication, but shouldn't that be available for you, then you can do this:
First things first, we'll need a single server timer, which will be of the loop type, and it will handle both the `Time remaining` notices and the actions for when the time expires.
For simplicity purposes, I'll make an example for the dungeons.
Now, we can either set up two full-scope variables, or defines:
Or, we can make an array that stores the information within a function, like this:
Note that functions initialized inside quests are not global: they are only valid within their scope - the state they get initialized in.
For this example, I'll make use of the first of the 2 methods I just showed you.
Now, we got 2 elements:
- time_out, which is our time limit.
- time_out_step, which will be the interval in seconds in-between triggers of our server loop timer.
We'll use them like this:
We have bound a timer to our dungeon instance and set it to trigger once every `time_out_step` seconds;
This allows us to control the interval between `Time remaining` notices by changing the `time_out_step` element as we like.
Now all that remains is to set our timer's trigger and make use of `time_out` and `time_out_step`, the full example code would look like this:
Alternatively, instead of using the `seconds_passed` flag like I'm doing (the way I showed you is more understandable and thus more proper since this is an example), you can initialize a single flag to register the starting time and make use of get_time() in between triggers.
And there you have it, full control in a single timer for your time remaining notices.