Resource:Missiontimer: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
 
(3 intermediate revisions by one other user not shown)
Line 6: Line 6:
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:
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:


<syntaxhighlight lang="lua">    g_MissionTimer = exports.missiontimer:createMissionTimer (g_TimeLimit,true,true,0.5,20,true,"default-bold",1)
<syntaxhighlight lang="lua">    g_MissionTimer = exports.missiontimer:createMissionTimer (g_TimeLimit,true,"%m:%s",0.5,20,true,"default-bold",1,255,255,255)
     addEventHandler ( "onMissionTimerElapsed", g_MissionTimer, onTimeElapsed )
     addEventHandler ( "onMissionTimerElapsed", g_MissionTimer, onTimeElapsed )
  </syntaxhighlight>
  </syntaxhighlight>
Line 12: Line 12:


The arguments for createMissionTimer as follows:
The arguments for createMissionTimer as follows:
<syntaxhighlight lang="lua">createMissionTimer ( duration, countdown, showCS, x, y, bg, font, scale )</syntaxhighlight>
<syntaxhighlight lang="lua">createMissionTimer ( duration, countdown, format, x, y, bg, font, scale, r, g, b )</syntaxhighlight>
* duration - The time in milliseconds
* 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)
* 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)
* format - A string detailing the format of the timer text to be shown. You can chose whether to show minutes, seconds or centiseconds using these 3 strings:
** %m - minutes
** %s - seconds
** %cs - centiseconds
This allows you to add normal text onto the timer as well as showing the time left (eg: "Time left: %m:%s")
* 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.
* 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
* 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
* font - The font of the timer.  Looks best in default-bold
* scale - The size of the text/bg.
* scale - The size of the text/bg.
* r,g,b - The red/green/blue components to make up the colour of the timer text (defaults to white)




Line 38: Line 43:
<syntaxhighlight lang="lua">setMissionTimerHurryTime ( missionTimer, time )</syntaxhighlight>
<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)  
Set the time that the clock will turn red (in milliseconds) (ie: to indicate there is not much time left)  
<syntaxhighlight lang="lua">setMissionTimerFormat ( missionTimer, format )</syntaxhighlight>
Set the text format for the timer




Line 44: Line 52:


Missiontimer is only compatible with MTASA 1.0 onwards.
Missiontimer is only compatible with MTASA 1.0 onwards.
[[ru:Resource:Missiontimer]]

Latest revision as of 15:20, 16 May 2012

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,"%m:%s",0.5,20,true,"default-bold",1,255,255,255)
    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, format, x, y, bg, font, scale, r, g, b )
  • 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)
  • format - A string detailing the format of the timer text to be shown. You can chose whether to show minutes, seconds or centiseconds using these 3 strings:
    • %m - minutes
    • %s - seconds
    • %cs - centiseconds

This allows you to add normal text onto the timer as well as showing the time left (eg: "Time left: %m:%s")

  • 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.
  • r,g,b - The red/green/blue components to make up the colour of the timer text (defaults to white)


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)

setMissionTimerFormat ( missionTimer, format )

Set the text format for the timer


To remove a missiontimer from the screen, use destroyElement.


Missiontimer is only compatible with MTASA 1.0 onwards.