Jump to content

Help Progress Bar


pepsi18

Recommended Posts

  • Moderators

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)

 

Link to comment
  • Moderators
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 by IIYAMA
  • 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...