Поиск Top 15 (Not For Current Online But For Everyone)

Сообщения
213
Реакции
71
Помог
2 раз(а)
Hello, can anyone help me with this plugin? Please?

Played Time by Alka, shows /pttop15, only among those who are currently online.
can anyone edit it? so it should show /pttop15, irrespective of online.

Link to plugin:
https://forums.alliedmods.net/showthread.php?t=53126

Screenshot:
https://i.ibb.co/VYhPsP4/New-Bitmap-Image.png

PHP:
/*Played Time with "Current(Total) played Time" on server.*
*                   (nVault support)                          *
*Author:Alka                                              *
*Version: 1.4                                              *
*---------------------------------------------------------*
*                                                          *
***********************************************************/
#include <amxmodx>
#include <amxmisc>
#include <nvault>
#include <ColorChat>

#define PLUGIN "Played Time"
#define VERSION "1.4"
#define AUTHOR "Alka"

/*Comment this if you don't want to use nvault*/
#define NVAULT
/*Comment this line if you don't want to prune vlutdata*/
#define PRUNE
/*Prune time:ater x time of beeing inactive,remove valutdata*/
#define PRUNE_TIME 157658000 /*6 Months*/ /*Time in seconds*/

new showpt;

new TotalPlayedTime[33];

public plugin_init() 
{
    register_plugin(PLUGIN, VERSION, AUTHOR );
    
    register_clcmd("say !ptime", "handle_say");
    register_clcmd("say_team !ptime", "handle_say");
    register_clcmd("say /ptime", "handle_say");
    register_clcmd("say_team /ptime", "handle_say");
    register_clcmd("say !playedtime", "handle_say");
    register_clcmd("say_team !playedtime", "handle_say");
    register_clcmd("say /playedtime", "handle_say");
    register_clcmd("say_team /playedtime", "handle_say");
    register_clcmd("say !playtime", "handle_say");
    register_clcmd("say_team !playtime", "handle_say");
    register_clcmd("say /playtime", "handle_say");
    register_clcmd("say_team /playtime", "handle_say");
    register_clcmd("say /pt", "handle_say");
    register_clcmd("say_team /pt", "handle_say");
    register_clcmd("say !pt", "handle_say");
    register_clcmd("say_team !pt", "handle_say");
    register_concmd("amx_playedtime", "admin_showptime", ADMIN_KICK," <#Player Name> - Details about playedtime.");
    register_concmd("amx_playtime", "admin_showptime", ADMIN_KICK," <#Player Name> - Details about playedtime.");
    register_clcmd("say /pttop15", "show_top15");
    register_clcmd("say_team /pttop15", "show_top15");
    
    showpt = register_cvar("amx_pt_mod","1");
        set_task(120.0, "playtime_advert", 100, _, _, "b")
        set_task(180.0, "playtimetop_advert", 100, _, _, "b")    
}

public playtime_advert(id) 
{ 
    client_print_color(0, print_chat, "^4[PSL] ^3Type ^4/ptime ^3in chat or team_chat to see ^4Current ^3And ^4Total Time Played!")
}
public playtimetop_advert(id) 
{  
    client_print_color(0, print_chat, "^4[PSL] ^x03Type ^x04/pttop15 ^x03in chat or team_chat to see ^4Top 15 Total Time Played!") 
} 

public handle_say(id) 
{
    set_task(0.1, "PrintTime", id);
}
public PrintTime(id) 
{
        static timep;
        
        timep = get_user_time(id, 1) / 60;
            new szName[32], szAuthId[35], szDateAndTime[22]
            get_user_name(id, szName, charsmax(szName))
            get_user_authid(id, szAuthId, charsmax(szAuthId))
        get_time("%H:%M:%S - %d/%m/%Y", szDateAndTime, charsmax(szDateAndTime))
        
        switch(get_pcvar_num(showpt))
        {
            case 0: return PLUGIN_HANDLED;
                
            case 1 :
            {
                client_print_color(id, print_chat, "^4[PSL] ^3%s ^4[%s] ^3you have been playing on the server for:^4 %d minute%s.", szName, szAuthId, timep, timep == 1 ? "" : "s");
                #if defined NVAULT 
                client_print_color(id, print_chat, "^4[PSL] ^3%s ^4[%s] ^3your total played time on the server:^4 %d minute%s.", szName, szAuthId, timep+TotalPlayedTime[id], timep+TotalPlayedTime[id] == 1 ? "" : "s");
                #endif
                client_print_color(id, print_chat, "^4[PSL] ^3Current time and date:^4 %s", szDateAndTime);
            }
            case 2 :
            {
                set_hudmessage(255, 50, 50, 0.34, 0.50, 0, 6.0, 4.0, 0.1, 0.2, -1);
                show_hudmessage(id, "[PSL] You have been playing on the server for: %d minute%s.^n[PSL] Current time: %s", timep, timep == 1 ? "" : "s", szDateAndTime);
            }
        }
        return PLUGIN_HANDLED;
    }

