Raised This Month: $32 Target: $400
 8% 

Solved XP TOP10


Post New Thread Reply   
 
Thread Tools Display Modes
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
JocAnis
Veteran Member
Join Date: Jun 2010
Old 04-11-2018 , 15:41   Re: XP TOP10
Reply With Quote #2

load xp is loaded on player connect...=> only connected players in top15...
load xp should be loaded in plugin_init (or with set_task) but dunno how exactly to do, hopefully someone will write it, i will also need this
JocAnis is offline
abdobiskra
Veteran Member
Join Date: Jul 2014
Location: Algeria
Old 04-21-2018 , 09:35   Re: XP TOP10
Reply With Quote #3

bump
__________________
abdobiskra is offline
Send a message via Skype™ to abdobiskra
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-21-2018 , 11:02   Re: XP TOP10
Reply With Quote #4

You will need to use nVault Utility to iterate through all data in the vault to load it into an array and then do your sort etc. This is not ideal, you can make improvements for how XP is saved to make this more efficient but I made it work with the current XP framework. Would be best to use SQL. This will only support a vault with up to 2000 players.

PHP Code:
public show_top_all(id)
{
    static 
Sort[2000][2];
    new 
count;
    
    
//Open vault for nvault utility usage
    
new iVault nvault_util_open"player_XP" );
    
    
//Get count of total number of entries in the vault
    
new num nvault_util_countiVault );
    new 
iOffsetiTS szKey45 ] , szVal12 ];
    
    
//Loop through all entries in the vault
    
for( count 0count num count++)
    {
        
//Read entry in vault
        
iOffset nvault_util_readiVault iOffset szKey charsmaxszKey ) , szVal charsmaxszVal ) , iTS );
    
        
//Set [0] to the byte offset for this players data within the vault so it can be referenced later to get his name if he is within the top 10.
        
Sort[count][0] = ( count == ) ? iOffset;
        
        
//Set [1] to his XP value
        
Sort[count][1] = str_to_numszVal );
    }
    
    
//Sort the array
    
SortCustom2D(Sort,count,"compare_xp");
    
    new 
motd[1501],iLen;
    
iLen formatex(motdsizeof motd 1,"<body bgcolor=#000000><font color=#98f5ff><pre>");
    
iLen += formatex(motd[iLen], (sizeof motd 1) - iLen,"%s %-22.22s %3s^n""#""Name""XP Top10");
    new 
minnum 10 );
    
    
//Build the top 10. y is set to the smaller of 10 or the total records in the vault.
    
for(new 0x++)
    {
        
//Above we set [0] to the players data offset within the vault file.
        
iOffset Sort[x][0];
        
        
//Read data at the players offset so we can get his name. Since he may not be online we can not use get_user_name().
        
nvault_util_readiVault iOffset szKey charsmaxszKey ) , szVal charsmaxszVal ) , iTS );
        
        
//Trim off the ' - XP:' part of their name.
        
szKeystrfindszKey " - XP:" ) ] = EOS;
        
        
iLen += formatex(motd[iLen], (sizeof motd 1) - iLen,"%d %-22.22s %d^n"1szKeySort[x][1] );
    }
    
    
//Close nvault utility file.
    
nvault_util_closeiVault );
    
    
iLen += formatex(motd[iLen], (sizeof motd 1) - iLen,"</body></font></pre>");
    
show_motd(id,motd"XP Top 10");

__________________

Last edited by Bugsy; 04-21-2018 at 13:16.
Bugsy is offline
abdobiskra
Veteran Member
Join Date: Jul 2014
Location: Algeria
Old 05-10-2018 , 10:58   Re: XP TOP10
Reply With Quote #5

Thank you for reply Bugsy but your code did not work for me ? (Nothing happens when i calle for it)
I found here who explains how https://amx-x.ru/viewtopic.php?f=9&t=29910 .. but it depends on the storage of data through the name.
And when I wanted to store it with SteamID .. the top 15 show SteamID only? Where is the problem ?
i need to show it with name ?
what i try to solve it :

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <nvault> 
#include <nvault_util> 


