Jump to content

Level no up.[mission complete]


slotman

Recommended Posts

Posted (edited)

Exp up but Level no up. Zombie sever

Client

function levelup () 
    local Exp = getElementData(localPlayer,"ExP") 
    local Level = getElementData(localPlayer,"Level") 
    if isElement(expLabel) then destroyElement(expLabel) end 
    expLabel = guiCreateLabel(0.777,0.22,0.1708,0.0963,"ExP gained: ??\nTotal ExP: ".. tostring(Exp) .."\nLevel: ".. tostring(Level),true) 
    guiLabelSetColor(expLabel,0,255,0) 
    guiLabelSetVerticalAlign(expLabel,"top") 
    guiLabelSetHorizontalAlign(expLabel,"left",false) 
    guiSetFont(expLabel,"clear-normal") 
    setTimer ( levelup, 2000, 1) 
end 
setTimer ( levelup, 2000, 1) 

 

Server

exports.scoreboard:scoreboardAddColumn("ExP") 
exports.scoreboard:scoreboardAddColumn("Level") 
local levels = {[30] = 1, [55] = 2, [75] = 3, [85] = 4, [95] = 5, [120] = 6, [150] = 7, [230] = 8, [350] = 9, [500] = 10} 
  
addEvent("onZombieWasted",true) 
addEventHandler("onZombieWasted",root, 
function (killer) 
    addPlayerZombieKills(killer) 
end) 
  
function addPlayerZombieKills(killer) 
    local account = getPlayerAccount(killer) 
    if isGuestAccount(account) then return end 
        local H = getElementData(killer, "ExP") 
        local S = getElementData(killer, "Level") 
        setElementData(killer, "ExP", tonumber(H)+5) 
        if levels[tonumber(H)] then 
            setElementData(killer, "Level", "lvl ".. tostring(levels[tonumber(H)]) .." !") 
            triggerClientEvent ( killer, "playSound", killer ) 
        end 
    end 
  
function onLogin (_,account) 
    setElementData(source, "Level", getAccountData(account, "lvl") or "Level 0 !") 
    setElementData(source, "ExP", getAccountData(account, "exp") or "0") 
end 
addEventHandler ("onPlayerLogin", root, onLogin) 
  
function saveData(thePlayer, theAccount) 
    if (theAccount and not isGuestAccount(theAccount)) then 
        setAccountData (theAccount, "lvl", getElementData(thePlayer, "Level")) 
        setAccountData (theAccount, "exp", getElementData(thePlayer, "ExP")) 
    end 
end 
  
addEventHandler ("onPlayerQuit", root, function () saveData(source, getPlayerAccount(source)) end) 
addEventHandler ("onPlayerLogout", root, function (prev) saveData(source, prev) end) 

Edited by Guest
Posted

Well, it should work if your experience is on the table.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

I've tested your script first, it seemed to work, although, I made some changes.

-- client side:

function levelup ( ) 
    if isElement ( expLabel ) then 
        destroyElement ( expLabel ) 
    end 
  
    local Exp = getElementData ( localPlayer, "ExP" ) 
    local Level = getElementData ( localPlayer, "Level" ) 
    expLabel = guiCreateLabel ( 0.777, 0.22, 0.1708, 0.0963, "ExP gained: ??\nTotal ExP: ".. tostring ( Exp ) .."\nLevel: ".. tostring ( Level ), true ) 
    guiLabelSetColor ( expLabel, 0, 255, 0 ) 
    guiLabelSetVerticalAlign ( expLabel, "top" ) 
    guiLabelSetHorizontalAlign ( expLabel, "left", false ) 
    guiSetFont ( expLabel, "clear-normal" ) 
    setTimer ( levelup, 2000, 1 ) 
end 
setTimer ( levelup, 2000, 1 ) 

-- server side:

exports.scoreboard:scoreboardAddColumn ( "ExP" ) 
exports.scoreboard:scoreboardAddColumn ( "Level" ) 
local levels = 
    { 
        [ 30 ] = 1, 
        [ 55 ] = 2, 
        [ 75 ] = 3, 
        [ 85 ] = 4, 
        [ 95 ] = 5, 
        [ 120 ] = 6, 
        [ 150 ] = 7, 
        [ 230 ] = 8, 
        [ 350 ] = 9, 
        [ 500 ] = 10 
    } 
  
