Burak5312

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

mta-screen-2019-12-12-06-40-28.png

 

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
addEventHandler("onClientRender", root, DRAW_HUD)

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

function addEXP(amount)
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

addCommandHandler("giveexp", function()
addEXP(80)
end)

 

Edited by Burak5312

Share this post


Link to post
3 hours ago, Burak5312 said:

i need reset exp bar when level up

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

Share this post


Link to post

Ads-z.png

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

Share this post


Link to post
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

 

Share this post


Link to post

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.