Jump to content

[HELP]Level System


lsd1999

Recommended Posts

How to make written under the radar level and exp?

Here is the code:

function experience () 
    for i, pPlayer in ipairs( getElementsByType( "player" ) ) do 
        local pAccount = getPlayerAccount( pPlayer ) 
        local exp = getAccountData(pAccount, "exp") 
        local exps = tonumber(getAccountData(pAccount, "exp")) 
        local lvls = tonumber(getAccountData(pAccount, "lvl")) 
        local needexp = lvls * 4 
        if not exp then 
            setAccountData(pAccount, "exp", 1) 
            setAccountData(pAccount, "allexp", 1) 
            setAccountData(pAccount, "lvl", 1) 
            outputChatBox("Your experience: " .. exps .. "/" .. needexp, getRootElement(), 0, 255, 0) 
        else 
            setAccountData(pAccount, "exp", exps + 1) 
            if exps == needexp then 
                setAccountData(pAccount, "lvl", lvls + 1) 
                setAccountData(pAccount, "exp", 1) 
                outputChatBox("Your lvl is up to " .. lvls + 1 .. "!", getRootElement(), 0, 255, 0) 
            else 
                outputChatBox("Your experience: " .. exps .. "/" .. needexp, getRootElement(), 0, 255, 0) 
            end 
        end 
    end 
end 
setTimer(experience, 3600000, 0) 

Link to comment

Well. You can do like that.

server

function experience () 
    for i, pPlayer in ipairs( getElementsByType( "player" ) ) do 
        local pAccount = getPlayerAccount( pPlayer ) 
        local exp = getAccountData(pAccount, "exp") 
        local exps = tonumber(getAccountData(pAccount, "exp")) 
        local lvls = tonumber(getAccountData(pAccount, "lvl")) 
        local needexp = lvls * 4 
        if not exp then 
            setAccountData(pAccount, "exp", 1) 
            setAccountData(pAccount, "allexp", 1) 
            setAccountData(pAccount, "lvl", 1) 
            outputChatBox("Your experience: " .. exps .. "/" .. needexp, pPlayer, 0, 255, 0) 
        else 
            setAccountData(pAccount, "exp", exps + 1) 
            if exps == needexp then 
                setAccountData(pAccount, "lvl", lvls + 1) 
                setAccountData(pAccount, "exp", 1) 
                outputChatBox("Your lvl is up to " .. lvls + 1 .. "!", pPlayer, 0, 255, 0) 
            else 
                outputChatBox("Your experience: " .. exps .. "/" .. needexp, pPlayer, 0, 255, 0) 
            end 
        end 
        triggerClientEvent ( pPlayer, "drawDxText", pPlayer, exps, needexp ) 
    end 
end 
setTimer(experience, 3600000, 0) 
  
addEventHandler ( "onPlayerLogin", root, 
    function ( _, account ) 
        if ( account ) then 
            local exp = tonumber ( getAccountData ( account, "exp" ) ) 
            local lvl = tonumber ( getAccountData ( account, "lvl" ) ) 
            if ( exp and lvl ) then 
                local needExp = lvl * 4 
                 
                triggerClientEvent ( source, "drawDxText", source, exp, needExp ) 
            end 
        end 
    end 
) 

client

text = "" 
  
addEvent ( "drawDxText", true ) 
addEventHandler ( "drawDxText", root, 
    function ( exp, needExp ) 
        text = exp .. "/" .. needExp 
    end 
) 
  
addEventHandler ( "onClientRender", root, 
    function ( ) 
        if ( string.len ( text ) > 0 ) then 
            dxDrawText ( text, 0, 0 ) 
        end 
    end 
) 

Should work imo. Didn't test.

Link to comment

This will work now, tested code:

text = "" 
  
function setText(xp, nxp) 
    text = "Experience: ".. xp .. "/" .. nxp 
end 
addEvent("drawDxText", true) 
addEventHandler("drawDxText", root, setText) 
  