addEvent ( "onZombieWasted", true ) 
addEventHandler ( "onZombieWasted", root, 
    function ( killer ) 
        addPlayerZombieKills ( killer ) 
    end 
) 
  
function addPlayerZombieKills ( killer ) 
    local account = getPlayerAccount ( killer ) 
    if isGuestAccount ( account ) then 
        return 
    end 
  
    local H = tonumber ( getElementData ( killer, "ExP" ) ) or 0 
    setElementData ( killer, "ExP", tonumber ( H ) + 5 ) 
    local H = ( H + 5 ) 
    if ( levels [ H ] ) then 
        setElementData ( killer, "Level", "lvl ".. tostring ( levels [ H ] ) .." !" ) 
        triggerClientEvent ( killer, "playSound", killer ) 
    end 
end 
  
function onLogin ( _, account ) 
    setElementData ( source, "Level", getAccountData ( account, "lvl" ) or "Level 0 !" ) 
    setElementData ( source, "ExP", getAccountData ( account, "exp" ) or "0" ) 
end 
addEventHandler ( "onPlayerLogin", root, onLogin ) 
  
function saveData ( thePlayer, theAccount ) 
    if ( theAccount and not isGuestAccount ( theAccount ) ) then 
        setAccountData ( theAccount, "lvl", getElementData ( thePlayer, "Level" ) ) 
        setAccountData ( theAccount, "exp", getElementData ( thePlayer, "ExP" ) ) 
    end 
end 
  
addEventHandler ( "onPlayerQuit", root, 
    function ( ) 
        saveData ( source, getPlayerAccount ( source ) ) 
    end 
) 
  
addEventHandler ( "onPlayerLogout", root, 
    function ( prev ) 
        saveData ( source, prev ) 
    end 
) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Works fine here, post your meta.xml.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Should work, are you logged in?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
exports.scoreboard:scoreboardAddColumn ( "ExP" ) 
exports.scoreboard:scoreboardAddColumn ( "Level" ) 
local levels = 
    { 
        [ 30 ] = 1, 
        [ 55 ] = 2, 
        [ 75 ] = 3, 
        [ 85 ] = 4, 
        [ 95 ] = 5, 
        [ 120 ] = 6, 
        [ 150 ] = 7, 
        [ 230 ] = 8, 
        [ 350 ] = 9, 
        [ 500 ] = 10 
    } 
  
addEvent ( "onZombieWasted", true ) 
addEventHandler ( "onZombieWasted", root, 
    function ( killer ) 
        addPlayerZombieKills ( killer ) 
    end 
) 
  
function addPlayerZombieKills ( killer ) 
    local account = getPlayerAccount ( killer ) 
    if isGuestAccount ( account ) then 
        return 
    end 
  
    local H = tonumber ( getElementData ( killer, "ExP" ) ) or 0 
    outputChatBox ( "Cur experience: ".. tostring ( H ) ) 
    setElementData ( killer, "ExP", tonumber ( H ) + 5 ) 
    local H = ( H + 5 ) 
    outputChatBox ( "New experience: ".. tostring ( H ) ) 
    if ( levels [ H ] ) then 
        setElementData ( killer, "Level", "lvl ".. tostring ( levels [ H ] ) .." !" ) 
        triggerClientEvent ( killer, "playSound", killer ) 
    else 
        outputChatBox ( "No level for experience: ".. tostring ( H ) ) 
    end 
end 
  
function onLogin ( _, account ) 
    setElementData ( source, "Level", getAccountData ( account, "lvl" ) or "Level 0 !" ) 
    setElementData ( source, "ExP", getAccountData ( account, "exp" ) or "0" ) 
end 
addEventHandler ( "onPlayerLogin", root, onLogin ) 
  
function saveData ( thePlayer, theAccount ) 
    if ( theAccount and not isGuestAccount ( theAccount ) ) then 
        setAccountData ( theAccount, "lvl", getElementData ( thePlayer, "Level" ) ) 
        setAccountData ( theAccount, "exp", getElementData ( thePlayer, "ExP" ) ) 
    end 
end 
  
