AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Chat getting spammed with levels (https://forums.alliedmods.net/showthread.php?t=206815)

P1raten 01-26-2013 09:32

Chat getting spammed with levels
 
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_pluginPLUGIN_NAMEVERSION"P1raten" );
    
register_forwardFM_CmdStart"FM_CmdStart_Pre");

    
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(idszNamecharsmax(szName));

    while(
XP[id] >= LEVELS[Level[id]])
    {
        
plrXP[id]++;
        
ColorChat(0NORMAL"^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_pluginPLUGIN_NAMEVERSION"P1raten" );
    
register_forwardFM_CmdStart"FM_CmdStart_Pre");

    
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(idszNamecharsmax(szName));

    while(
XP[id] >= LEVELS[Level[id]])
    {
        
plrXP[id]++;
        
isDone true;
    }

    if(
isDone)
    {
        
ColorChat(0NORMAL"^x03%s^x01 is now level ^x04%i with %i XP!"szName, CLASS[Level[id]], plrXP[id]);
        
isDone false;
    }




All times are GMT -4. The time now is 20:32.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.