Jump to content

Missiontimer


Zadara

Recommended Posts

Hi there,

I want to use the missiontimer script in mine game mode, but i have no idea how it works. Can anyone help my, how it works.

I just want to create a round time and when the round is finished and then the scoreboard is visible.

I would like it if the timer also is drawn.

Thanks,

Link to comment

How come you have a "missiontimer" but you don't know how it works?

If you want it to be "drawn" on screen, you have 2 ways, server-side and client-side. If you want to do it server-side (which IMO is better) you can use Text functions but if you want to do it client-side you can use GUI functions or Drawing functions (both of these have libraries for easier usage: GUI Lib, Textlib).

Basically, you need:

- a function which will display the text on the screen

- a function which will be counting down (that is, it will be called every second), so it will use timer and call function which displays the text or use text functions within this one

Link to comment
How come you have a "missiontimer" but you don't know how it works?

He means the resources SVN resource called "missiontimer", I think.

Thats what i mean.

How come you have a "missiontimer" but you don't know how it works?

If you want it to be "drawn" on screen, you have 2 ways, server-side and client-side. If you want to do it server-side (which IMO is better) you can use Text functions but if you want to do it client-side you can use GUI functions or Drawing functions (both of these have libraries for easier usage: GUI Lib, Textlib).

Basically, you need:

- a function which will display the text on the screen

- a function which will be counting down (that is, it will be called every second), so it will use timer and call function which displays the text or use text functions within this one

But in the missiontimer map wich is including the MTA 1.0 resources, is there also a lua. called missiontimer_draw. Does that not mean that i need to create a other kind of way to set that on the screen, the timer?

Link to comment
How come you have a "missiontimer" but you don't know how it works?

He means the resources SVN resource called "missiontimer", I think.

Thats what i mean.

OK, so I can't help because I prefer to make everything by myself and I don't use any other resources but mine (including votemanager, mapmanager, helpmanager, spawnmanager, etc.)

Link to comment

Check the "deathmatch" gamemode, this is an example use of the gamemode. 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 
getMissionTimerTime ( missionTimer ) --Gets the number currently on the clock 
setMissionTimerFrozen ( missionTimer, frozen )   --Freeze the timer 
isMissionTimerFrozen ( missionTimer ) 
  

To remove a missiontimer from the screen, use destroyElement.

Please also bear in mind missiontimer is only compatible with 1.0.

Link to comment
Check the "deathmatch" gamemode, this is an example use of the gamemode. 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. If this is the case, the duration is ignored.

* 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 
getMissionTimerTime ( missionTimer ) --Gets the number currently on the clock 
setMissionTimerFrozen ( missionTimer, frozen )   --Freeze the timer 
isMissionTimerFrozen ( missionTimer ) 
  

To remove a missiontimer from the screen, use destroyElement.

Please also bear in mind missiontimer is only compatible with 1.0.

Thank you! Only i think you need to edit setMissionTimerTime the second one to getMissionTimerTime in your post, this for people who search on this forum for the missiontimer.

Anyways, Thank you! :mrgreen:

Link to comment
Ok, another question, how can is the timer viseble for people that join the server when the timer if on 5 minuts of the 10 minuts?

The timer should display to everyone even on join. I've just realised i forgot to code this. I'll fix this soon.

edit: This is now fixed! Update your missiontimer resource :)

Also i just tested count up timers. The "duration" parameter is ignored for them.

Link to comment

Doesn't work... :x, says that by setElementHealth have a bad agrument

function onTimeElapsed() 
    local players = getElementsByType( "player" ) 
    setElementHealth ( players, 0 ) 
    restartResource(ProjectileWars) 
    restartResource(scores) 
    restartResource(scoreboard) 
    restartResource(playercolors) 
end 
addEventHandler ( "onMissionTimerElapsed", roundTimer, onTimeElapsed ) 

Link to comment
Doesn't work... :x, says that by setElementHealth have a bad agrument

function onTimeElapsed() 
    local players = getElementsByType( "player" ) 
    setElementHealth ( players, 0 ) 
    restartResource(ProjectileWars) 
    restartResource(scores) 
    restartResource(scoreboard) 
    restartResource(playercolors) 
end 
addEventHandler ( "onMissionTimerElapsed", roundTimer, onTimeElapsed ) 

You shouldnt have to be restarting your resource at the end of a round, this just shows that things arent coded very nicely. You should be able to manage this all without giving the resource access to start/stop resources.

Link to comment
Doesn't work... :x, says that by setElementHealth have a bad agrument

function onTimeElapsed() 
    local players = getElementsByType( "player" ) 
    setElementHealth ( players, 0 ) 
    restartResource(ProjectileWars) 
    restartResource(scores) 
    restartResource(scoreboard) 
    restartResource(playercolors) 
end 
addEventHandler ( "onMissionTimerElapsed", roundTimer, onTimeElapsed ) 

You shouldnt have to be restarting your resource at the end of a round, this just shows that things arent coded very nicely. You should be able to manage this all without giving the resource access to start/stop resources.

I need to use restart, because things like vehicle and the scores need to reset and there is no exported function to reset the scoren. There is one for the scoreboard, but not for the scores. I already give the resources the acces, but the consols says that there is a bad agrument.

Link to comment

Because you DO NOT read wiki as I told you to -_- If you ever visited the link and found the function getElementsByType you'd know this function returns indexed table of elements not "elements element" (which doesn't exist). You have to loop the players table and set every player's health separately.

for i, player in pairs( players ) do 
    setElementHealth( player, 0 ); 
end 

READ THE DAMN WIKI. All your questions so far could be answered by looking up the wiki. It's there for a reason.

http://development.mtasa.com/index.php

Link to comment
Because you DO NOT read wiki as I told you to -_- If you ever visited the link and found the function getElementsByType you'd know this function returns indexed table of elements not "elements element" (which doesn't exist). You have to loop the players table and set every player's health separately.
for i, player in pairs( players ) do 
    setElementHealth( player, 0 ); 
end 

READ THE DAMN WIKI. All your questions so far could be answered by looking up the wiki. It's there for a reason.

http://development.mtasa.com/index.php

I'm talking about restartResource, not about setElementHealth. And there is no resource in the type list. So need i use getResource()?

Like this?:

I can't test it now cuz i'm on some one others pc, or is there no getResourceName need?

local resources = getResources() 
for i, resource in ipairs(resources) do 
      local getResourceName(resource) 
      restartResource(scores) 
end 

Link to comment
local resources = getResources() 
for i, resource in ipairs(resources) do 
      local name=getResourceName(resource) 
      if name=="scores" then 
            restartResource(resource) 
      end 
end 

This should work

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