Raised This Month: $ Target: $400
 0% 

[Help] Xp Rank


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
2reason2kill
Senior Member
Join Date: Feb 2011
Old 05-09-2011 , 16:33   [Help] Xp Rank
Reply With Quote #1

PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <cstrike>
#include <nvault>

/* Check if player is a player:D */
#define IsPlayer(%1)    (1 <= %1 <= g_players) 

/* Times a player can write /xp ( To avoid spam! )*/
#define PrintTimes 3

/* Chat Prefix */
new const ChatPrefix[] = "HNS Ranks";

/* Change this to add more levels. 6 = 6 Levels. */
#define TOTALLEVELS 6

/* Edit here to add more levels. */
new const RANK[TOTALLEVELS] = 
{
    
50,
    
250
    
500
    
1000
    
1500,
    
2000
}

/* Name if player is unranked */
new const Level0[] = "Loser";

/* Edit here to add more levels. */
new const RANKNAMES[TOTALLEVELS][] =
{
    
"Noob",
    
"Beginner",
    
"Learning",
    
"Better",
    
"Soon pro",
    
"Pro"
}


new 
gXP[33], gLevel[33], iPrintXP[33];
new 
XP_KillXP_Hsg_vaultg_players;

public 
plugin_init()
{
    
register_plugin("XP-Ranking""1.0""nnajko");
 
    
/* This is when a player die or kill someone */
    
register_event("DeathMsg""eDeath""a");
    
    
/* When a player spawn FwdPlayerSpawn will be called */
    
RegisterHam(Ham_Spawn"player""FwdPlayerSpawn"1);
 
    
/* pCvars */
    
XP_Kill register_cvar("XP_per_kill""20");
    
XP_Hs register_cvar("XP_hs_bonus","10");
    
    
/* Get Maxplayers */
    
g_players get_maxplayers();
    
    
/* Chat Commands */
    
register_clcmd("say /xp""HideChat");
    
register_clcmd("say_team /xp""HideChat");
    
    
/* Save File Name */
    
g_vault nvault_open("HNSRANK");
}

public 
plugin_end()
{
    
nvault_close(g_vault);
}

public 
HideChat(id)
{
    if( 
IsPlayer(id) && is_user_alive(id) )
    {
        
ShowHud(id);
    }
    
    return 
PLUGIN_HANDLED;
}

public 
eDeath() 
{
    new 
killer read_data(1);
    new 
victim read_data(2);
    new 
gPrintMSG[100];
    new 
gXPKill get_pcvar_num(XP_Kill);
    new 
gXPHs get_pcvar_num(XP_Hs);
 
    if( 
IsPlayer(killer) && is_user_connected(killer) )
    {
        if( 
victim != killer )
        {
            if( 
cs_get_user_team(victim) != cs_get_user_team(killer) )
            {
                if( 
is_user_alive(killer) )
                {                    
                    if( !
read_data(3) )
                    {
                        
gXP[killer] += gXPKill
                        formatex
(gPrintMSGcharsmax(gPrintMSG), "You gained %d XP!"gXPKill);
                    }
                    else if( 
read_data(3) )
                    {
                        
gXP[killer] += (gXPKill gXPHs);
                        
formatex(gPrintMSGcharsmax(gPrintMSG), "You gained %d XP!^x01 (Headshot)", (gXPHs gXPKill));
                    }
    
                    Print(
killergPrintMSG);
                    
CheckLevel(killer);
                    
SaveData(killer);
                }
            }
        }
    }
    
    return 
PLUGIN_HANDLED;
}

public 
FwdPlayerSpawn(id)
{
    
iPrintXP[id] = 0;
}
        

public 
CheckLevel(id)
{
    if(
gXP[id] >= RANK[gLevel[id]])
    {
        
gLevel[id]++;
        Print(
id"^x01Congratulations!^x03 You are now a:^x01 %s^x03!"RANKNAMES[gLevel[id]]);
    }
}

