Jump to content

Experience Required


ZeyadGTX

Recommended Posts

My level system shows Lv : and XP: In my Hud by using @ dxDrawText Function The Problem is, that's what shown in my Hud

LV: 50 XP : 65004 How Can i make it get the Experience required to level up like this ,

Lv: 50 XP : 65004 / 70004 What Do i need an XML ?? or Script to show Exp Required Please Help ??

What To Make !

dxDrawText:

if XP and LV then 
        dxDrawText("XP  #FFFFFF"..XP, sWidth*(670/1280), sHeight*(689/720), sWidth*(621/1280), sHeight*(715/720), tocolor(255, 255, 255, 255), (0.8/1280)*sWidth,(0.8/720)*sHeight,"bankgothic", "left", "top", false, false, true, true, false) 
        dxDrawText("LV: #FFFFFF"..LV, sWidth*(350/1280), sHeight*(689/720), sWidth*(372/1280), sHeight*(715/720), tocolor(255, 255, 255, 255), (0.8/1280)*sWidth,(0.8/720)*sHeight,"bankgothic", "left", "top", false, false, true, true, false) 
    end 

Link to comment

Server Side ( PART OF )

function win(ammo, killer, weapon, bodypart) 
    if (killer and getElementType(killer) == "player" and killer ~= source) then 
        local H = getElementData(killer, "EXP") or 0 
        local S = getElementData(killer, "LV") or 0 
        local killer1 = getPlayerName(killer) 
        local noob = getPlayerName(source) 
        local experience = math.random(25, 100) 
        setElementData(killer, "EXP", tonumber(H)+experience) 
        local H = tonumber(H) + experience 
        triggerClientEvent(killer, "onTestExp", killer, experience) 
        if (tonumber(H) >= 100 and tonumber(H) <=400) then 
            setElementData(killer, "LV", 1) 
            setElementData(killer, "experience.rank", "Private") 
        elseif (tonumber(H) >= 401 and tonumber(H) <=600) then 
            setElementData(killer, "LV", 2) 
        elseif (tonumber(H) >= 601 and tonumber(H) <=800) then 
            setElementData(killer, "LV", 3) 
        elseif (tonumber(H) >= 801 and tonumber(H) <=1000) then 
            setElementData(killer, "LV", 4) 
            setElementData(killer, "experience.rank", "Private First Class") 
        elseif (tonumber(H) >= 1001 and tonumber(H) <=1200) then 
            setElementData(killer, "LV", 5) 
        elseif (tonumber(H) >= 1201 and tonumber(H) <=1400) then 
            setElementData(killer, "LV", 6) 
        elseif (tonumber(H) >= 1401 and tonumber(H) <=1600) then 
            setElementData(killer, "LV", 7) 
            setElementData(killer, "experience.rank", "Specialist") 
        elseif (tonumber(H) >= 1601 and tonumber(H) <=1800) then 
            setElementData(killer, "LV", -- s8) -->
        elseif (tonumber(H) >= 1801 and tonumber(H) <=2000) then 
            setElementData(killer, "LV", 9) 
        elseif (tonumber(H) >= 2001 and tonumber(H) <=2200) then 
            setElementData(killer, "LV", 10) 
            setElementData(killer, "experience.rank", "Corporal") 
        elseif (tonumber(H) >= 2201 and tonumber(H) <=2400) then 
                        setElementData(killer, "experience.rank", "Corporal") 
  
  
  
  
  
        end 
    end 
end 
addEventHandler( "onPlayerWasted", getRootElement(), win) 
  
function onLogin (_,account) 
    setElementData(source, "LV", getAccountData(account, "LV") or "0") 
    setElementData(source, "EXP", getAccountData(account, "EEXP") or "0") 
    setElementData(source, "player.key", getAccountData(account, "player.key") or "Guest") 
    setElementData(source, "experience.rank", getAccountData(account, "experience.rank") or "Guest") 
end 
addEventHandler ("onPlayerLogin", root, onLogin) 
  
function onLogout (_,account) 
    setElementData(source, "LV", 0) 
    setElementData(source, "EXP", 0) 
    setElementData(source, "reputation.point", 0) 
    setElementData(source, "experience.rank", "Newbie") 
    setElementData(source, "player.key", "Guest") 
end 
addEventHandler ("onPlayerLogout", root, onLogout) 
  
function saveData(thePlayer, theAccount) 
local theAccount = getPlayerAccount(source) 
    if (theAccount and not isGuestAccount(theAccount)) then 
        setAccountData (theAccount, "LV", getElementData(thePlayer, "LV")) 
        setAccountData (theAccount, "EEXP", getElementData(thePlayer, "EXP")) 
        setAccountData (theAccount, "experience.rank", getElementData(thePlayer, "experience.rank")) 
        setAccountData (theAccount, "player.key", getElementData(thePlayer, "player.key")) 
    end 
end 
  
