Page 1 of 1

Making your own XP Mod

Posted: Sat Sep 26, 2026 4:58 pm
by Archive-Poster
Hello everybody,

As I am creating a Furien XP Mod requested (somewhere ) I want to share this piece of code with you. If you find anything which isn't correct or could be made better (can be, quite sure ) please tell it here.

Code: Select all

/* Plugin generated by AMXX-Studio */ 

#include <amxmodx> 
#include <amxmisc> 
#include <fun> 
#include <nvault>

#define PLUGIN "XP Mod Example" 
#define VERSION "1.0" 
#define AUTHOR "Kia Armani" 

#define XP_BASE        100    // We define our base variables here, means with which |factor gets price / health increased| / 
#define XP_MULTI    3.75    // |base value we start| 

#define HEALTH_BASE    100 
#define HEALTH_MULTI    0.4 

#define MAXLEVEL    21    // Setting the MAX Level the player can reach 

new g_iXP[33], g_iLevel[33],  g_iHealth[33], XP2Calc[33],Health2Calc[33] // Make some variables which hold the players XP, his Level, his Health he gets and his calculated variables. 

public client_putinserver(id) // To prevent players getting other players stats, we reset them when they connect 
{ 
    g_iHealth[id] = 0 
    XP2Calc[id] = 0 
    Health2Calc[id] = 0
    LoadXP(id)
} 

public client_disconnect(id)
{
    SaveXP(id)
}

public plugin_init()  
{ 
    register_plugin(PLUGIN, VERSION, AUTHOR) 
    
    register_clcmd("say /xp",    "OpenHealthMenu") // Make the command /xp which open the menu 
    register_clcmd("say xp",    "OpenHealthMenu") 
    
    register_clcmd("say /bonus", "GiveBonusPoints") // We'll make a test command which gives us some points to test out everything.
} 

public GiveBonusPoints(id)
{
    g_iXP[id] += 150
}

public OpenHealthMenu(id) 
{ 
    new MainMenuTitle[64],HealthTitle[64] // Define two Strings which hold the Menu Title and the Menu Item Title, you can do it without them, but with them looks better 
    
    Recalc(id) // This is a function to recalculate the players vars. to prevent false vars. 
    
    formatex(MainMenuTitle,    sizeof(MainMenuTitle) - 1,    "XP Mod Example by Kia^n\rYou have %i XP",g_iXP[id]) 
    
    // Now we check if the player is under the Level Limit and change the string if so 
    
    if(g_iLevel[id] < MAXLEVEL)  
        formatex(HealthTitle,    sizeof(HealthTitle) - 1,        "\wHealth - \y Level:\w %i - \r(\w%i Health\r) (\w%i XP\r)", g_iLevel[id],Health2Calc[id],XP2Calc[id]) 
    else 
        formatex(HealthTitle,    sizeof(HealthTitle) - 1,        "\wHealth - \y Level:\r MAXED") 
    
    // We use formatex (output[],len, const format[]) to make our titles 
    
    new MainMenu =        menu_create(MainMenuTitle,    "MainMenuHandler") 
    
    if(g_iLevel[id] < MAXLEVEL) 
        menu_additem        (MainMenu, HealthTitle, "1", 0) 
    else 
        menu_additem        (MainMenu, HealthTitle, "1", 1) 
    
    menu_setprop        (MainMenu,MPROP_EXIT, MEXIT_ALL) 
    menu_display        (id, MainMenu, 0) 
    
    // Now we are creating the actual menu, you should know that stuff already. 
} 

public MainMenuHandler(id, menu, item) 
{ 
    new data[6], szName[64] 
    new access,callback 
    
    menu_item_getinfo(menu,item,access,data,charsmax(data),szName,charsmax(szName),callback) 
    new key = str_to_num(data) 
    
    switch(key) 
    { 
        case 1: 
        {    // Until here everything should be clear to you, or not.. 
            if(g_iXP[id] > XP2Calc[id] && g_iLevel[id] < MAXLEVEL) // So, if the player has enough XP he can continue 
            { 
                g_iXP[id] -= XP2Calc[id] // We reduce his XP with the price 
                Recalc(id) // Recalculating 
                g_iHealth[id] = Health2Calc[id] // Setting his new Health BEFORE adding new Level, if you add the level before setting his health, he would get the health of lvl + 1 
                g_iLevel[id]++ // Increasing his level 
                
                if(is_user_alive(id)) // and btw, we set his Health if he is alive 
                { 
                    set_user_health(id, g_iHealth[id]) 
                } 
                
                OpenHealthMenu(id) // and reopen the menu 
            } 
            else 
                return PLUGIN_HANDLED 
        } 
    } 
    return PLUGIN_HANDLED 
} 

public SaveXP(id)
{
    new authid[32]; 
    get_user_authid(id,authid,31); 
    // We get the users Auth ID
    
    new vaultkey[64], vaultdata[64]; 
    
    //Save their XP
    formatex(vaultkey,63,"Level-%s-xp",authid); 
    formatex(vaultdata,63,"%d",g_iXP[id]); 
    set_vaultdata(vaultkey,vaultdata); 
    
    //Save their level
    formatex(vaultkey,63,"Level-%s-level",authid); 
    formatex(vaultdata,63,"%d",g_iLevel[id]); 
    set_vaultdata(vaultkey,vaultdata);
}  

public LoadXP(id)
{
    new authid[32]; 
    get_user_authid(id,authid,31); 
    // We get the users Auth ID
    
    new vaultkey[64], vaultdata[64]; 
    
    //Load their XP
    formatex(vaultkey,63,"Level-%s-xp",authid); 
    get_vaultdata(vaultkey,vaultdata,63); 
    g_iXP[id] = str_to_num(vaultdata);   
    
    //Load their level
    formatex(vaultkey,63,"Level-%s-level",authid); 
    get_vaultdata(vaultkey,vaultdata,63);
    g_iLevel[id] = str_to_num(vaultdata); 
}  

stock Recalc(id) 
{ 
    XP2Calc[id]           =    floatround(XP_BASE * XP_MULTI * g_iLevel[id]) // With the vars. defined in the top the Calc would be : 100 * 3.75 * Player Level 
    Health2Calc[id]    =    floatround(HEALTH_BASE * HEALTH_MULTI * g_iLevel[id]) // 100 * 0.4 * Player Level 
    
    // We have to use floatround because we are using numbers like 0.6, 0.4 etc. 
}