Jump to content

[HELP] Mission with timer


Ryuto

Recommended Posts

I am creating a mission system and my question is how to create a timer for a mission, in short it is a mission against the clock. For example, each player has 5 minutes to finish it and if the counter reaches 0, cancel the entire mission function to simulate that you totally failed. I don't know what functions to use to achieve this.

 

Thanks!

Link to comment

Well, you have a couple options

1) A single timer using setTimer, generally the duration is not modifiable after it's been created but you can get current remaining time and set a new one with a different time if necessary. The callback is triggered when the timer runs out.

2) A timer set using setTimer that triggers every second (1000ms period) and increments or decrements a variable of how many seconds passed or are remaining, respectively; this way you get to change time remaining without having to deal with new timers (but this may be a bit more resource-hungry than the option above). Use the timer's callback and compare it against the remaining time to determine if the timer elapsed.

3) Use the missontimer resource packed with default MTA resources, as used by gamemodes like the default deathmatch. Using that you can abstract most of the internal timers and how to change durations using them, instead get exported functions that deal with it; and it takes care of rendering for you. onMissionTimerElapsed is triggered when the time runs out.

When it comes to options 1 and 2, you need to render the remaining time yourself. Ideally, the server should have an authoritative timer while clients get a very close approximation through data sending using triggerClientEvent and triggerServerEvent. Clients should only have math that controls the display of the timer, not the actual timer.

Edited by Addlibs
  • Thanks 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...