[HowTo] Dynamically handle `Time remaining` notices in Quests

  • Hello.

    100% of the people I've seen coding dungeons or making time-based events of any sort handled `Time remaining` notices like this:


    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:

    1. time_out, which is our time limit.
    2. 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.

    My Lua Questing service:

    Bitte melden Sie sich an, um diesen Link zu sehen.

  • Syreldar

    Hat den Titel des Themas von „Dynamically handle `Time remaining` notices in Quests“ zu „[HowTo] Dynamically handle `Time remaining` notices in Quests“ geändert.