addEventHandler ("onPlayerQuit", root, function () saveData(source, getPlayerAccount(source)) end) 
addEventHandler ("onPlayerLogout", root, function () saveData(source, getPlayerAccount(source)) end) 
--addEventHandler ("onPlayerLogout", root, function (prev) saveData(source, prev) end) 
  
  
addCommandHandler ( "setxp", 
    function ( thePlayer, _, who, EXP ) 
    if getElementData(thePlayer, "player.key") == "Zeyad" then 
    if ( who ) then 
        local EXP = tonumber (EXP) or 0 
        local ThePlayer = getPlayerFromParticalName ( who ) 
        if ( ThePlayer ) then 
            setElementData( ThePlayer,"EXP",EXP ) 
            outputChatBox("Your XP has been set to "..EXP, ThePlayer, 255, 0, 0, true) 
        else 
            outputChatBox("Couldn't find '"..who.."'", thePlayer, 255, 0, 0, true) 
        end 
    else 
        outputChatBox("Couldn't find '"..who.."'", thePlayer, 255, 0, 0, true) 
    end 
    end 
    end 
) 
  
function getPlayerFromParticalName(thePlayerName) 
    local thePlayer = getPlayerFromName(thePlayerName) 
    if thePlayer then 
        return thePlayer 
    end 
    for _,thePlayer in ipairs(getElementsByType("player")) do 
        if string.find(string.gsub(getPlayerName(thePlayer):lower(),"#%x%x%x%x%x%x", ""), thePlayerName:lower(), 1, true) then 

Link to comment

I draw the text in my HUD :)

local XP = getElementData(localPlayer, "EXP") or 0 
    local LV = getElementData(localPlayer, "LV") or 0 
    local rank = getElementData(localPlayer,"experience.rank") or "Newbie" 
  
if XP and LV then 
        dxDrawText("#FF0000XP  #FFFFFF"..XP, sWidth*(670/1280), sHeight*(689/720), sWidth*(621/1280), sHeight*(715/720), tocolor(255, 255, 255, 255), (0.8/1280)*sWidth,(0.8/720)*sHeight,"bankgothic", "left", "top", false, false, true, true, false) 
        dxDrawText("#FF0000LV: #FFFFFF"..LV, sWidth*(350/1280), sHeight*(689/720), sWidth*(372/1280), sHeight*(715/720), tocolor(255, 255, 255, 255), (0.8/1280)*sWidth,(0.8/720)*sHeight,"bankgothic", "left", "top", false, false, true, true, false) 
    end 
  
 if rank then 
dxDrawImage(sWidth*(315/1280), sHeight*(685/720), sWidth*(32/1280), sHeight*(30/720), ":Experience/Emblems/"..rank..".png", 0, 0, 0, tocolor(255, 255, 255, 255), true) 
end 
  
  
  
  

Link to comment

I didn't said it so clear , check how many exp the player have and draw the text how much he exp he need to get the next level. Simple.

elseif (tonumber(H) >= 401 and tonumber(H) <=600) then 
         triggerClientEvent(killer,"drawText",killer) 
end 
  
addEvent ( "drawText", true ) 
function drawText()   
addEventHandler ( "onClientRender", root, TextToNextLevel) 
end 
addEventHandler ( "drawText", root, drawText) 
  
  
  
  
function TextToNextLevel()   
dxDrawText() 
end 

Link to comment

have you considered using tables? e.g

  
local sw,sh = guiGetScreenSize() 
  
levelUpTable = {   -- required experience to level up,e.g if someone is level 1 he would need 500 xp to level up 
[1] = "500", 
[2] = "1000", 
[3] = "2000" 
} 
  
  
-- now draw it 
function levelRequired() 
local experience = getElementData(localPlayer,"EXP") 
local level = getElementData(localPlayer,"LV") 
dxDrawText("Level "..level.." EXP: "..experience.."/"..levelUpTable[level],sw/2,sh/2,sw,sh,tocolor(255,255,255)) 
end 
addEventHandler("onClientRender",root,levelRequired) 

there are better alternatives how to update level data instead of doing it onClientRender but this would work fine

Link to comment
have you considered using tables? e.g
  
local sw,sh = guiGetScreenSize() 
  
levelUpTable = {   -- required experience to level up,e.g if someone is level 1 he would need 500 xp to level up 
[1] = "500", 
[2] = "1000", 
[3] = "2000" 
} 
  
  
-- now draw it 
function levelRequired() 
local experience = getElementData(localPlayer,"EXP") 
local level = getElementData(localPlayer,"LV") 
dxDrawText("Level "..level.." EXP: "..experience.."/"..levelUpTable[level],sw/2,sh/2,sw,sh,tocolor(255,255,255)) 
end 
addEventHandler("onClientRender",root,levelRequired) 

there are better alternatives how to update level data instead of doing it onClientRender but this would work fine

I made client File and Server file in my experience file both didn't work what shall i do ?

  
local sw,sh = guiGetScreenSize() 
  
levelUpTable = { 
[1] = "200", 
[2] = "800", 
[3] = "1600" 
} 
  
function levelRequired() 
local XP = getElementData(localPlayer, "EXP") or 0 
    local LV = getElementData(localPlayer, "LV") or 0 
dxDrawText("LV: "..LV.." XP: "..XP.."/"..levelUpTable[LV],sw/2,sh/2,sw,sh,tocolor(255,255,255)) 
end 
addEventHandler("onClientRender",root,levelRequired) 

Link to comment

That's because script is trying to get data [0] from table which doesn't exist.

I dont know if tables can have [0] as index because i haven't tried it but you could try to do it

otherwise try to set default minimum level to 1 and it will work fine

shortly, it's because your level is currently 0 which is not in the table

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...