Resource:Missiontimer

From Multi Theft Auto: Wiki
Revision as of 16:32, 16 August 2010 by R3mp (talk | contribs)
Jump to navigation Jump to search

Missiontimer is a resource used to easily create timers that count down or up in your resources.

Overview

The "deathmatch" gamemode is an example use of missiontimer. It uses the "createMissionTimer" function to create a timer, and then the onMissionTimerElapsed event to trigger at the end:

    g_MissionTimer = exports.missiontimer:createMissionTimer (g_TimeLimit,true,true,0.5,20,true,"default-bold",1,"Time left: ")
    addEventHandler ( "onMissionTimerElapsed", g_MissionTimer, onTimeElapsed )
 

Then you use the onTimeElapsed function that you attached to the handler at the end of the timer.

The arguments for createMissionTimer as follows:

createMissionTimer ( duration, countdown, showCS, x, y, bg, font, scale )
  • duration - The time in milliseconds
  • countdown - A bool of whether to countdown or count up. Setting it to true will count down from the duration, setting it to false will count up to the duration (latter isnt tested yet)
  • showCS - A bool of whether to show Centiseconds. true shows them, false hides them. Showing centi seconds means its in the format of MM:SS:CS (e.g. 12:31:10), hiding them means its in the format of MM:SS (12:31)
  • x,y - Position on the screen, this uses "smart positioning". It can be relative or absolute - the deathmatch gamemode creates it at 0.5,20. This means the x value is in the centre, the y is 20pixels from the top. If you specify a negative value it draws the other way, i.e. -20 would be 20pixels from the bottom rather than the top. The same can be done for x.
  • bg - Whether to draw the default rounded-rectangle behind the timer. Setting this to false will hide it
  • font - The font of the timer. Looks best in default-bold
  • scale - The size of the text/bg.
  • prefix - Any text that you want to show in front of the time (eg: Time left: 00:00). Leave this blank for no text


There are also some other exported functions that you may or may not need:

setMissionTimerTime ( missionTimer, time )

Sets the countdown/countup target time (in milliseconds)

getMissionTimerTime ( missionTimer )

Gets the number currently showing on the clock (in milliseconds)

setMissionTimerFrozen ( missionTimer, frozen )

Sets the timer to frozen (true) or normal (false)

isMissionTimerFrozen ( missionTimer )

See if the timer is frozen

setMissionTimerHurryTime ( missionTimer, time )

Set the time that the clock will turn red (in milliseconds) (ie: to indicate there is not much time left)

setMissionTimerPrefix ( missionTimer, prefix )

Set the prefix text on the timer


To remove a missiontimer from the screen, use destroyElement.


Missiontimer is only compatible with MTASA 1.0 onwards.