levels plus XP
#1

Hello I have been working on making an Levels system where you level up everytime you get XP, but the xp always stays the same, like when you first start, you're level 0, when you get 150XP you're level 1, then another 150XP and you're level 2, I want the XP to go up with the level, So to get to level 1 you need 150XP, to level 2 300XP, level 3 350xp etc, how would I do this without making the script look spammed and messy?
this is on PlayerUpdate, the levels and xp are saved, using Y_ini, unlike you should need it to help me out here
pawn Код:
if(pInfo[playerid][XP] > 100)
    {
            new str[85];
            pInfo[playerid][Level] += 1;
            pInfo[playerid][XP] = 0;
            GivePlayerCash(playerid, 1500);
            format(str, sizeof(str), "You have leveled up to level %d", pInfo[playerid][Level]);
            SCM(playerid, pink, str);
    }
Thank you if you're able to help me out here! + rep for anyone who can
Reply
#2

we cant tell without the whole code/function...
How are the XPs increased?

//Edit:
Do not use OnPlayerUpdate for such stuff, that is really not neccessary.
Instead u can check everytime a player's XP status has changed.
Reply
#3

Once more, stop using OnPlayerUpdate for these kinds of things! You control when XP is given. It is at that point that you need to intercept it. Write a function live "GiveXP(playerid, amount)". In that function you check whether they have reached the required amount.



You need a formula like this one:

XP = (1.05 ^ level) * 150

Where ^ means power. Change the 1.05 to whatever suits your need. Put the formula in Excel so you can fiddle around with it.
Reply
#4

What do you mean about not using Update, if i use a timer and there are a lot of players online, it could lag, could you explain how to make the function so i don't keep using onplayerupdate, thanks for replying!

Quote:

we cant tell without the whole code/function...
How are the XPs increased?

That is the whole code, I have not got anything for the XP yet, I am working on a jobs system, which will give the xp when doing, the giving code should look something like this:
pawn Код:
pInfo[playerid][XP] += 1;
Reply
#5

NO, timers often are not that bad as many players think they are!
Its funny how people often suppose timers will lag the server (most cases timers are set to an intervall of 1000ms or higher)
while OnPlayerUpdate is executed about each 36ms PER player!

You could use a timer to accomplish this but you could also check JUST once everytime you update/increase the XP points of a player.
If the new XP status then is high enough for the new level you can announce it, reset the XP or do whatever you want to.
In that case you only check when its really needed and not every 36ms (like in OnPlayerUpdate).
Reply
#6

Don't you get it? You don't need ANY timers WHATSOEVER! When you need to give a player XP you do this:

pawn Код:
GiveXP(playerid, 1);
Then you write the corresponding function:

pawn Код:
GiveXP(playerid, amount)
{
    pInfo[playerid][XP] += amount;

    new requiredXP = floatround(floatpower(1.05, pInfo[playerid][Level]) * 150);

    if(pInfo[playerid][XP] >= requiredXP)
    {
        pInfo[playerid][Level] += 1;
    }
}
Reply
#7

maybe a bit less confusing for beginners

pawn Код:
GiveXP(playerid, amount)
{
    pInfo[playerid][XP] += amount;
    switch(pInfo[playerid][XP])
    {
        case 50,100,150,200:pInfo[playerid][Level]++;//what XP will increase level.
        default: return 1;
    }
}
Reply
#8

Quote:
Originally Posted by BlackWolf120
Посмотреть сообщение
maybe a bit less confusing for beginners

pawn Код:
GiveXP(playerid, amount)
{
    pInfo[playerid][XP] += amount;
    switch(pInfo[playerid][XP])
    {
        case 50,100,150,200:pInfo[playerid][Level]++;//what XP will increase level.
        default: return 1;
    }
}
eh NO. what if the exp is between 150 and 200 or other values then this wont work..

Use what Vince told..
Reply
#9

Ok, thanks for helping guys, I will test it when I'm home, and tell you if it worked or not
Reply
#10

Ok, Vince post helped, But before i use anything, I want to find out more about it so if it bugs i can fix it, what does this do?
Код:
new requiredXP = floatround(floatpower(1.05, pInfo[playerid][Level]) * 150);
I know most of it just don't know the 1.05 part or how it helps, Thanks if you are able to explain it!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)