exp bar calculation

Recommended Posts

hello i need calculate between totalexp and requiredexp but i need reset exp bar when level up

this bar disturb  and backward like that 3 or 4 level help me please

```function math.round(number)
return number - number % 1
end
function getRequiredEXP(level)
return math.round(math.pow(level, 2) * 300)
end

local level = 1
local currentEXP = 0
local totalEXP = 0
local requiredLevel = 0
local requiredEXP = getRequiredEXP(requiredLevel + 1)
function DRAW_HUD()
local percentageEXP = (currentEXP / requiredEXP) * 369 ---- formule
dxDrawRectangle(1539, 914, 369, 5, tocolor(0, 0, 0, 255))
dxDrawRectangle(1539, 914, percentageEXP, 5, tocolor(255, 255, 255, 255))
dxDrawBorderedText(2, "LEVEL:", 1539, 942, 0, 0, tocolor(255,255,255,255), 1.50, "bankgothic")
dxDrawBorderedText(2.5, level, 1722, 920, 0, 0, tocolor(255,255,255,255), 2.5, "bankgothic")
dxDrawBorderedText(1.5, "EXP:", 1538, 860, 0, 0, tocolor(255,255,255,255), 1, "bankgothic")
dxDrawBorderedText(1.5, totalEXP, 1538, 885, 0, 0, tocolor(255,255,255,255), 1, "bankgothic")
if requiredEXP <= 999 then
dxDrawBorderedText(1.5, "                           "..requiredEXP, 1538, 885, 0, 0, tocolor(255,255,255,255), 1, "bankgothic")
elseif requiredEXP <= 9999 then
dxDrawBorderedText(1.5, "                         "..requiredEXP, 1538, 885, 0, 0, tocolor(255,255,255,255), 1, "bankgothic")
elseif requiredEXP <= 99999 then
dxDrawBorderedText(1.5, "                       "..requiredEXP, 1538, 885, 0, 0, tocolor(255,255,255,255), 1, "bankgothic")
elseif requiredEXP <= 999999 then
dxDrawBorderedText(1.5, "                     "..requiredEXP, 1538, 885, 0, 0, tocolor(255,255,255,255), 1, "bankgothic")
elseif requiredEXP <= 9999999 then
dxDrawBorderedText(1.5, "                   "..requiredEXP, 1538, 885, 0, 0, tocolor(255,255,255,255), 1, "bankgothic")
elseif requiredEXP <= 99999999 then
dxDrawBorderedText(1.5, "                 "..requiredEXP, 1538, 885, 0, 0, tocolor(255,255,255,255), 1, "bankgothic")
end
end

function dxDrawBorderedText (outline, text, left, top, right, bottom, color, scale, font, alignX, alignY, clip, wordBreak, postGUI, colorCoded, subPixelPositioning, fRotation, fRotationCenterX, fRotationCenterY)
for oX = (outline * -1), outline do
for oY = (outline * -1), outline do
dxDrawText (text, left + oX, top + oY, right + oX, bottom + oY, tocolor(122, 122, 122, 255), scale, font, alignX, alignY, clip, wordBreak, postGUI, colorCoded, subPixelPositioning, fRotation, fRotationCenterX, fRotationCenterY)
end
end
dxDrawText (text, left, top, right, bottom, color, scale, font, alignX, alignY, clip, wordBreak, postGUI, colorCoded, subPixelPositioning, fRotation, fRotationCenterX, fRotationCenterY)
end

currentEXP = currentEXP + amount
totalEXP = totalEXP + amount
if totalEXP >= requiredEXP then
currentEXP = currentEXP - requiredEXP
level = level + 1
requiredLevel = requiredLevel + 1
requiredEXP = getRequiredEXP(requiredLevel + 1)
end
end

end)```

Edited by Burak5312

3 hours ago, Burak5312 said:

i need reset exp bar when level up

Debug line 50 and check if the value goes below 0.

yes goes below 0 but i dont know how to fix this i spend my all day  :d problem calculate formule? i tryed other methods but when level up exp bar staying half

i need zero bar

Edited by Burak5312

3 minutes ago, Burak5312 said:

yes goes below 0 but i dont know how to fix this i spend my all day  :d problem calculate formule?

Hmmm, maybe:

`currentEXP = totalEXP - requiredEXP`

this time not be full exp bar when level up

Edited by Burak5312