Raised This Month: $ Target: $400
 0% 

Xp Leveler


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Brreaker
Senior Member
Join Date: Oct 2009
Location: Constanta, Romania
Old 05-21-2010 , 15:19   Re: Xp Leveler
Reply With Quote #7

PHP Code:
#include <amxmodx> 
#include <amxmisc> 
#include <fun> 
#include <vault> 
#include <hamsandwich>
#define MAXCLASSES 4 

new PlayerClass[33]
new 
PlayerXP[33
new 
PlayerLevel[33

new 
msgtext 

new const CLASSES[MAXCLASSES][] = { 
    
"CLASS_NOTHING"
    
"CLASS_1"
    
"CLASS_2"
    
"CLASS_3" 

new const 
LEVELS[6] = { 
    
1,  
    
2,  
    
4,  
    
8
    
16
    
32 


public 
plugin_init() 

    
register_plugin("Lvler""1.0""SaM"
     
    
register_cvar("sv_Leveler""1"
    
RegisterHam(Ham_Spawn"player""fwdHamSpawn"
    
register_event("DeathMsg""eDeath""a"); 
    
register_cvar("XP_per_kill""1"


public 
fwdHamSpawn(id) { 
     
    
set_user_health(idget_user_health(id) + PlayerLevel[id]) 
    return 
HAM_IGNORED 
     
}  

public 
SaveXP(id

    new 
authid[32];  
    
get_user_authid(id,authid,31);  

    new 
vaultkey[64], vaultdata[64];  
   
    
format(vaultkey,63,"ANIMAL-%s-class",authid);  
    
format(vaultdata,63,"%d",PlayerClass[id]);  
    
set_vaultdata(vaultkey,vaultdata);  

    
format(vaultkey,63,"ANIMAL-%s-xp",authid);  
    
format(vaultdata,63,"%d",PlayerXP[id]);  
    
set_vaultdata(vaultkey,vaultdata);  

    
format(vaultkey,63,"ANIMAL-%s-level",authid);  
    
format(vaultdata,63,"%d",PlayerLevel[id]);  
    
set_vaultdata(vaultkey,vaultdata); 
}  

public 
LoadXP(id

    new 
authid[32];  
    
get_user_authid(id,authid,31);  

    new 
vaultkey[64], vaultdata[64];  

    
format(vaultkey,63,"ANIMAL-%s-class",authid);  
    
get_vaultdata(vaultkey,vaultdata,63);  
    
PlayerClass[id] = str_to_num(vaultdata);  

    
format(vaultkey,63,"ANIMAL-%s-xp",authid);  
    
get_vaultdata(vaultkey,vaultdata,63);  
    
PlayerXP[id] = str_to_num(vaultdata);    

    
format(vaultkey,63,"ANIMAL-%s-level",authid);  
    
get_vaultdata(vaultkey,vaultdata,63); 
    
PlayerLevel[id] = str_to_num(vaultdata);   
}  

public 
client_connect(id

    if(
get_cvar_num("SaveXP") == 1) { 
        
         
LoadXP(id

         
client_print(idprint_chat"[Animal Mod] XP Loaded!"
         
client_print(idprint_chat"[Animal Mod] You are a %s with level %s and %s XP"PlayerClass[id], PlayerLevel[id], PlayerXP[id]) 
    } 


public 
client_disconnect(id

    if(
get_cvar_num("SaveXP") == 1) { 
     
         
SaveXP(id
    } 


public 
eDeath() { 
    new 
iKiller read_data(1
    if(
PlayerClass[iKiller] == CLASS_NOTHING) return PLUGIN_CONTINUE 
    
if(PlayerLevel[iKiller] == 6) return PLUGIN_CONTINUE 
    PlayerXP
[iKiller] += get_cvar_num("XP_per_kill"
    if(
PlayerXP[iKiller] >= LEVELS[PlayerLevel[iKiller]]) { 
        
PlayerLevel[iKiller]++ 
        
client_print(iKillerprint_chat"[Beast] Congratulations! You are now level %i!"PlayerLevel[iKiller]) 
        if(
get_cvar_num("SaveXP")) { 
            
SaveXP(iKiller
            } 
        
ShowHUD(iKiller
        } 
    
ShowHUD(iKiller)  
    return 
PLUGIN_CONTINUE 

     


public 
ShowHUD(id)     
{  
    new 
HUD[51
    
format(HUD50"[%s]Level: %i XP: %i"CLASSES[PlayerClass[id]], PlayerLevel[id], PlayerXP[id])  

    
message_begin(MSG_ONEmsgtext, {0,0,0}, id)  
    
write_byte(0)  
    
write_string(HUD)  
    
message_end()  
    return 


Here, I made some improvements...Advices:

Instead of
PHP Code:
if(something == 1) {} 
use
PHP Code:
if(something) {} 
Also for
PHP Code:
if(something == 0) {} 
use
PHP Code:
if(!something) {} 
If there is going to be only one line after an if state, you can use it without {}
Ex:
PHP Code:
if(!cmd_access(idlevelcid3)) return PLUGIN_HANDLED 
is the same as
PHP Code:
if(!cmd_access(idlevelcid3)) 
    return 
PLUGIN_HANDLED 
or as
PHP Code:
if(!cmd_access(idlevelcid3)) {
    return 
PLUGIN_HANDLED 
For increasing/decreasing the value by 1 use
PHP Code:
Value++
Value-- 
Instead of
PHP Code:
Value += 1
Value 
-= 
Also, in an event, you should use
PHP Code:
return PLUGIN_CONTINUE 
because if you use
PHP Code:
return PLUGIN_HANDLED 
you would just block the event (in some cases, you need PLUGIN_HANDLED, but not in this case.For example, if you use PLUGIN_HANDLED in New Round Event(HLTV) you block the new round)
__________________
There are 10 kinds of people.Those who understand binary, and those who don't.
Also, for those who understand binary, there is a donation tab too!
No steam || PM support!

Last edited by Brreaker; 05-21-2010 at 16:03.
Brreaker is offline
Send a message via MSN to Brreaker Send a message via Yahoo to Brreaker
 



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 03:38.


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