Jump to content

[HELP]Map timer ?


TheMaysTRo

Recommended Posts

Hello there ,Im working on my own gamemode , and I want to create a timer when the map start and I will change the map when it ends.

My problem is each player have his own timer .

Maybe Because im working on client side ? I tried server side and it didn't work .

This is my code (client sided ) :

    theTimer = setTimer(function() end, 60000, 1) -- A timer that does nothing. 
  
screenX,screenY = guiGetScreenSize() 
function createText () 
remaining, executesRemaining, totalExecutes = getTimerDetails(theTimer) -- Get the timers details 
    if (remaining) then 
    dxDrawRectangle (screenX *.40, screenY * .09, 250, 50, tocolor(0,0,0,150)) 
    text = dxDrawText (remaining/1000, screenX * .48, screenY * .1, screenX, screenY, tocolor(255,255,255), 2) 
    else 
        outputChatBox("Timer no longer exists") 
    end 
end 
  
  
     
     
function HandleTheRendering ( ) 
    addEventHandler ( "onClientRender", root, createText ) -- keep the text visible with onClientRender. 
  
end 
HandleTheRendering ( ) 

Wish you help me , Thanks .

Link to comment

The timer is useless.

Just trigger the left time in ms serversided.

triggerClientEvent ( "lefttime", root, 10000 ) -- 10sec 

Then in addEventHandler save this rest time + getTickCount().

To get the rest time you just have to:

savedtime - getTickCount() = rest time in ms.

-- Client -- 
local timetoend = 0 
addEvent ... 
addEventHandler ( ..., function ( resttime ) 
    timetoend = getTickCount() + resttime 
end ) 
  
addCommandHandler ( "gettimer", function () 
    outputChatBox ( "It's "..timetoend - getTickCount().."ms left" ) 

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