Creating an experience system:
#1

I've been reading a tutorial for this purpose but it doesn't really help me much. I'm adding an experience system within my server. I want the player to level up after obtaining 1000 experience points by doing several things (I won't encourage killing, so players will get experience points for being online, completing missions, jobs, etc.). I'm not really sure how I could do this sort of system, therefore requiring your help.

pawn Код:
enum pInfo
{
    pPass, // un-needed
    pCash, // un-needed
    pAdmin, // un-needed
    pSex, // un-needed
    pAge, // un-needed
    pLevel,
    pEXP,
    Float:pPos_x, // un-needed
    Float:pPos_y, // un-needed
    Float:pPos_z, // un-needed
    pSkin, // un-needed
    pCrew // un-needed
}
To sum it up: For each 1000 experience points a player has, he levels up (using SetPlayerScore for that). I'd be very grateful If you could help me out.
Reply
#2

PHP код:
stock AddPlayerEXP(playerid,xp)
{
    
pEXP pEXP xp;
    if(
pEXP >= 1000)
    {
        
SetPlayerScore(playerid,GetPlayerScore(playerid) + 1);
        
pEXP pEXP 1000;
        
pLevel++;
    }
    return 
1;

Reply
#3

Quote:
Originally Posted by [Bios]Marcel
Посмотреть сообщение
PHP код:
stock AddPlayerEXP(playerid,xp)
{
    
pEXP pEXP xp;
    if(
pEXP >= 1000)
    {
        
SetPlayerScore(playerid,GetPlayerScore(playerid) + 1);
        
pEXP pEXP 1000;
        
pLevel++;
    }
    return 
1;

Added the pLevel++;
Reply
#4

where do u use the enums? I mean something like PlayerInfo[].... Should be there.Post it also so that i can help u.
Reply
#5

Quote:
Originally Posted by _Mohit_
Посмотреть сообщение
where do u use the enums? I mean something like PlayerInfo[].... Should be there.Post it also so that i can help u.
pawn Код:
enum pInfo
{
    pPass,
    pCash,
    pAdmin,
    pSex,
    pAge,
    pLevel,
    pEXP,
    Float:pPos_x,
    Float:pPos_y,
    Float:pPos_z,
    pSkin,
    pCrew
}
new PlayerInfo[MAX_PLAYERS][pInfo];
@[Bios]Marcel: What If I want to add a specific ammount of EXP to the player's EXP?
Reply
#6

I use this to check a similar system, if it's what you're looking for.

pawn Код:
if (!(PlayerInfo[pid][pEXP] % 1000))
{
    //level up or whatever in here.
}
Reply
#7

Maybe something like this?

pawn Код:
#define EXP_ACHIEVMENT (1000)

#define SetPlayerEXP(%0,%1) \
        PlayerInfo[%0][pEXP] = %1, CheckPlayerEXP(%0)

#define GetPlayerEXP(%0) \
        PlayerInfo[%0][pEXP]

CheckPlayerEXP(playerid)
{
    if(PlayerInfo[playerid][pEXP] >= EXP_ACHIEVMENT) //1, 000
    {
        //code here
    }
    if(PlayerInfo[playerid][pEXP] >= EXP_ACHIEVMENT * 2) //2, 000
    {
        //code here
    }
    if(PlayerInfo[playerid][pEXP] >= EXP_ACHIEVMENT * 3) //3, 000
    {
        //code here
    }        
}
Reply
#8

Okay, so I'll assume you are an experienced scripter who knows his way around, I'll just tell you the stages, generally.

You want to have an EXP variable for each player, preferably in an enum.
Each time you give a player EXP (such as completing a mission) you will want to see how much EXP he/she will have after you give him/her the EXP, if it's over 1000 (assuming you'll level up only at 1000 no matter what level you are at) you will want to get the difference between 1000 and his current EXP:
example: Player A has 600 EXP and you're giving him 500 EXP we don't 100 EXP to go to waste, so you will have to do 1000 - 600 = 400. You will then subtract 400 from the 500, you will level him up and SET (not add) his EXP to the remaining of the 500 which in this case is 100.

Also you'll probably want to save his data somewhere (a .ini file, a database) I guess that's it.
Reply
#9

pawn Код:
#include <a_samp>
#include <zcmd>

enum PlayerInfo
{
    Exp,
    CurExp,
    Level,
}
new pInfo[MAX_PLAYERS][PlayerInfo];

CMD:test(playerid, params[])
{
    SetTimer("LevelTimer", 1800000, true);
   
    pInfo[playerid][Exp] = 8;
    pInfo[playerid][Level] = 1;
   
    return 1;
}

forward LevelTimer(playerid);
public LevelTimer(playerid)
{
    new string[128];
   
    if(pInfo[playerid][CurExp] != pInfo[playerid][Exp])
    {
        pInfo[playerid][CurExp] += 1;

        format(string, sizeof(string), "SERVER:{FFFFFF} Level progression: {BF4B4B}%d{FFFFFF}/{60B34B}%d{FFFFFF}. Next payday in 30 minutes.", pInfo[playerid][CurExp], pInfo[playerid][Exp]);
        SendClientMessage(playerid, 0x46E850FF, string);
    }
   
    else if(pInfo[playerid][CurExp] == pInfo[playerid][Exp])
    {
        pInfo[playerid][CurExp] = 0;
        pInfo[playerid][Exp] += 8;
       
        pInfo[playerid][Level] += 1;

        format(string, sizeof(string), "SERVER:{FFFFFF} You have leveled up! New level: {FFBB00}%d{FFFFFF}!", pInfo[playerid][Level]);
        SendClientMessage(playerid, 0x46E850FF, string);
       
        format(string, sizeof(string), "SERVER:{FFFFFF} Experience necessities upgraded: {BF4B4B}%d{FFFFFF}/{FFBB00}%d{FFFFFF}.", pInfo[playerid][CurExp], pInfo[playerid][Exp]);
        SendClientMessage(playerid, 0x46E850FF, string);
    }

    return 1;
}
Reply
#10

Quote:
Originally Posted by Twizted
Посмотреть сообщение
pawn Код:
enum pInfo
{
    pPass,
    pCash,
    pAdmin,
    pSex,
    pAge,
    pLevel,
    pEXP,
    Float:pPos_x,
    Float:pPos_y,
    Float:pPos_z,
    pSkin,
    pCrew
}
new PlayerInfo[MAX_PLAYERS][pInfo];
@[Bios]Marcel: What If I want to add a specific ammount of EXP to the player's EXP?
You said that u want them to lvl up every 1000 xp );
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)