Jump to content

Exp system


Recommended Posts

Posted

Hello i have this exp_system and i want two things on it i tryed but not working here is the lua

exports.scoreboard:scoreboardAddColumn("ExP") 
exports.scoreboard:scoreboardAddColumn("Level") 
local levels = {[1] = 1, [50] = 2, [75] = 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)+75) 
        if levels[tonumber(H)] then 
            setElementData(killer, "Level", "Lvl ".. tostring(levels[tonumber(H)]) .." !") 
            triggerClientEvent ( killer, "playSound", killer ) 
        end 
    end 
end 
addEventHandler( "onPlayerWasted", getRootElement(), win) 
  
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) 

I want when player kill somebody he earn Random Experience i tryed adding this but not working math.random ( 5, 35 )

and when he get killed by somebody who had a higher exp he lose like math.random ( -5, -35 )

Thanks for helping

  • Replies 53
  • Created
  • Last Reply

Top Posters In This Topic

Posted
exports.scoreboard:scoreboardAddColumn("ExP") 
exports.scoreboard:scoreboardAddColumn("Level") 
local levels = {[1] = 1, [50] = 2, [75] = 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 ( 5, 35 ) ) 
        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, 35 ) ) 
end 
addEventHandler( "onPlayerWasted", getRootElement(), win) 
  
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) 

Posted

Thanks a lot bro you're the best and one more thing please

The command of get player experience dont work

function getRep ( commandName, playerName ) 
    if ( playerName ) then 
        local thePlayer = getPlayerFromName ( playerName ) 
        if ( thePlayer ) then 
            local ExP = getElementData ( thePlayer, "ExP" ) 
            outputChatBox ( getPlayerName ( thePlayer ) .." Reputation is ".. ExP "!", source ) 
        else 
            outputChatBox ( "Couldn't find '" .. playerName .. "'", source ) 
        end 
    end 
end 
addCommandHandler ( "getrep", getRep ) 

Posted (edited)

yes

can i remove " Lvl " and "!" from

            setElementData(killer, "Level", "Lvl ".. tostring(levels[tonumber(H)]) .." !") 

because when i remove it the script being crashed

Edited by Guest
Posted
function getRep ( _, playerName ) 
    if ( playerName ) then 
        local thePlayer = getPlayerFromName ( playerName ) 
        if ( thePlayer ) then 
            local ExP = getElementData ( thePlayer, "ExP" ) or 0 
            outputChatBox ( getPlayerName ( thePlayer ) .." Reputation is ".. tostring ( ExP ) .."!" ) 
        else 
            outputChatBox ( "Couldn't find '" .. playerName .. "'", source ) 
        end 
    end 
end 
addCommandHandler ( "getrep", getRep ) 

Posted

Castillo, i tryed this but not working can you fix it please

This for set player exp

addCommandHandler ( "setexp", 
    function ( thePlayer, commandName, theExP ) 
                local theExP = tonumber ( theExP ) or 0 
        exports.exp_system:setPlayerExP ( thePlayer, theExP ) 
    end 
) 

and this for set player level

addCommandHandler ( "setlevel", 
    function ( thePlayer, commandName, theLevel ) 
                local theLevel = tonumber ( theLevel ) or 1 
        exports.exp_system:setPlayerLevel ( thePlayer, theLEvel ) 
    end 
) 

Posted

yes on meta

    function="getPlayerLevel" type="server" /> -- arguments: thePlayer --> 
    function="setPlayerLevel" type="server" /> -- arguments: thePlayer, theLevel  --> 
    function="getPlayerEXP" type="server" /> -- arguments: thePlayer --> 
    function="setPlayerEXP" type="server" /> -- arguments: thePlayer, theExperience  -->   
    function="addPlayerEXP" type="server" /> -- arguments: thePlayer, theExperience  -->   
     
    function="getAccountLevel" type="server" /> -- arguments: theAccount --> 
    function="setAccountLevel" type="server" /> -- arguments: theAccount, theLevel  --> 
    function="getAccountEXP" type="server" /> -- arguments: theAccount --> 
    function="setAccountEXP" type="server" /> -- arguments: theAccount, theExperience  -->     
    function="addAccountEXP" type="server" /> -- arguments: theAccount, theExperience  --> 
    function="getLevelData" type="server" /> -- arguments: theLevel  --> 

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 
) 

Posted
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 ?

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