public admin_showptime(id,level,cid) 
{
    if(!cmd_access(id, level, cid, 2))
        return PLUGIN_HANDLED;
    
    static arg[32];
    read_argv(1, arg, 31);
    
    new player = cmd_target(id, arg, 2);
    
    if(!player)
        return PLUGIN_HANDLED;
    
    static name[32];
    get_user_name(player, name, 31);
    
    static timep;
    
    timep = get_user_time(player, 1) / 60;
    new szDateAndTime[22]
    get_time("%H:%M:%S - %d/%m/%Y", szDateAndTime, charsmax(szDateAndTime))
    
    console_print(id, "-----------------------(# [PSL] PlayedTime #)-----------------------");
    console_print(id, "[PSL] %s have been playing on the server for %d minute%s.",name, timep, timep == 1 ? "" : "s");
    #if defined NVAULT
    console_print(id, "[PSL] %s's total played time on the server %d minute%s.",name, timep+TotalPlayedTime[player], timep == 1 ? "" : "s"); // new
    #endif
    console_print(id, "[PSL] Current time and date: %s", szDateAndTime);
    console_print(id, "-----------------------------------------------------------------");
    
    return PLUGIN_HANDLED;
}

#if defined NVAULT
public client_disconnect(id)
{
    TotalPlayedTime[id] = TotalPlayedTime[id] + (get_user_time(id)/60);
    SaveTime(id, TotalPlayedTime[id]);
}
#endif

#if defined NVAULT
public client_putinserver(id)
{
    TotalPlayedTime[id] = LoadTime(id);
}
#endif

#if defined NVAULT
public LoadTime( id ) 
{
    new valut = nvault_open("Time_played")
    
    new authid[33];
    new vaultkey[64], vaultdata[64];
    
    get_user_authid(id, authid, 32);
    
    format(vaultkey, 63, "TIMEPLAYED%s", authid);
    
    nvault_get(valut, vaultkey, vaultdata, 63);
    nvault_close(valut);
    
    return str_to_num(vaultdata);
}
#endif

#if defined NVAULT
public SaveTime(id,PlayedTime)
{
    new valut = nvault_open("Time_played")
    
    if(valut == INVALID_HANDLE)
        set_fail_state("nValut returned invalid handle")
    
    new authid[33];
    new vaultkey[64], vaultdata[64];
    
    get_user_authid(id, authid, 32);
    
    format(vaultkey, 63, "TIMEPLAYED%s", authid); 
    format(vaultdata, 63, "%d", PlayedTime); 
    
    nvault_set(valut, vaultkey, vaultdata);
    nvault_close(valut);
}
#endif

#if defined PRUNE
public prune()
{
    new valut = nvault_open("Time_played");
    
    if(valut == INVALID_HANDLE)
        set_fail_state("nValut returned invalid handle");
    
    nvault_prune(valut, 0, get_systime() - PRUNE_TIME);
    nvault_close(valut);
}
#endif

#if defined PRUNE
public plugin_end()
{
    prune()
}
#endif

#if defined NVAULT
public show_top15(id)
{
    new i, count;
    static sort[33][2], maxPlayers;
    
    if(!maxPlayers) maxPlayers = get_maxplayers();
    
    for(i=1;i<=maxPlayers;i++)
    {
        sort[count][0] = i;
        sort[count][1] = TotalPlayedTime[i] + (get_user_time(i, 1) / 60);
        count++;
    }
    
    SortCustom2D(sort,count,"stats_custom_compare");
    
    new motd[1024], len    
    
    len = format(motd, 1023,"<body bgcolor=#000000><font color=#FFB000><pre>")
    len += format(motd[len], 1023-len,"%s %-22.22s %3s^n", "#", "Name", "Time")
    
    new players[32], num
    get_players(players, num)
    
    new b = clamp(count,0,15)
    
    new name[32], player
    
    for(new a = 0; a < b; a++)
    {
        player = sort[a][0]
        
        get_user_name(player, name, 31)        
        len += format(motd[len], 1023-len,"%d %-22.22s %d^n", a+1, name, sort[a][1])
    }
    
    len += format(motd[len], 1023-len,"</body></font></pre>")
    show_motd(id, motd, "Played-Time Top 15")
    
    return PLUGIN_CONTINUE
}
#endif

public stats_custom_compare(elem1[],elem2[])
{
    if(elem1[1] > elem2[1]) return -1;
    else if(elem1[1] < elem2[1]) return 1;
        
    return 0;
}
 
