Resource:Missiontimer: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 23: Line 23:


There are also some other exported functions that you may or may not need:
There are also some other exported functions that you may or may not need:
<syntaxhighlight lang="lua">  
 
setMissionTimerTime ( missionTimer, time ) --Sets the countdown/countup target time
<syntaxhighlight lang="lua">setMissionTimerTime ( missionTimer, time )</syntaxhighlight>
getMissionTimerTime ( missionTimer ) --Gets the number currently on the clock
Sets the countdown/countup target time (in milliseconds)
setMissionTimerFrozen ( missionTimer, frozen )   --Freeze the timer
 
isMissionTimerFrozen ( missionTimer )
<syntaxhighlight lang="lua">getMissionTimerTime ( missionTimer )</syntaxhighlight>
</syntaxhighlight>
Gets the number currently showing on the clock (in milliseconds)
 
<syntaxhighlight lang="lua">setMissionTimerFrozen ( missionTimer, frozen )</syntaxhighlight>
Sets the timer to frozen (true) or normal (false)
 
<syntaxhighlight lang="lua">isMissionTimerFrozen ( missionTimer )</syntaxhighlight>
See if the timer is frozen
 
<syntaxhighlight lang="lua">setMissionTimerHurryTime ( missionTimer, time )</syntaxhighlight>
Set the time that the clock will turn red (in milliseconds) (ie: to indicate there is not much time left)
 
 
To remove a missiontimer from the screen, use [[destroyElement]].
To remove a missiontimer from the screen, use [[destroyElement]].




Missiontimer is only compatible with MTASA 1.0 onwards.
Missiontimer is only compatible with MTASA 1.0 onwards.

Revision as of 18:52, 11 August 2010

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)
    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.


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)


To remove a missiontimer from the screen, use destroyElement.


Missiontimer is only compatible with MTASA 1.0 onwards.