Jump to content

Level system advanced


-Doc-

Recommended Posts

  • 1 month later...
I need a example how to make level system please just a example

I am not familiar with the sql funcions, i think you just retrive the data from sql data base, the current level and exp, for example you are level 7, and you have 200 exp. lvl 7 to lvl 8 needs 500 exp, so your position is 200 / 500. Now everytime you get exp you save it in sql database, and before that you do a calculation, see if the ammount of exp you got exceed the ammount needed to lvl up. For example you got 200 exp 500 - 200 = 300 ( the ammount of exp needed to lvl up) 300 - 200 = 100 so this havnt exceed the ammount of exp needed to lvl up. If you get 500 exp 500 - 300 = 200, the ammount of exp you got exceed by 200 of the ammount of exp you need. So you make this player lvl up and save it in database, and after lvl up add 200 to his current exp progress, e.g. now he is lvl 8 and he needs 800 to lvl up, now his pos is 200 / 800.

Link to comment

Server

function givePlayerXP ( source, valve ) 
    local finalXP = valve 
    local currXP = getElementData ( source, "xp" ) or 0  
    local level = getElementData ( source, "level" ) 
    local nextXP = 50*level 
    setElementData ( source, "xp", currXP + finalXP ) 
    if currXP+finalXP > nextXP then 
        setElementData ( source, "xp", 0 ) 
        setElementData ( source, "level", level + 1 ) 
        outputChatBox ("Rank up"..tostring(level+1), source, 255, 25, 0, true)) 
  
    end 
end 

give xp use: givePlayerXP (killer,10)

Client:

    local level = getElementData ( localPlayer, "level" ) 
    local xp = getElementData ( localPlayer, "xp" ) 
    dxDrawText ("Level: "..level, 15, y-50, 200, y, tocolor ( 100, 255, 100, 200 ), 1.1, "default-bold" ) 
    dxDrawText ("XP: "..xp.."/"..tostring(level*50), 15, y-25, 200, y, tocolor ( 100, 255, 100, 200 ), 1.02, "default-bold" ) 

I wore it once, do not remember the author's name only remember who posted on a Russian forum

Link to comment
But if i want change exp needed and max level?

Dude, you really need to do it on yourself, you can't always rely on other people, specially when you are developing a server

Why do you need to go to every single topic like this, and tell people this? No offense.

Link to comment
But if i want change exp needed and max level?

Dude, you really need to do it on yourself, you can't always rely on other people, specially when you are developing a server

Why do you need to go to every single topic like this, and tell people this? No offense.

That's a hobby of some MTA forum members.

OT:

  
levels = { 
 {exp=100}, 
 {exp=250}, 
 {exp=500}, 
 {exp=600} 
} 
 maxlvl = 4 
    function givePlayerXP ( source, valve ) 
        local finalXP = valve 
        local currXP = getElementData ( source, "xp" ) or 0 
        local level = getElementData ( source, "level" ) or 1 
        local nextXP = levels[level].exp 
        
        if currXP+finalXP >= nextXP and maxlvl > level then 
            setElementData ( source, "xp", 0 ) 
            setElementData ( source, "level", level + 1 ) 
            outputChatBox ("Rank up"..tostring(level+1), source, 255, 25, 0, true)) 
       else 
            setElementData ( source, "xp", currXP + finalXP ) 
        end 
    end 
  

I used tables then I edited #Thug's function.

Change maxlvl, and don't forget to add levels into the table like what I did.

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