Help XP System - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Help XP System (
/showthread.php?tid=546165)
Help XP System -
RonnyCZ - 13.11.2014
Hello I have a little problem on the server I'm ID: 0 and writes it correctly then it buddy has ID 1 and shows him a 0/0 Level 0 and me it shows Level 1 0/200 please what is wrong?
Код:
#include a_samp
#include sscanf
#define BasicXp 100
new PlayerXp[150];
new PlayerLevel[150] = 1;
new MaxLevelUp[150] = 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;
}
}
}
Re: Help XP System -
Kwarde - 13.11.2014
You made the next arrays:
PlayerXp
PlayerLevel
MaxLevelUp
- They all have a size of '150', so you could store data for 150 players. You probably knew that already. What you probably didn't know, is that by adding a value at creating, it does not set the data for all cells.
Some examples:
pawn Код:
new data[2];
//This would create the next array;
//data = 0, 0, NULL;
new data[2] = 1;
//This would create the next array;
//data = 1, 0, NULL;
Okay. My explaination sucks. I looked arround, and I found a nice tutorial for you to read:
https://sampforum.blast.hk/showthread.php?tid=318212
Anyway, how to fix it: Set the data in OnPlayerConnect!
pawn Код:
public OnPlayerConnect(playerid)
{
PlayerLevel[playerid] = 1;
MaxLevelUp[playerid] = 2;
}
Re: Help XP System -
RonnyCZ - 13.11.2014
It works, then the problem is to reach 250 XP and change it to 0/400 0/200 when I reach it is to change it to 0/400 and add lvl