Jump to content

MTA Progress Bar


LyricalMM

Recommended Posts

Posted

Hello, i've made a script for a new job, so when he is in the marker, he freeze for a random time.

timer = math.random(4000,6000)
setTimer(function()
	local freeze = getElementData(getLocalPlayer(), "curierFreeze")
	if freeze then
	setElementFrozen(getPedOccupiedVehicle(getLocalPlayer()), false)
	toggleAllControls(true, true, false)
	setElementData(getLocalPlayer(), "curierFreeze", false)
	guiProgressBarSetProgress(progress, 100)

end
if (guiProgressBarGetProgress(progress) == 100) then
	destroyElement(progress)
end

end, timer, 0)

how to set the progress bar percentage by the timer?

like if the timer is 4.6 seconds, in 4.6 seconds to fill in the progress bar.

Posted
4 hours ago, LyricalMM said:

Hello, i've made a script for a new job, so when he is in the marker, he freeze for a random time.


timer = math.random(4000,6000)
setTimer(function()
	local freeze = getElementData(getLocalPlayer(), "curierFreeze")
	if freeze then
	setElementFrozen(getPedOccupiedVehicle(getLocalPlayer()), false)
	toggleAllControls(true, true, false)
	setElementData(getLocalPlayer(), "curierFreeze", false)
	guiProgressBarSetProgress(progress, 100)

end
if (guiProgressBarGetProgress(progress) == 100) then
	destroyElement(progress)
end

end, timer, 0)

how to set the progress bar percentage by the timer?

like if the timer is 4.6 seconds, in 4.6 seconds to fill in the progress bar.

You didnt define progress.
 

Posted
2 minutes ago, LyricalMM said:

any functions or methods?

timer = math.random(4000,6000)
setTimer(function()
	local freeze = getElementData(getLocalPlayer(), "curierFreeze")
	if freeze then
      progress = guiCreateProgressBar ( float x, float y, float width, float height, bool relative, [element parent = nil] )
	setElementFrozen(getPedOccupiedVehicle(getLocalPlayer()), false)
	toggleAllControls(true, true, false)
	setElementData(getLocalPlayer(), "curierFreeze", false)
	guiProgressBarSetProgress(progress, 100)

end
if (guiProgressBarGetProgress(progress) == 100) then
	destroyElement(progress)
end

end, timer, 0)

 

Posted
Just now, Knuck said:

timer = math.random(4000,6000)
setTimer(function()
	local freeze = getElementData(getLocalPlayer(), "curierFreeze")
	if freeze then
      progress = guiCreateProgressBar ( float x, float y, float width, float height, bool relative, [element parent = nil] )
	setElementFrozen(getPedOccupiedVehicle(getLocalPlayer()), false)
	toggleAllControls(true, true, false)
	setElementData(getLocalPlayer(), "curierFreeze", false)
	guiProgressBarSetProgress(progress, 100)

end
if (guiProgressBarGetProgress(progress) == 100) then
	destroyElement(progress)
end

end, timer, 0)

 

aah, I've defined the progress bar in another function, that's not the problem.

Posted
local lol = guiProgressBarGetProgress(progress)

setTimer( guiProgressBarSetProgress, 5000, 1,progress,lol+10 )

setTimer( guiProgressBarSetProgress, 10000, 1,progress,lol+20 )

setTimer( guiProgressBarSetProgress, 15000, 1,progress,lol+30 )

setTimer( guiProgressBarSetProgress, 20000, 1,progress,lol+40 )

setTimer( guiProgressBarSetProgress, 25000, 1,progress,lol+50 )

setTimer( guiProgressBarSetProgress, 30000, 1,progress,lol+60 )

setTimer( guiProgressBarSetProgress, 35000, 1,progress,lol+70 )

setTimer( guiProgressBarSetProgress, 40000, 1,progress,lol+80 )

setTimer( guiProgressBarSetProgress, 45000, 1,progress,lol+90 )

setTimer( guiProgressBarSetProgress, 50000, 1,progress,lol+100 )

@LyricalMM

Posted
1 minute ago, Knuck said:

local lol = guiProgressBarGetProgress(progress)

setTimer( guiProgressBarSetProgress, 5000, 1,progress,lol+10 )

setTimer( guiProgressBarSetProgress, 10000, 1,progress,lol+20 )

setTimer( guiProgressBarSetProgress, 15000, 1,progress,lol+30 )

setTimer( guiProgressBarSetProgress, 20000, 1,progress,lol+40 )

setTimer( guiProgressBarSetProgress, 25000, 1,progress,lol+50 )

setTimer( guiProgressBarSetProgress, 30000, 1,progress,lol+60 )

setTimer( guiProgressBarSetProgress, 35000, 1,progress,lol+70 )

setTimer( guiProgressBarSetProgress, 40000, 1,progress,lol+80 )

setTimer( guiProgressBarSetProgress, 45000, 1,progress,lol+90 )

setTimer( guiProgressBarSetProgress, 50000, 1,progress,lol+100 )

@LyricalMM

nope, I want to set the progress by the timer.

Posted (edited)

Then you'll need to monitor getTimerDetails every now and then (perhaps even by render event but it's overkill - you do not need to do this every frame).

local duration = --[[ define a duration in ms ]]
local timeLeft = getTimerDetails(--[[ the timer ]])
local timeDone = duration - timeLeft
local percent = timeDone / duration
guiProgressBarSetProgress(--[[ progressbar element ]], percent)

 

Edited by MrTasty

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