So, I've made this plugin based an XP mod. It's the same principal as an XP mod.
Now, when people connect it prints a message for each level that they have achieved.
Let's say a player is level 16.
The plugin will loop through each level and print it out.
Code:
Player is now level 1!
Player is now level 2!
Player is now level 3!
Player is now level 4!
Player is now level 5!
// etc
This is not at all what I want it to do.
I just want it to print when someone reaches a new level.
Here's some of the code.
PHP Code:
#define MAXCLASSES 53
new const CLASS[MAXCLASSES][] =
{
"None",
"Newbie",
{...}
};
new const LEVELS[52] =
{
0,
10,
{...}
};
public plugin_init()
{
register_plugin( PLUGIN_NAME, VERSION, "P1raten" );
register_forward( FM_CmdStart, "FM_CmdStart_Pre", 0 );
register_clcmd("say","CmdSay");
set_task(1.0, "MySql_Init");
}
public client_putinserver(id)
{
Load_MySql(id);
set_task(1.0,"checkLevel",id,_,_,"b");
}
public checkLevel(id)
{
new szName[32];
get_user_name(id, szName, charsmax(szName));
while(XP[id] >= LEVELS[Level[id]])
{
plrXP[id]++;
ColorChat(0, NORMAL, "^x03%s^x01 is now level ^x04%i with %i XP!", szName, CLASS[Level[id]], plrXP[id]);
}
}
Any ideas?
EDIT:
I managed to fix this by adding this:
PHP Code:
#define MAXCLASSES 53
new bool:isDone;
new const CLASS[MAXCLASSES][] =
{
"None",
"Newbie",
{...}
};
new const LEVELS[52] =
{
0,
10,
{...}
};
public plugin_init()
{
register_plugin( PLUGIN_NAME, VERSION, "P1raten" );
register_forward( FM_CmdStart, "FM_CmdStart_Pre", 0 );
register_clcmd("say","CmdSay");
set_task(1.0, "MySql_Init");
}
public client_putinserver(id)
{
Load_MySql(id);
set_task(1.0,"checkLevel",id,_,_,"b");
}
public checkLevel(id)
{
new szName[32];
get_user_name(id, szName, charsmax(szName));
while(XP[id] >= LEVELS[Level[id]])
{
plrXP[id]++;
isDone = true;
}
if(isDone)
{
ColorChat(0, NORMAL, "^x03%s^x01 is now level ^x04%i with %i XP!", szName, CLASS[Level[id]], plrXP[id]);
isDone = false;
}
}
__________________