addEventHandler ( "onPlayerQuit", root, 
    function ( ) 
        saveData ( source, getPlayerAccount ( source ) ) 
    end 
) 
  
addEventHandler ( "onPlayerLogout", root, 
    function ( prev ) 
        saveData ( source, prev ) 
    end 
) 

Try that and tell me what does it output to chat box.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

I told you to post here what did it say.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

That's obviously, you don't have the value 2486 on your levels table:

local levels = 
    { 
        [ 30 ] = 1, 
        [ 55 ] = 2, 
        [ 75 ] = 3, 
        [ 85 ] = 4, 
        [ 95 ] = 5, 
        [ 120 ] = 6, 
        [ 150 ] = 7, 
        [ 230 ] = 8, 
        [ 350 ] = 9, 
        [ 500 ] = 10 
    } 

See? your script searches for the experience on that table, if there is, you level up.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

The way your script works is not good, because if the exact experience is not on the levels table, it won't level up.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

I made your script to work different, this way it'll work.

-- client side:

function levelup ( ) 
    if isElement ( expLabel ) then 
        destroyElement ( expLabel ) 
    end 
  
    local Exp = getElementData ( localPlayer, "ExP" ) or 0 
    local Level = getElementData ( localPlayer, "Level" ) or 0 
    expLabel = guiCreateLabel ( 0.777, 0.22, 0.1708, 0.0963, "ExP gained: ??\nTotal ExP: ".. tostring ( Exp ) .."\nLevel: ".. tostring ( Level ), true ) 
    guiLabelSetColor ( expLabel, 0, 255, 0 ) 
    guiLabelSetVerticalAlign ( expLabel, "top" ) 
    guiLabelSetHorizontalAlign ( expLabel, "left", false ) 
    guiSetFont ( expLabel, "clear-normal" ) 
    setTimer ( levelup, 2000, 1 ) 
end 
setTimer ( levelup, 2000, 1 ) 

-- server side:

exports.scoreboard:scoreboardAddColumn ( "ExP" ) 
exports.scoreboard:scoreboardAddColumn ( "Level" ) 
local levels = 
    { 
        30, 
        55, 
        75, 
        85, 
        95, 
        120, 
        150, 
        230, 
        350, 
        500 
    } 
  
addEvent ( "onZombieWasted", true ) 
addEventHandler ( "onZombieWasted", root, 
    function ( killer ) 
        addPlayerZombieKills ( killer ) 
    end 
) 
  
function addPlayerZombieKills ( killer ) 
    local account = getPlayerAccount ( killer ) 
    if isGuestAccount ( account ) then 
        return 
    end 
  
    local H = tonumber ( getElementData ( killer, "ExP" ) ) or 0 
    local L = tonumber ( getElementData ( killer, "Level" ) ) or 0 
    setElementData ( killer, "ExP", tonumber ( H ) + 5 ) 
    local H = ( H + 5 ) 
    local L = ( L + 1 ) 
    if ( L <= #levels ) and ( levels [ L ] ) and ( tonumber ( H ) >= tonumber ( levels [ L ] ) ) then 
        setElementData ( killer, "Level", L ) 
        triggerClientEvent ( killer, "playSound", killer ) 
    end 
end 
  
function onLogin ( _, account ) 
    setElementData ( source, "Level", getAccountData ( account, "lvl" ) or "Level 0 !" ) 
    setElementData ( source, "ExP", getAccountData ( account, "exp" ) or "0" ) 
end 
addEventHandler ( "onPlayerLogin", root, onLogin ) 
  
function saveData ( thePlayer, theAccount ) 
    if ( theAccount and not isGuestAccount ( theAccount ) ) then 
        setAccountData ( theAccount, "lvl", getElementData ( thePlayer, "Level" ) ) 
        setAccountData ( theAccount, "exp", getElementData ( thePlayer, "ExP" ) ) 
    end 
end 
  
addEventHandler ( "onPlayerQuit", root, 
    function ( ) 
        saveData ( source, getPlayerAccount ( source ) ) 
    end 
) 
  
addEventHandler ( "onPlayerLogout", root, 
    function ( prev ) 
        saveData ( source, prev ) 
    end 
) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

You're welcome.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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