Jump to content

record time and stop it


Recommended Posts

Hello ,

I would like to make some timer like in the gamemode from Race

So it need to record the time from 1 to ... till it hits a marker , i guess killTimer on that marker.

Then i would like it so if its below 1 minute for example it says "Congratz u finnished it within 1 minute"

and if its above 1 minute it says "Ahw you needed more then 1 minute"

I have no clues how to do this.

If you could explain me what i should use it would be helpfull :) im ready to learn.

sorry for no trys but i dont know how to start

Thank you in advance!

Link to comment

You can set a variable at the begning, and set it equal to getTickCount. When finished, the time taken will be: getTickCount ( ) - beginingVariable .

Here's an example:

local beginingTick = getTickCount ( ); 
  
local marker = createMarker ( 0, 0, 3, "cylinder", 5, 255, 255, 255, 255 ); 
  
addEventHandler ( "onMarkerHit", marker, function ( p )  
    outputChatBox ( "Time taken: ".. math.floor ( ( getTickCount ( ) - beginingTick ) / 100 ).. " seconds!", p ); 
end ); 

Link to comment

Hm i tought something like this but i get an error :

server lua 38 ; Attempt to perform arithmetic on local 'beginingTick' a boolean value

i just made it with a test command to test it.

  
 local marker = createMarker ( 0, 0, 3, "cylinder", 5, 255, 255, 255, 255 ); 
  
function test () 
  
local beginingTick = getTickCount ( p ); 
setElementData(p,"test",tonumber(beginingTick)) 
end 
addCommandHandler("test",test) 
  
  
addEventHandler ( "onMarkerHit", marker, function ( p ) 
    local beginingTick = getElementData(p,"test") 
    outputChatBox ( "Time taken: ".. math.floor ( ( getTickCount ( ) - beginingTick ) / 100 ).. " seconds!", p ); 
end ); 
  

Link to comment

Still same error and if getElementType ( p ) == "player" showed me that P is me , (i tried this within function ;

  
  
 if getElementType ( p ) == "player" then 
outputChatBox("It works!") 
else 
outputChatBox("You're not P") 
  

I putted my code after the getelementtype and now its working , thanks

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