Creating EXP with level system
#1

Hey, im trying to make my own EXP and level system for my DM server but i always fails when i try to make it to check the player's EXP to set him to next level in 'OnPlayerUpdate' part

can anyone help me to make it?

Код:
enum PInfo
{
	plevel,
	exp

};
new PlayerInfo[MAX_PLAYERS][PInfo];
here is some function i made..
Код:
stock SetPlayerEXP(playerid,EXP)
{
	new INI:file = INI_Open(Path(playerid));
	INI_SetTag(file,"Player's Data");
	INI_WriteInt(file,"EXP",EXP);
	INI_Close(file);
	PlayerInfo[playerid][exp] = exp;
	return 1;
}

stock GivePlayerEXP(playerid,EXP)
{
	PlayerInfo[playerid][exp] += EXP;
	new INI:file = INI_Open(Path(playerid));
	INI_SetTag(file,"Player's Data");
	INI_WriteInt(file,"EXP",PlayerInfo[playerid][exp]);
	INI_Close(file);
	return 1;
}

stock SetPlayerLevel(playerid,LEVEL)
{
        PlayerInfo[playerid][exp] = LEVEL;
	new INI:file = INI_Open(Path(playerid));
	INI_SetTag(file,"Player's Data");
	INI_WriteInt(file,"EXP",PlayerInfo[playerid][plevel]);
	INI_Close(file);
	return 1;
}

stock GivePlayerLevel(playerid,LEVEL)
{
	PlayerInfo[playerid][exp] += LEVEL;
	new INI:file = INI_Open(Path(playerid));
	INI_SetTag(file,"Player's Data");
	INI_WriteInt(file,"EXP",PlayerInfo[playerid][plevel]);
	INI_Close(file);
	return 1;
}
Reply
#2

I see several possible mistakes:

In SetPlayerEXP change PlayerInfo[playerid][exp] = exp to: PlayerInfo[playerid][exp] = EXP;

In SetPlayerLevel change PInfo[playerid][exp] = LEVEL; to PInfo[playerid][plevel] = LEVEL;

In GivePlayerLevel change PInfo[playerid][exp] += LEVEL; to PInfo[playerid][plevel] += LEVEL;


Thats due to copy'n paste...
Reply
#3

Oh thanks i didn't take care of these function or even test yet..but about the OnPlayerUpdate part can you help me on it to make it check if my EXP = 2000 it will change my level to level 2 and for level 3 multiply it by 2..etc

Quote:
Originally Posted by alexus
Посмотреть сообщение
Thats due to copy'n paste...
Well,It doesn't matter if i copied and pasted it.. i have just learned the way to make it and these mistakes because of me didn't concentrate well while remaking it by my own way
Reply
#4

Do NOT use OnPlayerUpdate for things that are entirely within your control. YOU control when a player gets XP. Not the player. Not the server. YOU. Therefore, you always know its value and at what value the player should level up.

Place the level up code in GivePlayerExp.
Reply
#5

Quote:
Originally Posted by Vince
Посмотреть сообщение
Place the level up code in GivePlayerExp.
I didn't understand that part... can you explain with examples why should i put the level up code in the GivePlayerExp function ?
Reply
#6

Quote:
Originally Posted by TheSperm
Посмотреть сообщение
I didn't understand that part... can you explain with examples why should i put the level up code in the GivePlayerExp function ?
There is nothing really to explain further. Just put whatever code you was going to use under OnPlayerUpdate to check the XP in the GivePlayerEXP function that you mdae. Make sure you check for the XP AFTER giving it to the player.
Reply
#7

I made the changes in your code. Notice that I named "LEVEL" the level's field but perhaps you use another name. You can change the value of LEVELUP to the amount of EXP points needed to increase one level.

Код:
#define LEVELUP 5  // it means 1 level more each +5 exp

stock SetPlayerEXP(playerid,EXP)
{
	PlayerInfo[playerid][exp] = EXP;
	new INI:file = INI_Open(Path(playerid));
	INI_SetTag(file,"Player's Data");
	INI_WriteInt(file,"EXP",EXP);
	INI_Close(file);
	return 1;
}

stock GivePlayerEXP(playerid,EXP)
{
	PlayerInfo[playerid][exp] += EXP;
	new INI:file = INI_Open(Path(playerid));
	INI_SetTag(file,"Player's Data");
	INI_WriteInt(file,"EXP",PlayerInfo[playerid][exp]);
	if(!(PlayerInfo[playerid][exp] %LEVELUP))
	{
		PlayerInfo[playerid][plevel] += 1;
		INI_WriteInt(file,"LEVEL",PlayerInfo[playerid][plevel]);
	}
	INI_Close(file);
	return 1;
}

stock SetPlayerLevel(playerid,LEVEL)
{
	PlayerInfo[playerid][plevel] = LEVEL;
	new INI:file = INI_Open(Path(playerid));
	INI_SetTag(file,"Player's Data");
	INI_WriteInt(file,"LEVEL",PlayerInfo[playerid][plevel]);
	INI_Close(file);
	return 1;
}

stock GivePlayerLevel(playerid,LEVEL)
{
	PlayerInfo[playerid][plevel] += LEVEL;
	new INI:file = INI_Open(Path(playerid));
	INI_SetTag(file,"Player's Data");
	INI_WriteInt(file,"LEVEL",PlayerInfo[playerid][plevel]);
	INI_Close(file);
	return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)