This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

Making your own XP Mod


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 03-15-2013 , 13:12   Making your own XP Mod
Reply With Quote #1

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.

Screenshots :



Code :
PHP Code:
/* 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] = 
    XP2Calc
[id] = 
    Health2Calc
[id] = 0
    LoadXP
(id)


public 
client_disconnect(id)
{
    
SaveXP(id)
}

public 
plugin_init()  

    
register_plugin(PLUGINVERSIONAUTHOR
    
    
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        (MainMenuHealthTitle"1"0
    else 
        
menu_additem        (MainMenuHealthTitle"1"1
    
    
menu_setprop        (MainMenu,MPROP_EXITMEXIT_ALL
    
menu_display        (idMainMenu0
    
    
// Now we are creating the actual menu, you should know that stuff already. 


public 
MainMenuHandler(idmenuitem

    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(idg_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. 

Greetz,
Kia.
Attached Files
File Type: sma Get Plugin or Get Source (xpmodexample.sma - 875 views - 3.9 KB)
File Type: sma Get Plugin or Get Source (xpmodexample_saving.sma - 992 views - 5.1 KB)
__________________

Last edited by Kia; 03-24-2013 at 05:08.
Kia is offline
oxygen935
Veteran Member
Join Date: Jun 2012
Location: Athens, Greece
Old 03-15-2013 , 15:53   Re: Making your own XP Mod
Reply With Quote #2

Excellent work kia! Helped much!
__________________
Quote:
Originally Posted by quark View Post
You're a genius
Stopped any pawn work cause of university for computer science
oxygen935 is offline
Send a message via Skype™ to oxygen935
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 03-19-2013 , 06:21   Re: Making your own XP Mod
Reply With Quote #3

I'll update the code later, will add a saving function using NVault.
__________________
Kia is offline
hLiaS
Senior Member
Join Date: Aug 2011
Location: In My Holly Dreams
Old 03-23-2013 , 14:22   Re: Making your own XP Mod
Reply With Quote #4

pssssss your code is SO GOODDDD and helpfull
hLiaS is offline
Send a message via Skype™ to hLiaS
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 03-24-2013 , 05:06   Re: Making your own XP Mod
Reply With Quote #5

Updated Code with NVault saving in first post.
__________________
Kia is offline
oxygen935
Veteran Member
Join Date: Jun 2012
Location: Athens, Greece
Old 04-06-2013 , 13:05   Re: Making your own XP Mod
Reply With Quote #6

add MySql database support...
__________________
Quote:
Originally Posted by quark View Post
You're a genius
Stopped any pawn work cause of university for computer science
oxygen935 is offline
Send a message via Skype™ to oxygen935
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 04-20-2013 , 09:19   Re: Making your own XP Mod
Reply With Quote #7

PHP Code:
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] = 
    LoadXP
(id


PHP Code:
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] = 
    g_iXP
[id] = 0
    LoadXP
(id

Because if player never joined that server, and before that, did joined other server with that method, he wont have 0 points
Btw you should use cvars, instead of defines, dont need recompile all the time
__________________

Last edited by Jhob94; 04-20-2013 at 09:22. Reason: fix
Jhob94 is offline
guipatinador
SourceMod Donner Party
Join Date: Oct 2009
Location: Poortugal
Old 04-27-2013 , 08:25   Re: Making your own XP Mod
Reply With Quote #8

You include < nvault >, but you only use the old vault system. lol.
guipatinador is offline
Old 01-03-2014, 12:49
alexinhotm99
This message has been deleted by hornet. Reason: This section is not for scripting help
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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