Jump to content

Need Marker Timer Script


Recommended Posts

  • Moderators
1 hour ago, falconthunder said:

Hello, I need a marker timer script which starts a timer on screen for that player who hit marker X and stopped when that player hit marker Y. And when that player hits marker X again without hitting marker Y, it restarts/reset timer again. Help me pls.

local sx, sy = guiGetScreenSize()
function renderTime()
	local currentTime = getTickCount()
	local elapsedTime = (currentTime - startTime) / 1000
	dxDrawText(elapsedTime, 0, 0, sx, sy/4, tocolor(255,255,255,255), 2, "default-bold", "center", "center")
end

addEventHandler("onClientMarkerHit", startMarker, function(hitPlayer, matchingDimension) -- Attach onClientMarkerHit event to startMarker
	if hitPlayer == localPlayer and matchingDimension then -- You need the check the player who hit the marker is the client.  AND  localPlayers's dimension is matching with marker's dimension
		if started then -- timer already started, need to reset it
			startTime = getTickCount()
		
		else -- timer not running, you need to start the onClientRender and display time on client's screen
			started = true
			startTime = getTickCount()
			addEventHandler("onClientRender", root, renderTime)
		end
	end
end)

addEventHandler("onClientMarkerHit", endMarker, function(hitPlayer, matchingDimension) -- Attach onClientMarkerHit event to endMarker
	if hitPlayer == localPlayer and matchingDimension then  -- You need the check the player who hit the marker is the client.  AND  localPlayers's dimension is matching with marker's dimension
		if started then -- if the timer is running need to stop it.
			local currentTime = getTickCount()
			local elapsedTime = currentTime - startTime
			outputChatBox("Your time is: " .. elapsedTime)
			
			removeEventHandler("onClientRender", root, renderTime)
			started = false
		end
	end
end)

 

  • Thanks 1
Link to comment
  • Moderators
28 minutes ago, falconthunder said:

It will be better if you show me how I can set Marker X and Marker Y location in this script. Idk where to add xyz locations of markers in this script.

local startMarker = createMarker(0,0,3, "cylinder", 1, 0, 255, 0) -- The start marker (Here you can change the marker's position and color)
local endMarker = createMarker(0,10,3, "cylinder", 1, 255, 0, 0) -- The end marker (Here you can change the marker's position and color)


local sx, sy = guiGetScreenSize()
function renderTime()
	local currentTime = getTickCount()
	local elapsedTime = (currentTime - startTime) / 1000
	dxDrawText(elapsedTime, 0, 0, sx, sy/4, tocolor(255,255,255,255), 2, "default-bold", "center", "center")
end

addEventHandler("onClientMarkerHit", startMarker, function(hitPlayer, matchingDimension) -- Attach onClientMarkerHit event to startMarker
	if hitPlayer == localPlayer and matchingDimension then -- You need the check the player who hit the marker is the client.  AND  localPlayers's dimension is matching with marker's dimension
		if started then -- timer already started, need to reset it
			startTime = getTickCount()
		
		else -- timer not running, you need to start the onClientRender and display time on client's screen
			started = true
			startTime = getTickCount()
			addEventHandler("onClientRender", root, renderTime)
		end
	end
end)

addEventHandler("onClientMarkerHit", endMarker, function(hitPlayer, matchingDimension) -- Attach onClientMarkerHit event to endMarker
	if hitPlayer == localPlayer and matchingDimension then  -- You need the check the player who hit the marker is the client.  AND  localPlayers's dimension is matching with marker's dimension
		if started then -- if the timer is running need to stop it.
			local currentTime = getTickCount()
			local elapsedTime = currentTime - startTime
			outputChatBox("Your time is: " .. elapsedTime)
			
			removeEventHandler("onClientRender", root, renderTime)
			started = false
		end
	end
end)

 

  • Thanks 1
Link to comment
10 minutes ago, stPatrick said:

local startMarker = createMarker(0,0,3, "cylinder", 1, 0, 255, 0) -- The start marker (Here you can change the marker's position and color)
local endMarker = createMarker(0,10,3, "cylinder", 1, 255, 0, 0) -- The end marker (Here you can change the marker's position and color)


local sx, sy = guiGetScreenSize()
function renderTime()
	local currentTime = getTickCount()
	local elapsedTime = (currentTime - startTime) / 1000
	dxDrawText(elapsedTime, 0, 0, sx, sy/4, tocolor(255,255,255,255), 2, "default-bold", "center", "center")
end

addEventHandler("onClientMarkerHit", startMarker, function(hitPlayer, matchingDimension) -- Attach onClientMarkerHit event to startMarker
	if hitPlayer == localPlayer and matchingDimension then -- You need the check the player who hit the marker is the client.  AND  localPlayers's dimension is matching with marker's dimension
		if started then -- timer already started, need to reset it
			startTime = getTickCount()
		
		else -- timer not running, you need to start the onClientRender and display time on client's screen
			started = true
			startTime = getTickCount()
			addEventHandler("onClientRender", root, renderTime)
		end
	end
end)

addEventHandler("onClientMarkerHit", endMarker, function(hitPlayer, matchingDimension) -- Attach onClientMarkerHit event to endMarker
	if hitPlayer == localPlayer and matchingDimension then  -- You need the check the player who hit the marker is the client.  AND  localPlayers's dimension is matching with marker's dimension
		if started then -- if the timer is running need to stop it.
			local currentTime = getTickCount()
			local elapsedTime = currentTime - startTime
			outputChatBox("Your time is: " .. elapsedTime)
			
			removeEventHandler("onClientRender", root, renderTime)
			started = false
		end
	end
end)

 

sry for this, i am nub scripter

 

ERROR: editor_test\timer.lua:5: attempt to call global 'guiGetScreenSize' (a nil value)

Edited by falconthunder
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...