#define PLUGIN  "[TUT]StatsNvault(amx-x)"
#define VERSION         "1.0"
#define AUTHOR  "BaJIeHoK"

new g_Vault
new iPlayerNum[33][3]



//new Trie:g_Name 
//new Array:g_SteamID 

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)

    
register_clcmd("say /set_num""SetPlayerNum"//??????? ??? ?????????? ?????
    
register_clcmd("say /rank""ShowRank"//??????? ??? ?????? ?????
    
register_clcmd("say""handle_say"//??????? ??? ?????? ????
    
    
    //g_SteamID = ArrayCreate(32, 1)
    //g_Name = TrieCreate()

    
}

public 
SetPlayerNum(id){
    
    new 
iPlayers[32//???? ??????? ??? id ???????
    
new iPlayeriNum //? ????? ????? ??????? ?????????? ?????? ? ???? ???????
    
    
get_players(iPlayersiNum//???????? ???????
    
    
for(new iiNumi++) //????????? ????? ????    
    
{
        
iPlayer iPlayers[i//??? ????????? ?????????? ?????? ????????
        
        
iPlayerNum[iPlayer][1] += random_num(15//??????????? 1 ?????
        
iPlayerNum[iPlayer][2] += random_num(15//??????????? 2 ?????
    
}
}

public 
client_putinserver(id){
    
    
g_Vault nvault_open("level_xp_rank"//????????? ????
    
    
if(g_Vault == INVALID_HANDLE//???? ??????
    
{
        
set_fail_state("level_xp_rank"//?????? ?????, ????? ? ????????? ????
    
}
    
    new 
szData[32//??? ???????? ?????? ?? ????
    
new szName[32//???? ??????? ???
    
    
    //get_user_name(id, szName, charsmax( szName )) //???????? ???
    
get_user_authid(idszNamecharsmax(szName))
    
    
nvault_get(g_VaultszNameszDatacharsmaxszData )) //???????? ??????
    
    
nvault_closeg_Vault //????????? ????
    
    
replace_all(szDatacharsmaxszData ), "#"" "//???????? # ?? ??????(# - ????? ???????????? ??????)
    
new szParse[3][32//????? ??????? ?????????? ?????
    
    
parse(szDataszParse[1], 31szParse[2], 31)

    
iPlayerNum[id][1] = str_to_numszParse[1] ) //??????????? 1 ????? ??????
    
iPlayerNum[id][2] = str_to_numszParse[2] ) //??????????? 2 ????? ??????
    
}


public 
client_disconnect(id){
    
    
g_Vault nvault_open("level_xp_rank"
    
    if(
g_Vault == INVALID_HANDLE)     
    {
        
        
set_fail_state("NVault Error")
    }
    
    new 
szData[32
    new 
szName[32
    
    
//get_user_name(id, szName, charsmax( szName )) 
    
get_user_authid(idszNamecharsmax(szName))
    

    
formatex(szDatacharsmaxszData ), "%i#%i"iPlayerNum[id][1], iPlayerNum[id][2])
    
    
nvault_set(g_VaultszNameszData)
    
    
nvault_closeg_Vault 
    
}


public 
ShowRank(id){
    
    new 
iPlayers[32]
    new 
iPlayeriNum 
    
    get_players
(iPlayersiNum
    
    for(new 
iiNumi++) 
    {
        
        
iPlayer iPlayers[i
        
        
client_disconnect(iPlayer
    }
    
    
    new Array:
aNames  ArrayCreate(32
    new Array:
aNums ArrayCreate(1)
    
    new 
iPosiCountiTime 
    
    g_Vault 
nvault_util_open("level_xp_rank")
    
iCount nvault_util_countg_Vault 
    
    for(new 
iiCounti++) 
    {
        
        new 
szName[32], szData[10
        
        
iPos nvault_util_read(g_VaultiPosszNamecharsmaxszName ), szDatacharsmaxszData ), iTime)
        
        
ArrayPushString(aNamesszName
        
        
ArrayPushCell(aNumsstr_to_numszData )) 
        
    }
    
    
nvault_util_closeg_Vault 
    
    new 
iCheckNum 
    
    
for(new i,  j< ( iCount ); i++) 
    {
        
        
iCheckNum ArrayGetCell(aNumsi
        
        for( 
1iCountj++ ) 
        {
            
            if(
iCheckNum ArrayGetCell(aNumsj))      
            {
                
                
ArraySwap(aNamesi,  j
                
                
ArraySwap(aNumsi,  j
                
                
                
                
i-- 
                
                break 
                
            }
            
        }
        
    }
    
    new 
szName[32], szParseName[32]
    
    
get_user_name(idszNamecharsmaxszName ))
    
    for(new 
iiCounti++) 
    {
        
        
ArrayGetString(aNamesiszParseNamecharsmaxszParseName )) 
        
        
        
        if(
equal(szParseNameszName)) 
        {
            
            
client_print(idprint_chat"you rank %d  %d", (1), iCount)
            
            break
            
        }
        
    }
    
    
ArrayDestroy(aNames
    
ArrayDestroy(aNums
    
    return 
PLUGIN_HANDLED
    
}

public 
handle_say(id
{
    static 
args[32]
    
read_args(argscharsmax(args))
    
remove_quotes(args)
    
trim(args)
    
    if(
args[0] != '/')
        return 
PLUGIN_CONTINUE
    
    
if(contain(args"/top") != -1
    {
        
replace(argscharsmax(args), "/top"" ")
        
        return 
handle_top(idstr_to_num(args))
    }
    return 
PLUGIN_CONTINUE
}
handle_top(idtopnum 15)
{    
    
    new 
buffer[2048], buf[64]
    
topnum ShowTop(idbuffertopnum)
    
    
formatex(bufcharsmax(buf), "Zobmbie Infection - Top %d"topnum)
    
show_motd(idbufferbuf)
    
    return 
PLUGIN_CONTINUE
}

ShowTop(idszMotd[2048], topnum){
    
    new 
iPlayers[32]
    new 
iPlayeriNum 
    
    get_players
(iPlayersiNum
    
    for(new 
iiNumi++) 
    {
        
iPlayer iPlayers[i
    
        
client_disconnect(iPlayer)
    }
    
    new Array:
g_SteamID ArrayCreate(321)
    new 
Trieg_Name TrieCreate()
    
//new Array:aNames  = ArrayCreate(32) 
    
new Array:aNum1 ArrayCreate(1
    new Array:
aNum2 ArrayCreate(1
    
    new 
iPosiCountiTime 
    
    g_Vault 
nvault_util_open("level_xp_rank"
    
iCount nvault_util_countg_Vault 
    
    for(new 
iiCounti++) 
    {
        
        new 
szName[32], szData[10
        
        
iPos nvault_util_read(g_VaultiPosszNamecharsmaxszName ), szDatacharsmaxszData ), iTime)
        
        
replace_all(szDatacharsmaxszData ), "#"" ")
        
        new 
szParseNum1[32], szParseNum2[32]
        
        
parse(szDataszParseNum1charsmaxszParseNum1 ), szParseNum2charsmaxszParseNum2 ))
        
        
ArrayPushString(g_SteamIDszName
        
ArrayPushCell(aNum1str_to_numszParseNum1 ))
        
ArrayPushCell(aNum2str_to_numszParseNum2 )) 
        
    }
    
    
nvault_util_closeg_Vault 
    
    new 
iCheckNum 
    
    
for(new i,  j< ( iCount ); i++) 
    {
        
        
iCheckNum ArrayGetCell(aNum1i
        
        
        
        for( 
1iCountj++ ) 
        {
            
            if(
iCheckNum ArrayGetCell(aNum1j))
            {
                
                
ArraySwap(g_SteamIDi,  j
                
ArraySwap(aNum1i,  j)  
                
                
ArraySwap(aNum2i,  j)  
                
                
i-- 
                
                break 
            }
            
        }
        
    }
    
    new 
szName[32], szParseName[32], SteamID[32]
    new 
iParseNum[3
    new 
iLensizePosition
    
    iLen 
+= formatex(szMotd[iLen], charsmaxszMotd ) - iLen,"%5s  %30s %25s %25s %25s" "Rank""Name""XP""Level""Contry");
    
    
    
size min(ArraySize(g_SteamID), topnum)
    
    
//for (Position = 0, Size = min(ArraySize(aNames), topnum); Position < Size; Position++)
    //{
    
for(Position size 15 size 15Position size && charsmax(szMotd) - iLen 0Position++)
    {
        
ArrayGetString(g_SteamID PositionSteamIDcharsmaxSteamID )) 
        
//ArrayGetString(aNames, Position, szParseName, charsmax( szParseName )) 
        
TrieGetString(g_NameSteamIDszParseNamecharsmax(szParseName));
        
//get_user_name(id, szParseName, charsmax( szParseName )) //???????? ???
        
        
iParseNum[1] = ArrayGetCell(aNum1Position
        
iParseNum[2] = ArrayGetCell(aNum2Position
        
        
iLen += formatex(szMotd[iLen], charsmaxszMotd ) - iLen"^n%5d  %25s %6.0d/%d", (Position 1), szParseNameiParseNum[1], iParseNum[2])
    }
    
    
    return 
size
    

But the result is that the name does not appear
Attached Images
File Type: jpg Capture.JPG (35.6 KB, 81 views)
__________________

Last edited by abdobiskra; 05-10-2018 at 11:07.
abdobiskra is offline
Send a message via Skype™ to abdobiskra
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-10-2018 , 17:52   Re: XP TOP10
Reply With Quote #6

I coded it based on your above code. How am I supposed to know you truly wanted to store using steamid? Am I supposed to spend time coding it assuming things for you to then tell me I didn't do what you asked?

Although it is the correct way to go storing data using steam id, I coded based on your first post. It will take some more work and nvault array to do this with name, steam id and value.
__________________
Bugsy is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-10-2018 , 20:49   Re: XP TOP10
Reply With Quote #7

You need these includes:Make sure your nVault module is updated as stated in the nVault Array thread (AMX-X dev builds >= 4589 are ok).

Set a players XP using: pdData[ id ][ XP ] = X

Edit: Applied fix to correctly associate XP to player.
Spoiler
__________________

Last edited by Bugsy; 05-13-2018 at 13:06.
Bugsy is offline
abdobiskra
Veteran Member
Join Date: Jul 2014
Location: Algeria
Old 05-11-2018 , 05:12   Re: XP TOP10
Reply With Quote #8

Quote:
Originally Posted by Bugsy View Post
I coded it based on your above code. How am I supposed to know you truly wanted to store using steamid? Am I supposed to spend time coding it assuming things for you to then tell me I didn't do what you asked?

Although it is the correct way to go storing data using steam id, I coded based on your first post. It will take some more work and nvault array to do this with name, steam id and value.
No I do not blame your code just I'm the one who wanted to do it to try just because I consider it the best way
Sorry, maybe I was in a hurry. I appreciate your effort and the time you give me for help

Thank you very much again have been resolved
__________________

Last edited by abdobiskra; 05-11-2018 at 05:43. Reason: Solved
abdobiskra is offline
Send a message via Skype™ to abdobiskra
Old 05-11-2018, 05:16
abdobiskra
This message has been deleted by abdobiskra. Reason: Solved
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-13-2018 , 13:07   Re: XP TOP10
Reply With Quote #9

abdobiskra, please use the updated code in my previous post. The original plugin was not correctly associating XP to a player.
__________________
Bugsy is offline
Old 10-25-2018, 13:51
abdobiskra
This message has been deleted by abdobiskra.
Reply


Thread Tools
Display Modes

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 11:09.


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