Tails Posted December 26, 2015 Share Posted December 26, 2015 (edited) Hello fellow MTA scripters, So, I've been trying to solve this calculation for some time now. What I have is the 'secs' which is the duration of the song. I'm trying to fill up a bar going from 0 to 479 in width but I must calculate how much to add for every second in the song until it gets to 479. I've tried all sorts of things, but this is what I have at the moment and I just don't know what to do anymore. Does anyone know how to solve the math problem? Any help is much appreciated! progressBarMin = 0 -- = 0% progressBarMax = 479 -- = 100% width = secs / progressBarMax incremental = width+width setTimer( function() width = width+incremental end ,1000,secs ) dxDrawRectangle(17, 175, width, 4, tocolor(255, 255, 255, 255), false) Edited December 27, 2015 by Guest Link to comment
starksZ Posted December 26, 2015 Share Posted December 26, 2015 local width = ( progress * 479 ) / 100 Link to comment
Tails Posted December 26, 2015 Author Share Posted December 26, 2015 Where do I type that in? Is 'progress', the seconds? When I type setTimer( function() width = (secs * 479) / 100 end ,1000,secs ) I get expected vector 2 at argument 3 for the dxDrawRectangle. Or width = (secs * 479) / 100 setTimer( function() width = width+width end ,1000,secs ) Not sure what to do here. Link to comment
dk99 Posted December 26, 2015 Share Posted December 26, 2015 You can check my resource to see how I did it: https://community.multitheftauto.com/index.php?p= ... s&id=12426 Decompiled version download link is in description. Link to comment
Tails Posted December 26, 2015 Author Share Posted December 26, 2015 I need to calculate it based on the duration of the song (secs). GetSoundPosition won't work in my case because of the type of source. Link to comment
ozulus Posted December 26, 2015 Share Posted December 26, 2015 Use this code. progressBarMax = 479 -- = 100% width = (secs / 100) * progressBarMax dxDrawRectangle(17, 175, width, 4, tocolor(255, 255, 255, 255), false) Link to comment
Sasu Posted December 26, 2015 Share Posted December 26, 2015 function ...(...) playSound(...) tick = getTickCount() end addEventHandler("onClientRender", root, function() local progress = math.floor( ( getTickCount() - tick ) / 1000 ) local width = ( progress * 479 ) / secs dxDrawRectangle(17, 175, width, 4, tocolor(255, 255, 255, 255), false) end ) Link to comment
Tails Posted December 27, 2015 Author Share Posted December 27, 2015 Thank to all who've tried to help. I managed to fix this using some very simple math. It's how I had it in mind from the start. Here's the final code: width = 0 maxWidth = 480 increment = maxWidth/secs -- secs is defined elsewhere for the length of the song setTimer(function() width = width+increment end ,1000,secs) function displayTitle() dxDrawRectangle(24, 192, 480, 8, tocolor(255, 255, 255, 255), false) dxDrawRectangle(24, 192, width, 8, tocolor(55, 55, 55, 255), false) end addEventHandler("onClientRender",root,displayTitle) @Sasu, Someone else came up with something very similar using getTickCount too. It worked so I'll assume yours will work just as well. I won't be using it, though, as I wanted to come up with something much simpler and straightforward. But thanks for your contribution because it certainly helps. 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