pepsi18 Posted May 17, 2017 Posted May 17, 2017 How can I make a progress bar composed for multiple rectangle
Moderators IIYAMA Posted May 17, 2017 Moderators Posted May 17, 2017 You have to see it as 1 large rectangle. local progress = 55 -- 55% local amountOfSegments = 5 -- bars local progressPerSegment = (100 / amountOfSegments) local remainingProgress = progress & progressPerSegment local segmentsFull = math.floor(progress / progressPerSegment) local segmentsInUse = math.ceil(progress / progressPerSegment) iprint("segmentsFull: " .. segmentsFull) iprint("segmentsInUse: " .. segmentsInUse) iprint("remainingProgress: " .. remainingProgress) Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
pepsi18 Posted May 18, 2017 Author Posted May 18, 2017 You explain to me how it works I do not understand your code very well
Moderators IIYAMA Posted May 21, 2017 Moderators Posted May 21, 2017 (edited) local progress = 55 -- 55% local amountOfSegments = 5 -- the amount of bars / segments local progressPerSegment = (100 / amountOfSegments) -- when you devide the total progress over the segment count, you will know how much percentage every segment is. local remainingProgress = progress % progressPerSegment -- the next step is to calculate how much percentage is left over after removing all full bars of it. So for example ever segment is 10% and you have 95% health, it will subtrack 10 from 95 as much as possible. At the end 5% will remain. local segmentsFull = math.floor(progress / progressPerSegment) -- it is usefull to know how much bars are full, so that you can fill those up. local segmentsInUse = math.ceil(progress / progressPerSegment) -- This will show you have many bars do contain any health. iprint("segmentsFull: " .. segmentsFull) iprint("segmentsInUse: " .. segmentsInUse) iprint("remainingProgress: " .. remainingProgress) for i=1, amountOfSegments do if i <= segmentsFull then -- draw a fulled health line iprint("full") else -- draw a fulled [gray] health line iprint("background") if i == segmentsInUse and remainingProgress > 0 then -- draw a health line depending on the remainingProgress iprint("remaining " .. tostring(remainingProgress)) else iprint("empty") end end end Edited May 21, 2017 by IIYAMA 1 Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Moderators IIYAMA Posted May 25, 2017 Moderators Posted May 25, 2017 You might want to reply @pepsi18 it is a bit rude if you do not. 1 Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
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