Jump to content

Level no up.[mission complete]


slotman

Recommended Posts

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

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 
) 

Link to comment
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.

Link to comment

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.

Link to comment

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 
) 

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