Jump to content

Exp system


Recommended Posts

  • Replies 53
  • Created
  • Last Reply

Top Posters In This Topic

Posted

im not using level.xml

im using this

exports.scoreboard:scoreboardAddColumn("ExP") 
exports.scoreboard:scoreboardAddColumn("Level") 
local levels = {[50] = 1, [100] = 2, [175] = 3, [240] = 4, [950] = 5, [1200] = 6, [2000] = 7, [5000] = 8, [9963] = 9, [20000] = 10, [100000] = 11} 
  
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) 

and if i want change levels to like Example

Level 1 : Rookie

Level 2 : Amateur

Level 3 : Semi-pro

Level 4 : Pro

Level 5 : ELITE

Level 6 : Boss

can you help me ?

Do you want set the player level if write [[command]] ?

or do you want set the level name ?

Level change local levels to level name

Posted

First, stop DOUBLE/TRIPLE posting, because is annoying.

Second, you can add a second value to your levels table, defining the name of the level.

Posted

Like that ?

exports.scoreboard:scoreboardAddColumn("ExP") 
exports.scoreboard:scoreboardAddColumn("Level") 
local levels = {[50] = Rookie, [100] = Amateur, [175] = SemiPro, [240] = Pro, [950] = Elite, [1200] = Boss, [2000] = Hero, [5000] = Evil, [9963] = Demon, [20000] = Criminal} 
  
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) 

Posted

Is there a solution that if i removed the local levels

local levels = {[1] = 1, [50] = 2, [75] = 3, [240] = 4, [950] = 5, [1200] = 6, [2000] = 7, [5000] = 8, [9963] = 9, [20000] = 10, [100000] = 11} 

it load levels from levels.xml ?

    "Rookie" experienceRequired = "2" /> 
    "Amateur" experienceRequired = "100" /> 
    "Semi-Pro" experienceRequired = "150" /> 
    "Pro" experienceRequired = "200" /> 
    "ELITE" experienceRequired = "2000" /> 

Posted
addCommandHandler ( "setexp", 
    function ( thePlayer, _, who, theExP ) 
        local theExP = tonumber ( theExP ) or 0 
        local playerWho = getPlayerFromName ( who ) 
        if ( playerWho ) then 
            exports.exp_system:setPlayerEXP ( playerWho, theExP ) 
        end 
    end 
) 

it was working fine now it show a error in console

ERROR: attempt to call a nil value [string"?"]

ERROR: call:failed to call 'exp_system:setPlayerEXP' [string"?"]

help

Posted

Yes

addCommandHandler ( "setexp", 
    function ( thePlayer, _, who, theExP ) 
        local theExP = tonumber ( theExP ) or 0 
        local playerWho = getPlayerFromName ( who ) 
        if ( playerWho ) then 
            exports.exp_system:setPlayerEXP ( playerWho, theExP ) 
        end 
    end 
) 

Posted

To me, it looks like you've copied the exports from the meta.xml of my "exp_system" and pasted it on that resource, without the actual functions, it won't work.

Posted

no another one

using this

exports.scoreboard:scoreboardAddColumn("ExP") 
exports.scoreboard:scoreboardAddColumn("Level") 
local levels = {[50] = 1, [100] = 2, [175] = 3, [240] = 4, [950] = 5, [1200] = 6, [2000] = 7, [5000] = 8, [9963] = 9, [20000] = 10, [100000] = 11} 
  
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) 

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