Сообщения
1,287
Реакции
2,279
Помог
57 раз(а)
DrStrange,
Forget about it. This plugin uses nvault. Nvault is key-based storage. You give key (string, like SteamID), storage gives you data for provided key. You cannot say to it "hey, give me top15 by online" (actually, you can, by using binary reading for ALL storage from first to last entry, but it is a inadequate method).

For your idea you need a plugin that stores data through sqlite/mysql. SQL provides you something like
Код:
SELECT * FROM `table` ORDER BY `online_time` DESC LIMIT 15

If you use a plugin that track played time (some stats plugin, like csstatsx mysql), you can use it as a base for a solution.
 
Сообщения
213
Реакции
71
Помог
2 раз(а)
DrStrange,
Forget about it. This plugin uses nvault. Nvault is key-based storage. You give key (string, like SteamID), storage gives you data for provided key. You cannot say to it "hey, give me top15 by online" (actually, you can, by using binary reading for ALL storage from first to last entry, but it is a inadequate method).

For your idea you need a plugin that stores data through sqlite/mysql. SQL provides you something like
Код:
SELECT * FROM `table` ORDER BY `online_time` DESC LIMIT 15

If you use a plugin that track played time (some stats plugin, like csstatsx mysql), you can use it as a base for a solution.
I have question, is it necessary for mysql or sqlite to have database? Like Web, etc? Or that can be made like nvault (into server folders too)?

Since, mysql/sqlite operation have always been bit difficult for me to understand and act upon !!
 
Последнее редактирование:
Сообщения
146
Реакции
29
I have question, is it necessary for mysql or sqlite to have database? Like Web, etc? Or that can be made like nvault (into server folders too)?
.php (webhost) is needed if you use SQLite (about MySQL you need mysql databaess with external access and php ofc)
if you have your own vps you can go with SQLite and XAMPP (locahost) for showing .php (top15) files, if im not mistaken

other 'good' methods are, storing informations in .ini file...this include is interesting for that: https://forums.alliedmods.net/showthread.php?t=315031
 
Сообщения
1,287
Реакции
2,279
Помог
57 раз(а)
I have question, is it necessary for mysql or sqlite to have database?
SQLite module doesn't require external database (vds/hosting), and uses local storage (in '/addons/amxmodx/data/sqlite3') instead ("like nvault", as you say). But in this case all maintenance (saving/loading data) is done by module itself and uses game server resources. MySQL requires external database, and maintenance is done by external sql server, AMXX just sends queries and receives answers. If you plan to use output data through website, - your choice is mysql. If not, - sqlite (or again, mysql, if you have place to host external database).
 
Сообщения
146
Реакции
29
we didnt tell you..with sqlite you can do easily that top15 of all players...doing motd in .sma, so you are only limited with characters there, thats one more difference compared to .php
 
Сообщения
213
Реакции
71
Помог
2 раз(а)
SQLite module doesn't require external database (vds/hosting), and uses local storage (in '/addons/amxmodx/data/sqlite3') instead ("like nvault", as you say). But in this case all maintenance (saving/loading data) is done by module itself and uses game server resources. MySQL requires external database, and maintenance is done by external sql server, AMXX just sends queries and receives answers. If you plan to use output data through website, - your choice is mysql. If not, - sqlite (or again, mysql, if you have place to host external database).
I understand, so sqlite is some what, much similar to nvault but kind of upgraded module where as Mysql requires external database !!

we didnt tell you..with sqlite you can do easily that top15 of all players...doing motd in .sma, so you are only limited with characters there, thats one more difference compared to .php
Sorry, I didn't understand your explanation mate !!
But Thanks for atleast adding into help !! I appreciate it !!
 
Сообщения
146
Реакции
29
you can make motd window with top15 players (like you wanted) in the .sma, where will you get player informations from SQLite datbase (just like from nvault)...there are tutorials on net..but if you use mysql then you need space for databases and its better to load player informations (tables from database) by .php...im sorry if i didnt explain it good, it can be a little hard at the start to undestand how it is working..:)
 
Сообщения
213
Реакции
71
Помог
2 раз(а)
you can make motd window with top15 players (like you wanted) in the .sma, where will you get player informations from SQLite datbase (just like from nvault)...there are tutorials on net..but if you use mysql then you need space for databases and its better to load player informations (tables from database) by .php...im sorry if i didnt explain it good, it can be a little hard at the start to undestand how it is working..:)
Yes, now I understand and I also understood why its better to load information from .php, since it uses resources by web database and AMXX just send quries and recieves answers. (BlackSignature reply cleared it more). But I understood you too, this time !! Thanks Friend.
 
Последнее редактирование:

Пользователи, просматривающие эту тему

Сейчас на форуме нет ни одного пользователя.
Сверху Снизу