Jump to content

Need help !!


Recommended Posts

I have another trouble if player like example have in experience 112 he don't move to level 1.

P.S : It was working fine.

here's the lua

exports.scoreboard:scoreboardAddColumn("Level") 
local levels = {[100] = 1, [200] = 2, [300] = 3, [400] = 4, [500] = 5, [1000] = 6, [2500] = 7, [5000] = 8, [7000] = 9, [10000] = 10, [15000] = 11, [20000] = 12, [30000] = 13, [55000] = 14, [65000] = 15} 
function win(ammo, killer, weapon, bodypart) 
    if (killer and killer ~= source) then 
        local H = getElementData(killer, "ExP") 
        local S = getElementData(killer, "Level") 
        local killer1 = getPlayerName(killer) 
        local noob = getPlayerName(source) 
        setElementData(killer, "ExP", tonumber(H)+math.random ( 10, 80 ) ) 
        if levels[tonumber(H)] then 
            setElementData(killer, "Level", "Lvl ".. tostring(levels[tonumber(H)]) .." ! ") 
            triggerClientEvent ( killer, "playSound", killer ) 
        end 
    end 
    local H = getElementData ( source, "ExP" ) or 0 
    setElementData ( source, "ExP", tonumber ( H ) - math.random ( 5, 50 ) ) 
end 
addEventHandler( "onPlayerWasted", getRootElement(), win) 
  
