Jump to content

Timer onMarkerHit


Thivenin

Recommended Posts

hai, I wanna start a marker when the player hit the marker "startMarker" and stop it and tell you our time

startMarker = createMarker ( -5475, 2376, 15, "checkpoint", 8, 250, 0, 0, 255 ) 
finishMarker = createMarker ( -5460, 2376, 15, "checkpoint", 8, 250, 0, 0, 255 ) 
local seconds = 0 
  
function startRace () 
    if ( markerHit == startMarker ) then  
        timer = setTimer(seconds_function, 1000, 0) 
    end 
end 
addEventHandler("onMarkerHit", getRootElement(), startRace) 
  
function seconds_function () 
    seconds = seconds + 1 
end 
  
function finishRace (MarkerHit, matchingDimension) 
    if matchingDimension == true and markerHit == finishMarker then 
        outputChatBox(seconds, source) 
        killTimer(timer) 
        resetTimer(timer) 
        seconds = 0 
    end 
end 
addEventHandler("onMarkerHit", getRootElement(), finishRace) 

I found 2 function in this forum and edited a bit, I haven't got any error :/

Link to comment

What they are all trying to say; trigger a client sided function to start and cancel the timer. :) Else everyone will get the timer (cause its server sided)

you could try this, please note that I haven't tested it!

server

startMarker = createMarker ( -5475, 2376, 15, "checkpoint", 8, 250, 0, 0, 255 ) 
  
function startRace () 
    if ( markerHit == startMarker ) then 
        triggerClientEvent( "startRace", hitElement, hitElement ); 
    end 
end 
addEventHandler("onMarkerHit", getRootElement(), startRace) 

client

addEvent("startRace", true); 
addEventHandler("startRace", root, 
    function ( source ) 
        seconds = 0; 
        finishMarker = createMarker ( -5460, 2376, 15, "checkpoint", 8, 250, 0, 0, 255 ) 
        countSecondsTimer = setTimer( countSeconds, 1000, 0 -- s;) -->
    end 
); 
  
function countSeconds() 
    seconds = seconds + 1 
end 
  
addEventHandler("onClientMarkerHit", finishMarker, 
    function ( hitElement ) 
        if ( ( source == finishMarker ) and ( hitElement = getLocalPlayer() ) ) then 
            killTimer ( countSecondsTimer ); 
            destroyElement ( finishMarker ); 
            seconds = 0; 
        end 
    end 
); 

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