scaryface87 Posted April 9, 2015 Posted April 9, 2015 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!
xXMADEXx Posted April 9, 2015 Posted April 9, 2015 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 );
scaryface87 Posted April 10, 2015 Author Posted April 10, 2015 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 );
WhoAmI Posted April 10, 2015 Posted April 10, 2015 When someone hit the marker, check if 'p' is element and if getElementType ( p ) == "player". If doesn't work post your current code.
WhoAmI Posted April 10, 2015 Posted April 10, 2015 I know why it doesn't work. function test () Change to function test ( p )
scaryface87 Posted April 10, 2015 Author Posted April 10, 2015 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now