function renderText() 
    if (#text > 0) then 
        local sw, sh = guiGetScreenSize() 
        dxDrawText (text, 50, sy-50) 
    end 
end 
addEventHandler("onClientRender", root, renderText) 

Now trigger these functions by serverside via:

triggerClientEvent(source, "drawDxText", source, experience, neededExp) -- Here, source is the specific player who will see text under radar. 

Link to comment
Its working fine for me, tell me how are you doing it? It'll show exp under the minimap.

Client

    text = "" 
  
function setText(exp, needexp) 
    text = "Experience: ".. exp .. "/" .. needexp 
end 
addEvent("drawDxText", true) 
addEventHandler("drawDxText", root, setText) 
  
function renderText() 
    if (#text > 0) then 
        local sw, sh = guiGetScreenSize() 
        dxDrawText (text, 50, sy-50) 
    end 
end 
addEventHandler("onClientRender", root, renderText) 

Sever

function experience () 
    for i, pPlayer in ipairs( getElementsByType( "player" ) ) do 
        local pAccount = getPlayerAccount( pPlayer ) 
        local exp = getAccountData(pAccount, "exp") 
        local exps = tonumber(getAccountData(pAccount, "exp")) 
        local lvls = tonumber(getAccountData(pAccount, "lvl")) 
        local needexp = lvls * 4 
        if not exp then 
            setAccountData(pAccount, "exp", 1) 
            setAccountData(pAccount, "allexp", 1) 
            setAccountData(pAccount, "lvl", 1) 
            outputChatBox("Your experience: " .. exps .. "/" .. needexp, pPlayer, 0, 255, 0) 
        else 
            setAccountData(pAccount, "exp", exps + 1) 
            if exps == needexp then 
                setAccountData(pAccount, "lvl", lvls + 1) 
                setAccountData(pAccount, "exp", 1) 
                outputChatBox("Your lvl is up to " .. lvls + 1 .. "!", pPlayer, 0, 255, 0) 
            else 
                outputChatBox("Your experience: " .. exps .. "/" .. needexp, pPlayer, 0, 255, 0) 
            end 
        end 
triggerClientEvent(source, "drawDxText", source, exp, needexp) 
    end 
end 
setTimer(experience, 3600000, 0) 
  
addEventHandler ( "onPlayerLogin", root, 
    function ( _, paccount ) 
        if ( account ) then 
            local exp = tonumber ( getAccountData ( paccount, "exp" ) ) 
            local lvl = tonumber ( getAccountData ( paccount, "lvl" ) ) 
            if ( exp and lvl ) then 
                local needExp = lvl * 4 
                
                triggerClientEvent(source, "drawDxText", source, exp, needexp) 
            end 
        end 
    end 
) 

Link to comment

client

text = "" 
  
function setText(exp, needxp) 
    text = "Experience: ".. exp .. "/" .. needexp 
end 
addEvent("drawDxText", true) 
addEventHandler("drawDxText", root, setText) 
  
function renderText() 
    if (#text > 0) then 
        local sw, sh = guiGetScreenSize() 
        dxDrawText (text, 50, sy-50) 
    end 
end 
addEventHandler("onClientRender", root, renderText) 

server

function experience () 
    for i, pPlayer in ipairs( getElementsByType( "player" ) ) do 
        local pAccount = getPlayerAccount( pPlayer ) 
        local exp = getAccountData(pAccount, "exp") 
        local exps = tonumber(getAccountData(pAccount, "exp")) 
        local lvls = tonumber(getAccountData(pAccount, "lvl")) 
        local needexp = lvls * 4 
        if not exp then 
            setAccountData(pAccount, "exp", 1) 
            setAccountData(pAccount, "allexp", 1) 
            setAccountData(pAccount, "lvl", 1) 
            outputChatBox("Your experience: " .. exps .. "/" .. needexp, pPlayer, 0, 255, 0) 
        else 
            setAccountData(pAccount, "exp", exps + 1) 
            if exps == needexp then 
                setAccountData(pAccount, "lvl", lvls + 1) 
                setAccountData(pAccount, "exp", 1) 
                outputChatBox("Your lvl is up to " .. lvls + 1 .. "!", pPlayer, 0, 255, 0) 
            else 
                outputChatBox("Your experience: " .. exps .. "/" .. needexp, pPlayer, 0, 255, 0) 
            end 
        end 
        triggerClientEvent ( pPlayer, "drawDxText", pPlayer, exps, needexp ) 
    end 
end 
setTimer(experience, 3600000, 0) 
  
addEventHandler ( "onPlayerLogin", root, 
    function ( _, account ) 
        if ( account ) then 
            local exp = tonumber ( getAccountData ( account, "exp" ) ) 
            local lvl = tonumber ( getAccountData ( account, "lvl" ) ) 
            if ( exp and lvl ) then 
                local needExp = lvl * 4 
                
triggerClientEvent(source, "drawDxText", source, experience, needexp) 
            end 
        end 
    end 
) 

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