public 
ShowHud(id)
{
    new 
iLevelName[100];
    if( 
gLevel[id] > )
    {
        
formatex(iLevelNamecharsmax(iLevelName), "%s"RANKNAMES[gLevel[id]]);
    }
    else 
    {
        
formatex(iLevelNamecharsmax(iLevelName), "%s"Level0);
    }
    
    if( 
iPrintXP[id] < PrintTimes )
    {
        new 
szName[33];
        
get_user_name(idszNamecharsmax(szName));
        Print(
0"^x01%s^x03 has:^x01 %d/%d XP^x03! Title:^x01 %s^x03!"szNamegXP[id], RANK[gLevel[id]], iLevelName);
        
iPrintXP[id]++;
    }
    else if( 
iPrintXP[id] >= PrintTimes )
    {
        Print(
id"You have printed your level maximum times this round!^x01 (%d)"PrintTimes);
    }
}

public 
client_connect(id)
{
    
LoadData(id);
}

public 
client_disconnect(id)
{
    
SaveData(id);
    
gXP[id] = 0;
    
gLevel[id] = 0;
}

public 
SaveData(id)
{
    new 
AuthID[35];
    
get_user_authid(id,AuthID,34);

    new 
vaultkey[64],vaultdata[256];
    
format(vaultkey,63,"%s-Mod"AuthID);
    
format(vaultdata,255,"%i#%i#",gXP[id],gLevel[id]);
    
nvault_set(g_vault,vaultkey,vaultdata);
    return 
PLUGIN_CONTINUE;
}

LoadData(id)
{
    new 
AuthID[35];
    
get_user_authid(id,AuthID,34);

    new 
vaultkey[64],vaultdata[256];
    
format(vaultkey,63,"%s-Mod",AuthID);
    
format(vaultdata,255,"%i#%i#",gXP[id],gLevel[id]);
    
nvault_get(g_vault,vaultkey,vaultdata,255);

    
replace_all(vaultdata255"#"" ");

    new 
playerxp[32], playerlevel[32];

    
parse(vaultdataplayerxp31playerlevel31);

    
gXP[id] = str_to_num(playerxp);
    
gLevel[id] = str_to_num(playerlevel);

    return 
PLUGIN_CONTINUE;

}

Print(
id, const sMsg[], any:...)
{
    static 
iid id get_Player();
    if ( !
) return;
    
    new 
sMessage[256];
    new 
len formatex(sMessagesizeof(sMessage) - 1"^x04[%s]^x03 "ChatPrefix);
    
vformat(sMessage[len], sizeof(sMessage) - lensMsg3);
    
sMessage[192] = '^0';
        
    static 
msgid_SayText;
    if ( !
msgid_SayText msgid_SayText get_user_msgid("SayText");
    
    new const 
team_Names[][] =
    {
        
"",
        
"TERRORIST",
        
"CT",
        
"SPECTATOR"
    
};
        
    new 
sTeam get_user_team(i);
    
    
team_Info(iidteam_Names[0]);
        
    
message_begin(id MSG_ONE_UNRELIABLE MSG_BROADCASTmsgid_SayText_id);
    
write_byte(i);
    
write_string(sMessage);
    
message_end();
        
    
team_Info(iidteam_Names[sTeam]);
}

team_Info(receiversendersTeam[])
{
    static 
msgid_TeamInfo;
    if ( !
msgid_TeamInfo msgid_TeamInfo get_user_msgid("TeamInfo");
    
    
message_begin(sender MSG_ONE_UNRELIABLE MSG_BROADCASTmsgid_TeamInfo_sender);
    
write_byte(receiver);
    
write_string(sTeam);
    
message_end();
}

get_Player()
{
    for ( new 
id 1id <= get_maxplayers(); id++ )
    {
        return 
id;
    }
    
    return 
0;

how do i do like 1 for cts and 1 for ts and they can see there rank in the left lower conor? plz help +K

Credits 2 nnajko for making the tut!

Last edited by 2reason2kill; 05-09-2011 at 16:36. Reason: forgot 2 give credits 2 nnajko
2reason2kill is offline
 



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 04:28.


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