function onLogin (_,account) 
    setElementData(source, "Level", getAccountData(account, "lvl") or "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

Try this :

exports.scoreboard:scoreboardAddColumn( "Level" ); 
  
local levels = {  
    [ 100 ] = 1,  
    [ 200 ] = 2, 
    [ 300 ] = 3,  
    [ 400 ] = 4,  
    [ 500 ] = 5,  
    [ 1000 ] = 6,  
    [ 2500 ] = 7,  
    [ 5000 ] = 8,  
    [ 7000 ] = 9,  
    [ 10000 ] = 10,  
    [ 15000 ] = 11,  
    [ 20000 ] = 12,  
    [ 30000 ] = 13,  
    [ 55000 ] = 14,  
    [ 65000 ] = 15 
}; 
  
function win( ammo, killer, weapon, bodypart ) 
    if killer and killer ~= source then 
        local H = getElementData( killer, "ExP" ); 
        local S = getElementData( killer, "Level" ); 
        local killer1 = getPlayerName( killer ); 
        local noob = getPlayerName( source ); 
        local setData = setElementData( killer, "ExP", tonumber( H ) + math.random( 10, 80 ) ); 
        if setData then 
            if levels[ getElementData( killer, "Exp" ) ] then 
                setElementData( killer, "Level", "Lvl ".. getElementData( killer, "Exp" ) .." ! " ); 
                triggerClientEvent( killer, "playSound", killer ); 
            end 
        end 
    end 
    local _H = getElementData( source, "ExP" ) or 0 
    setElementData( source, "ExP", tonumber( _H ) - math.random( 5, 50 ) ); 
end 
addEventHandler( "onPlayerWasted", root, win ); 
  
function onLogin( _, account ) 
    setElementData( source, "Level", getAccountData( account, "lvl" ) or "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
  • Moderators

Because it only should work when his level is exp is 100 and exact 200....

+ math.random( 10, 80 )

logistic...

loop the table and compare and when you find the right information, break it. -_-"

Link to comment
  • Moderators

Like as sample:

  
local levels = { 
    {100,1}, 
    {200,2}, 
    {300,3}, 
    {400,4}, 
    {500,5}, 
    {1000,6}, 
    {2500,7}, 
    {5000,8}, 
    {7000,9}, 
    {10000,10}, 
    {15000,11}, 
    {20000,12}, 
    {30000,13}, 
    {55000,14}, 
    {65000,15} 
} 
  
local getLevel = function (xp) 
    for i=1,#levels do 
        local position = levels[i] 
        if xp => position[1] then 
            return position[2] 
        end 
    end 
end 
  
-- getLevel(xp) 
  

You also can create your own index start number to save cpu power.

Link to comment
  • Moderators

Maybe you should first test it.

exports.scoreboard:scoreboardAddColumn("Level") 
  
local levels = { 
    {100,1}, 
    {200,2}, 
    {300,3}, 
    {400,4}, 
    {500,5}, 
    {1000,6}, 
    {2500,7}, 
    {5000,8}, 
    {7000,9}, 
    {10000,10}, 
    {15000,11}, 
    {20000,12}, 
    {30000,13}, 
    {55000,14}, 
    {65000,15} 
} 
  
local getLevel = function (xp,level) 
    for i=level,#levels do 
        local position = levels[i] 
        if xp => position[1] then 
            return position[2] 
        end 
    end 
end 
  
function win(ammo, killer, weapon, bodypart) 
    if (killer and killer ~= source) then 
        local H = getElementData(killer, "ExP")  or 0 
        local S = getElementData(killer, "Level") or 0 
        local killer1 = getPlayerName(killer) 
        local noob = getPlayerName(source) 
        setElementData(killer, "ExP", tonumber(H)+math.random ( 10, 80 ) ) 
        local newLevel = getLevel(H,S+1) 
        if newLevel and newLevel ~= S then 
            setElementData(killer, "Level", "Lvl ".. tostring(newLevel) .." ! ") 
            triggerClientEvent ( killer, "playSound", killer ) 
        end 
    end 
    local H = getElementData ( source, "ExP" ) or 0 
    setElementData ( source, "ExP", tonumber ( H ) - math.random ( 5, 50 ) ) 
end 
addEventHandler( "onPlayerWasted", getRootElement(), win) 
  
function onLogin (_,account) 
    setElementData(source, "Level", getAccountData(account, "lvl") or "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
Maybe you should first test it.
exports.scoreboard:scoreboardAddColumn("Level") 
  
local levels = { 
    {100,1}, 
    {200,2}, 
    {300,3}, 
    {400,4}, 
    {500,5}, 
    {1000,6}, 
    {2500,7}, 
    {5000,8}, 
    {7000,9}, 
    {10000,10}, 
    {15000,11}, 
    {20000,12}, 
    {30000,13}, 
    {55000,14}, 
    {65000,15} 
} 
  
local getLevel = function (xp,level) 
    for i=level,#levels do 
        local position = levels[i] 
        if xp => position[1] then 
            return position[2] 
        end 
    end 
end 
  
function win(ammo, killer, weapon, bodypart) 
    if (killer and killer ~= source) then 
        local H = getElementData(killer, "ExP")  or 0 
        local S = getElementData(killer, "Level") or 0 
        local killer1 = getPlayerName(killer) 
        local noob = getPlayerName(source) 
        setElementData(killer, "ExP", tonumber(H)+math.random ( 10, 80 ) ) 
        local newLevel = getLevel(H,S+1) 
        if newLevel and newLevel ~= S then 
            setElementData(killer, "Level", "Lvl ".. tostring(newLevel) .." ! ") 
            triggerClientEvent ( killer, "playSound", killer ) 
        end 
    end 
    local H = getElementData ( source, "ExP" ) or 0 
    setElementData ( source, "ExP", tonumber ( H ) - math.random ( 5, 50 ) ) 
end 
addEventHandler( "onPlayerWasted", getRootElement(), win) 
  
function onLogin (_,account) 
    setElementData(source, "Level", getAccountData(account, "lvl") or "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) 

ok i will test ...and thanks dude.

Link to comment
  • Moderators

Saw another mistake, the new xp wasn't calculated for the leveling, but only for the elementdata. Of course in time it would be come correct, but it would not logistic. It have to be done within the locals.

Tell me if something doesn't work, I did not really test it. Based on logistic.

exports.scoreboard:scoreboardAddColumn("Level") 
  
local levels = { 
    {100,1}, 
    {200,2}, 
    {300,3}, 
    {400,4}, 
    {500,5}, 
    {1000,6}, 
    {2500,7}, 
    {5000,8}, 
    {7000,9}, 
    {10000,10}, 
    {15000,11}, 
    {20000,12}, 
    {30000,13}, 
    {55000,14}, 
    {65000,15} 
} 
  
local getLevel = function (xp,level) 
    for i=level,#levels do 
        local position = levels[i] 
        if xp >= position[1] then 
            local position2 = levels[i+1] 
            if position2 and xp < position2[1] then -- this is for the future when you are going to give more xp. 
                return position[2] 
            end 
        else 
            return false -- he didn't reached the next level. 
        end 
    end 
end 
  
function win(ammo, killer, weapon, bodypart) 
    if (killer and killer ~= source) then 
        local H = tonumber(getElementData(killer, "ExP")) or 0 
        local S = getElementData(killer, "Level") or 0 
        local killer1 = getPlayerName(killer) 
        local noob = getPlayerName(source) 
        local newXP = H+math.random ( 10, 80 ) -- new xp, for the elementdata and level finder. 
        setElementData(killer, "ExP", newXP )  
        if S < #levels then -- stop doing things when he reached max level  
            local newLevel = getLevel(newXP,S+1) 
            if newLevel and newLevel ~= S then 
                setElementData(killer, "Level", "Lvl ".. tostring(newLevel) .." ! ") 
                triggerClientEvent ( killer, "playSound", killer ) 
            end 
        end 
    end 
    local H = tonumber (getElementData ( source, "ExP" )) or 0 
    setElementData ( source, "ExP", H - math.random ( 5, 50 ) ) 
end 
addEventHandler( "onPlayerWasted", getRootElement(), win) 
  
function onLogin (_,account) 
    setElementData(source, "Level", getAccountData(account, "lvl") or "0") 
    setElementData(source, "ExP", getAccountData(account, "exp") or "0") 
end 
addEventHandler ("onPlayerLogin", root, onLogin) 
  
local saveData = function (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
  • Moderators
i tried both, not working.

Cause? I am not going to test it, it is your code.

It is your job to debug it, not mine. I can't help you if the only thing you say is "not working".

A system like that require lots of brain power, if you want it working then you have to debug it.

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