Jump to content

Why start timer automatically, when resource start?


Turbe$Z

Recommended Posts

function countdownFin()
	removeEventHandler("onClientRender", root, eventszamlalas)
end

local countdown = setTimer(countdownFin, 5000, 1) 
local screenW, screenH = guiGetScreenSize()

function eventszamlalas()
	local x = getTimerDetails(countdown) 
	local timeLeft = math.ceil(x/1000) 
        dxDrawLine((screenW * 0.4111) - 1, (screenH * 0.1244) - 1, (screenW * 0.4111) - 1, screenH * 0.1589, tocolor(254, 254, 254, 255), 1, false)
        dxDrawLine(screenW * 0.6118, (screenH * 0.1244) - 1, (screenW * 0.4111) - 1, (screenH * 0.1244) - 1, tocolor(254, 254, 254, 255), 1, false)
        dxDrawLine((screenW * 0.4111) - 1, screenH * 0.1589, screenW * 0.6118, screenH * 0.1589, tocolor(254, 254, 254, 255), 1, false)
        dxDrawLine(screenW * 0.6118, screenH * 0.1589, screenW * 0.6118, (screenH * 0.1244) - 1, tocolor(254, 254, 254, 255), 1, false)
        dxDrawRectangle(screenW * 0.4111, screenH * 0.1244, screenW * 0.2007, screenH * 0.0344, tocolor(0, 0, 0, 161), false)
        dxDrawText("Az event elkezdődött! Vége: "..convertSecondsToMinutes(timeLeft), screenW * 0.4118, screenH * 0.1244, screenW * 0.6118, screenH * 0.1589, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false)
end

function eventstart()
addEventHandler("onClientRender", root, eventszamlalas)
end
addCommandHandler("asd", eventstart)

function convertSecondsToMinutes(sec)
	local temp = sec/60 
	local temp2 = (math.floor(temp))
	local temp3 = sec-(temp2*60)
	if string.len(temp3) < 2 then
		temp3 = "0"..tostring(temp3) 
	end 
	return tostring(temp2)..":"..tostring(temp3) 
end 

i created a command, which displays the dx elements, and the timer, but the timer  starts with the script, and when it expires, the command doesn't working.. :S i want, when i type command, show dx elements to everyone, and start timer, how to fix this ? :/ 

sorry for my very bad English..:|

 

 
Link to comment
42 minutes ago, Turbo777 said:

function countdownFin()
	removeEventHandler("onClientRender", root, eventszamlalas)
end

local countdown = setTimer(countdownFin, 5000, 1) 
local screenW, screenH = guiGetScreenSize()

function eventszamlalas()
	local x = getTimerDetails(countdown) 
	local timeLeft = math.ceil(x/1000) 
        dxDrawLine((screenW * 0.4111) - 1, (screenH * 0.1244) - 1, (screenW * 0.4111) - 1, screenH * 0.1589, tocolor(254, 254, 254, 255), 1, false)
        dxDrawLine(screenW * 0.6118, (screenH * 0.1244) - 1, (screenW * 0.4111) - 1, (screenH * 0.1244) - 1, tocolor(254, 254, 254, 255), 1, false)
        dxDrawLine((screenW * 0.4111) - 1, screenH * 0.1589, screenW * 0.6118, screenH * 0.1589, tocolor(254, 254, 254, 255), 1, false)
        dxDrawLine(screenW * 0.6118, screenH * 0.1589, screenW * 0.6118, (screenH * 0.1244) - 1, tocolor(254, 254, 254, 255), 1, false)
        dxDrawRectangle(screenW * 0.4111, screenH * 0.1244, screenW * 0.2007, screenH * 0.0344, tocolor(0, 0, 0, 161), false)
        dxDrawText("Az event elkezdődött! Vége: "..convertSecondsToMinutes(timeLeft), screenW * 0.4118, screenH * 0.1244, screenW * 0.6118, screenH * 0.1589, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false)
end

function eventstart()
addEventHandler("onClientRender", root, eventszamlalas)
end
addCommandHandler("asd", eventstart)

function convertSecondsToMinutes(sec)
	local temp = sec/60 
	local temp2 = (math.floor(temp))
	local temp3 = sec-(temp2*60)
	if string.len(temp3) < 2 then
		temp3 = "0"..tostring(temp3) 
	end 
	return tostring(temp2)..":"..tostring(temp3) 
end 

i created a command, which displays the dx elements, and the timer, but the timer  starts with the script, and when it expires, the command doesn't working.. :S i want, when i type command, show dx elements to everyone, and start timer, how to fix this ? :/ 

sorry for my very bad English..:|

 


 

It's because you initialised the timer in the global scope meaning it basically gives you the same result as using the event "onResourceStart". If you want to set a timer when called for, use it within a function instead of the global scope.

Edited by Pembo
Link to comment
3 minutes ago, Pembo said:

It's because you initialised the timer in the global scope meaning it basically gives you the same result as using the event "onResourceStart". If you want to set a timer when called for, use it within a function instead of the global scope.

How? :S

  • Like 1
Link to comment
3 hours ago, Turbo777 said:

doesn't working now :S 

local screenW, screenH = guiGetScreenSize()
local countdown

function initTimer()
	if not isTimer(countdown) then -- make sure you can only start it once
		countdown = setTimer(countdownFin, 5000, 1)
	end
end
addCommandHandler("asd", initTimer, false, false)

function countdownFin()
	removeEventHandler("onClientRender", root, eventszamlalas)
end

function eventszamlalas()
	local x = getTimerDetails(countdown)
	local timeLeft = math.ceil(x/1000) 
	dxDrawLine((screenW * 0.4111) - 1, (screenH * 0.1244) - 1, (screenW * 0.4111) - 1, screenH * 0.1589, tocolor(254, 254, 254, 255), 1, false)
	dxDrawLine(screenW * 0.6118, (screenH * 0.1244) - 1, (screenW * 0.4111) - 1, (screenH * 0.1244) - 1, tocolor(254, 254, 254, 255), 1, false)
	dxDrawLine((screenW * 0.4111) - 1, screenH * 0.1589, screenW * 0.6118, screenH * 0.1589, tocolor(254, 254, 254, 255), 1, false)
	dxDrawLine(screenW * 0.6118, screenH * 0.1589, screenW * 0.6118, (screenH * 0.1244) - 1, tocolor(254, 254, 254, 255), 1, false)
	dxDrawRectangle(screenW * 0.4111, screenH * 0.1244, screenW * 0.2007, screenH * 0.0344, tocolor(0, 0, 0, 161), false)
	dxDrawText("Az event elkezdődött! Vége: "..convertSecondsToMinutes(timeLeft), screenW * 0.4118, screenH * 0.1244, screenW * 0.6118, screenH * 0.1589, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false)
end

function convertSecondsToMinutes(sec)
	local temp = sec/60 
	local temp2 = (math.floor(temp))
	local temp3 = sec-(temp2*60)
	if string.len(temp3) < 2 then
		temp3 = "0"..tostring(temp3) 
	end 
	return tostring(temp2)..":"..tostring(temp3) 
end

Does now. Try it

  • Like 1
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...