Код:
#include a_samp
#include sscanf
#define BasicXp 100
new PlayerXp[150];
new PlayerLevel[150] = 1;
new MaxLevelUp[150] = 2;
public OnPlayerConnect(playerid)
{
PlayerLevel[playerid] = 1;
MaxLevelUp[playerid] = 2;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if(!strcmp(cmdtext, "/xp", true))
{
new str[64];
format(str, sizeof str, "XP: %d/%d; Level: %d", PlayerXp[playerid], (MaxLevelUp[playerid] * BasicXp), PlayerLevel[playerid]);
SendClientMessage(playerid, -1, str);
return 1;
}
if(!strcmp(cmdtext, "/givexp", true, 5))
{
new xp;
if(sscanf(cmdtext[7], "d", xp)) return SendClientMessage(playerid, -1, "/givexp [XP]");
LevelUp(playerid, xp);
return 1;
}
return 0;
}
LevelUp(playerid, xp)
{
if(PlayerLevel[playerid] == 1)
{
if(PlayerXp[playerid] >= 100)
{
PlayerLevel[playerid]++;
PlayerXp[playerid] = PlayerXp[playerid] - 100;
MaxLevelUp[playerid] = MaxLevelUp[playerid] * 2;
}
else
{
PlayerXp[playerid] = PlayerXp[playerid] + xp;
}
}
else
{
if(PlayerXp[playerid] >= (MaxLevelUp[playerid] * BasicXp))
{
PlayerLevel[playerid]++;
PlayerXp[playerid] = PlayerXp[playerid] - (MaxLevelUp[playerid] * BasicXp);
MaxLevelUp[playerid] = MaxLevelUp[playerid] * 2;
}
else
{
PlayerXp[playerid] = PlayerXp[playerid] + xp;
}
}
}