Snow-Man Posted December 17, 2013 Share Posted December 17, 2013 How can i make Progress bar in Dx Rectangle ?? Link to comment
xXMADEXx Posted December 17, 2013 Share Posted December 17, 2013 Here's an example: local per = 0 addEventHandler ( 'onClientRender', root, function ( ) dxDrawRectangle ( 0, 0, per*2, 20 ) if ( per < 100 ) then per = per + 1 end end ) You need to make a variable, and every so often update the variable to a higher/lower number, and the rectangle's width needs to be the variable. Link to comment
Dealman Posted December 17, 2013 Share Posted December 17, 2013 Here's one I made for another thread, it's a bit overly complex but it does what you want Commands: /draw This will start drawing the rectangles. Run command again to hide them. /progress This will start progressing the timer with random values. local screenW, screenH = guiGetScreenSize() -- Assign a local variable to know if it is currently drawing or not. local isCurrentlyDrawing = false -- Variable for telling the script whether the timer is active or not. local progressTimer = false -- The total and current progress, this should always be between 0-100. local totalProgress = 0 -- Math for converting the width. Originally the relative size to the screen was 2.575. So when totalProgress is at 100, renderProgress will be at 2.575. This will display the progress bar as full. local renderProgress = (totalProgress/100)/2.575 function startDrawing() -- Check if it is currently not drawing the rectangle. if(isCurrentlyDrawing == false) then -- Add the event handler to the function containing the drawings. addEventHandler("onClientRender", getRootElement(), stuffToDraw) -- Change the variable to true since you are now drawing it with every frame. isCurrentlyDrawing = true -- Check if it is currently drawing the rectangle. elseif(isCurrentlyDrawing == true) then -- If it is drawing, then remove the event handler. This will stop drawing the rectangle. removeEventHandler("onClientRender", getRootElement(), stuffToDraw) -- And change the variable back to false, since you're no longer drawing. isCurrentlyDrawing = false end end addCommandHandler("draw", startDrawing, false, false) function startTheProgress() -- Check so the timer isn't already running. if(progressTimer == false) then -- Change the variable, you know the drill about those from now on. progressTimer = true -- Start the timer, and assign it a variable so it can be killed later. theTimer = setTimer(function() -- Increase the totalProgress with a random value between 0 to 10. local randomProgress = math.random(0, 10) -- Increase the totalProgress with the returned integer from above. totalProgress = totalProgress+randomProgress -- For debugging, will out put the random number and total progress in the format of randomNumber(totalProgress). outputChatBox(tostring(randomProgress).."("..tostring(totalProgress)..")") -- Update the renderProgress variable. renderProgress = (totalProgress/100)/2.575 -- Check if the totalProgress becomes equal to or greater than 100. if(totalProgress >= 100) then -- Set the total progress to 100, in case it became greater than 100. This is to prevent the actual progress bar from becoming wider than the background. totalProgress = 100 -- Update the renderProgress variable, since you change totalProgress above. renderProgress = (totalProgress/100)/2.575 -- Update the timer variable. progressTimer = false -- Message to tell you that the progress became greater than or equal to 100. outputChatBox("Progress greater than or equal to 100, killed timer.") -- Kill the timer so it doesn't keep running. killTimer(theTimer) end end, 1000, 0) else outputChatBox("Already progressing!") end end addCommandHandler("progress", startTheProgress, false, false) function stuffToDraw() -- Add the drawings you want in here. Do note that this code will be run with every frame. So 30-60 times PER SECOND. Be careful when using other code attached to onClientRender and onClientPreRender. backgroundRectangle = dxDrawRectangle(screenW/3.0, screenH/1.4, screenW/2.5, screenH/15.0, tocolor(0, 0, 0, 200)) progressRectangle = dxDrawRectangle(screenW/2.95, screenH/1.38, screenW*renderProgress, screenH/22, tocolor(187, 0, 0, 255)) progressText = dxDrawText("Progress: ("..totalProgress.."%)", screenW/2.15, screenH/1.37, screenW/2.575, screenH/22, tocolor(255, 255, 255, 255), 1, "pricedown") end Link to comment
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