Thread: [Solved] XP TOP10
View Single Post
Author Message
abdobiskra
Veteran Member
Join Date: Jul 2014
Location: Algeria
Old 04-11-2018 , 04:40   XP TOP10
Reply With Quote #1

Hi, I found this plugin in the forum
But it only shows the current players and not the data top players ?
PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <nvault>

#define PLUGIN "New Plugin"
#define VERSION "1.0"
#define AUTHOR "Author"

#define MAXSLOTS    32
new g_XP[MAXSLOTS+1];

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR);
    
register_clcmd("say /xptop10","show_top");
}
public 
client_disconnect(id){
    
SaveXP(id)
}
public 
client_putinserver(id){
    
LoadXP(id)
}
//Save xp when a player disconnect
public SaveXP(id){
    new 
Vault nvault_open("player_XP");
    new 
Key[64],Value[64],Name[32];
    
get_user_name(id,Name,sizeof Name 1);
    
formatex(Key,sizeof Key 1"%s - XP:"Name);
    
formatex(Value,sizeof Value 1"%d"g_XP[id]);
    
    
nvault_set(Vault,Key,Value);
    
nvault_close(Vault);
}
//Load xp when a player enters on the server
public LoadXP(id){
    new 
Vault nvault_open("player_XP");
    new 
Key[64],Value[64],Name[32];
    
get_user_name(id,Name,sizeof Name 1);
    
    
formatex(Key,sizeof Key 1"%s - XP:"Name);
    
nvault_get(Vault,Key,Value,sizeof Value 1);
    
nvault_close(Vault);
    
    
g_XP[id] = str_to_num(Value)
}
//Show top10
public show_top(id){
    static 
Sort[33][2];
    new 
players[32],num,count,index;
    
get_players(players,num);
    
    for(new 
0numi++){
        
index players[i];
        
Sort[count][0] = index;
        
Sort[count][1] = g_XP[index];
        
count++;
    }
    
    
SortCustom2D(Sort,count,"compare_xp");
    new 
motd[1501],iLen;
    
iLen format(motdsizeof motd 1,"<body bgcolor=#000000><font color=#98f5ff><pre>");
    
iLen += format(motd[iLen], (sizeof motd 1) - iLen,"%s %-22.22s %3s^n""#""Name""XP Top10");
    
    new 
clamp(count,0,10);
    new 
name[32],kindex;
    
    for(new 
0yx++){
        
kindex Sort[x][0];
        
get_user_name(kindex,name,sizeof name 1);
        
iLen += format(motd[iLen], (sizeof motd 1) - iLen,"%d %-22.22s %d^n"1nameSort[x][1]);
    }
    
iLen += format(motd[iLen], (sizeof motd 1) - iLen,"</body></font></pre>");
    
show_motd(id,motd"XP Top 10");
}
public 
compare_xp(elem1[], elem2[])
{
    if(
elem1[1] > elem2[1])
        return -
1;
    else if(
elem1[1] < elem2[1])
        return 
1;
    
    return 
0;

The question is how to call the ranking in the data for the players ?
__________________

Last edited by abdobiskra; 05-11-2018 at 05:47.
abdobiskra is offline
Send a message via Skype™ to abdobiskra