Raised This Month: $ Target: $400
 0% 

Add a some values to vault..


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
alonelive
Senior Member
Join Date: Jan 2011
Location: Big snow country.. :)
Old 06-14-2013 , 15:34   Add a some values to vault..
Reply With Quote #1

Hello!
I have this plugin, which collect played time.

PHP Code:
/*Played Time with "Current(Total) played Time" on server.*/
/*Many thanks to hackziner & Deviance for show how to use "nvault".*/
/*Thanks to Avalanche for Prune function*/


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

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

/*Prune time:ater x time of beeing inactive,remove valutdata*/
#define PRUNE_TIME 5184000 /*2 x 30 days*/ /*Time in seconds*/


enum _:VaultDataN
{
    
VD_Key[64],
    
VD_Value
};


new 
TotalPlayedTime[33];

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR );
    
register_concmd("amx_ptime""admin_showptime"ADMIN_KICK," <#Player Name> - Details about playedtime.");
    
    
register_clcmd("say /ptop15""show_top15");
    
register_clcmd("say_team /ptop15""show_top15");
}



public 
admin_showptime(id,level,cid
{
    if(!
cmd_access(idlevelcid2))
        return 
PLUGIN_HANDLED;
    
    static 
arg[32];
    
read_argv(1arg31);
    
    new 
player cmd_target(idarg2);
    
    if(!
player)
        return 
PLUGIN_HANDLED;
    
    static 
name[32];
    
get_user_name(playername31);
    
    if((
containi(name"Player") != -1) || (containi(name"detected") != -1))
    {
        
console_print(id"TimeStats data not available for nickname player and etc.");
        return 
PLUGIN_HANDLED
    
}
    
    static 
timepctime[64];
    
    
timep get_user_time(player1) / 60;
    
get_time("%H:%M:%S"ctime63);
    
    
console_print(id"-----------------------(#PlayedTime#)-----------------------");
    
console_print(id"[PT]%s have been playing on the server for %d minute%s.",nametimeptimep == "" "s");
    
console_print(id"[PT]%s's total played time on the server %d minute%s.",nametimep+TotalPlayedTime[player], timep == "" "s"); // new
    
console_print(id"[PT]Current time: %s"ctime);
    
console_print(id"-----------------------------------------------------------------");
    
    return 
PLUGIN_HANDLED;
}


public 
client_disconnect(id)
{
    if(
is_user_bot(id))
    return 
PLUGIN_HANDLED
    
    
    
new pName[33]
    
get_user_name(idpNamecharsmax(pName))
    
    if((
containi(pName"Player") != -1) || (containi(pName"detected") != -1))
    return 
PLUGIN_HANDLED
    
    TotalPlayedTime
[id] = TotalPlayedTime[id] + (get_user_time(id)/60);
    
SaveTime(idTotalPlayedTime[id]);
    
    return 
PLUGIN_CONTINUE
}

public 
client_putinserver(id)
{
    if(
is_user_bot(id))
    return 
PLUGIN_HANDLED
    
    
new pName[33]
    
get_user_name(idpNamecharsmax(pName))
    
    if((
containi(pName"Player") != -1) || (containi(pName"detected") != -1))
    return 
PLUGIN_HANDLED
    
    TotalPlayedTime
[id] = LoadTime(id);
    
    return 
PLUGIN_CONTINUE
}

public 
LoadTimeid 
{
    if(
is_user_bot(id))
    {
        return 
PLUGIN_HANDLED
    
}
    
    new 
valut nvault_open("Time_played")
    
    new 
name[33];
    new 
vaultkey[64], vaultdata[64];
    
    
get_user_name(idname32);
    
    if((
containi(name"Player") != -1) || (containi(name"detected") != -1))
    return 
PLUGIN_HANDLED
    
    format
(vaultkey63"> %s"name);
    
    
nvault_get(valutvaultkeyvaultdata63);
    
nvault_close(valut);
    
    return 
str_to_num(vaultdata);
}

public 
SaveTime(id,PlayedTime)
{
    if(
is_user_bot(id))
    return 
PLUGIN_HANDLED
    
    
new valut nvault_open("Time_played")
    
    if(
valut == INVALID_HANDLE)
        
set_fail_state("nValut returned invalid handle")
    
    new 
name[33];
    new 
vaultkey[64], vaultdata[64];
    
    
get_user_name(idname32);
    
    if((
containi(name"Player") != -1) || (containi(name"detected") != -1))
    return 
PLUGIN_HANDLED
    
    format
(vaultkey63"> %s"name); 
    
format(vaultdata63"%d"PlayedTime); 
    
    
nvault_set(valutvaultkeyvaultdata);
    
nvault_close(valut);
    
    return 
PLUGIN_CONTINUE
}

public 
prune()
{
    new 
valut nvault_open("Time_played");
    
    if(
valut == INVALID_HANDLE)
        
set_fail_state("nValut returned invalid handle");
    
    
nvault_prune(valut0get_systime() - PRUNE_TIME);
    
nvault_close(valut);
}

public 
plugin_end()
{
    
prune()
}



public 
show_top15(id)
{
    
// maximum number of entries to save in array
    
const MAX_ENTRIES 10;
    
    
// open the vualt
    
new vault nvault_util_open("vaultname");
    
    
// create our array to hold entries and keep track of its size
    
new Array:entries ArrayCreate(VaultDataN);
    new 
sizeEntries;
    
    
// count entries in vault and prepare variables
    
new numEntries nvault_util_count(vault);
    new 
data[VaultDataN], value[12], data2[VaultDataN];
    
    
// iterate through all entries
    
for(new 0postimestampnumEntriesi++) {
        
// grab entry data from current position
        
pos nvault_util_read(vaultposdata[VD_Key], charsmax(data[VD_Key]), valuecharsmax(value), timestamp);
        
        
// turn value string into integer
        
data[VD_Value] = str_to_num(value);
        
        
// if this is the first entry
        
if(sizeEntries == 0) {
            
// go ahead and add it
            
ArrayPushArray(entriesdata);
            
sizeEntries++;
        } else {
            
// loop through other entries to see where this one should be placed (sorted from HIGH->LOW)
            
for(timestamp 0timestamp <= sizeEntriestimestamp++) {
                
// if we looped through all entries without finding a place
                
if(timestamp == sizeEntries) {
                    
// this entry value is too low to fit before any others
                    // if we have room at the end of the array
                    
if(sizeEntries MAX_ENTRIES) {
                        
// add it to the end
                        
ArrayPushArray(entriesdata);
                        
sizeEntries++;
                    }
                    
                    
// don't continue with code below
                    
break;
                }
                
                
// grab current entry to compare it with
                
ArrayGetArray(entriestimestampdata2);
                
                
// if this new entry should be placed before the compared entry
                
if(data[VD_Value] >= data2[VD_Value]) {
                    
// insert before
                    
ArrayInsertArrayBefore(entriestimestampdata);
                    
                    
// if we aren't maxxed out
                    
if(sizeEntries MAX_ENTRIES) {
                        
// increase entry size
                        
sizeEntries++;
                    } else {
                        
// delete the last entry to keep the size at maximum
                        
ArrayDeleteItem(entriessizeEntries);
                    }
                    
                    break;
                }
            }
        }
    }
    
    
// close the vault
    
nvault_util_close(vault);
    
    
// loop through our entries and display them
    
server_print("Top %d entries are:"MAX_ENTRIES);
    
    for(new 
0sizeEntriesi++) {
        
// grab current entry
        
ArrayGetArray(entriesidata);
        
        
// truncate entry key for output
        
data[VD_Key][20] = 0;
        
        
// display data
        
server_print("%d. %-20.20s %d", (1), data[VD_Key], data[VD_Value]);
    }
    
    
// destroy the entry array from cache
    
ArrayDestroy(entries);
}


stock bool:IsOdd(num)
{
    return 
num == 0
}

public 
stats_custom_compare(elem1[],elem2[])
{
    if(
elem1[1] > elem2[1]) return -1;
    else if(
elem1[1] < elem2[1]) return 1;
        
    return 
0;

It's a working combination of:

Exolent[jNr]'s https://forums.alliedmods.net/showpo...11&postcount=6
and
Alka's https://forums.alliedmods.net/showthread.php?p=457071



What we have: a number in list, name of player and his total time in game):
PHP Code:
  server_print("%d. %-20.20s %d", (1), data[VD_Key], data[VD_Value]); 
What i want: new format of stored data - number in list, name of player, his total time, tis time for each day of last week, last connection time. We can replace su, mo, tu and etc. with a date (8, 9, 10, 11, 12, 13, 14 of jun, for example)
PHP Code:
  server_print("%d. %-20.20s %d %d %d %d %d %d %d %d %s", (1), data[VD_Key], data[VD_Value], data[su], data[mo], data[tu], data[we], data[th], data[fr], data[sa], data[last]); 
PHP Code:
[num][name]  [total played time]    [su] [mo] [tu] [we] [th] [fr] [sa]     [last]
[
1]  [user1] [6565]                 [66] [55] [32] [0]  [10] [1]  [150]    [01/01/2012 15:45:01
__________________
sorry my bad english...

Last edited by alonelive; 06-14-2013 at 15:38.
alonelive is offline
Reply



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 20:10.


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