AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Re : Played time script help, time not saved for offline players. (https://forums.alliedmods.net/showthread.php?t=194440)

lolness 08-28-2012 12:10

Re : Played time script help, time not saved for offline players.
 
I have 3 issues regarding this code.

1. it doesn't save time for offline players. when a player plays for 10 mins & leaves the server, i check in top15time list & his name is not there.
2. when server crashes, all time is erased from all players.
3. when a player plays from the start and another player joins later, both of the players' times become the same.
example : i was playing for 20 mins on my server & one guy joined my server. I checked the top15time list & i saw that even his time is 20 mins played on the server, when he actually has only played for 5-10 seconds :/

Anyone pls fix these 3 issues for me asap :)
thanku :)

PHP Code:

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

#define PLUGIN "PlayedTime"
#define VERSION "3.3"
#define AUTHOR "Ricardo"

/*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 2592000 /*30 days*/ /*Time in seconds*/

new showpt;

new 
TotalPlayedTime[33];

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR );
    
    
register_clcmd("say""handle_say");
    
register_concmd("amx_playedtime""admin_showptime"ADMIN_KICK," <#Player Name> - Details about playedtime.");
    
register_clcmd("say /top15_time""show_top15");
    
    
showpt register_cvar("amx_pt_mod","1");
    
}

public 
handle_say(id
{
    static 
said[9]
    
read_argv(1said8);
    
    if(
equali(said"/my_time"))
    {
        static 
ctime[64], timep;
        
        
timep get_user_time(id1) / 60;
        
get_time("%H:%M:%S"ctime63);
        
        switch(
get_pcvar_num(showpt))
        {
            case 
0: return PLUGIN_HANDLED;
                
            case 
:
            {
                
client_print(idprint_chat"[PT]You have been playing on the server for: %d minute%s."timeptimep == "" "s");
                
#if defined NVAULT 
                
client_print(idprint_chat"[PT]Your total played time on the server: %d minute%s."timep+TotalPlayedTime[id], timep+TotalPlayedTime[id] == "" "s");
                
#endif
                
client_print(idprint_chat"[PT]Current time: %s"ctime);
            }
            case 
:
            {
                
set_hudmessage(25550500.340.5006.04.00.10.2, -1);
                
show_hudmessage(id"[PT]You have been playing on the server for: %d minute%s.^n[PT]Current time: %s"timeptimep == "" "s"ctime);
            }
        }
        return 
PLUGIN_HANDLED;
    }
    return 
PLUGIN_CONTINUE;
}

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);
    
    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");
    
#if defined NVAULT
    
console_print(id"[PT]%s's total played time on the server %d minute%s.",nametimep+TotalPlayedTime[player], timep == "" "s"); // new
    #endif
    
console_print(id"[PT]Current time: %s"ctime);
    
console_print(id"-----------------------------------------------------------------");
    
    return 
PLUGIN_HANDLED;
}

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

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

#if defined NVAULT
public LoadTimeid 
{
    new 
valut nvault_open("Time_played")
    
    new 
authid[33];
    new 
vaultkey[64], vaultdata[64];
    
    
get_user_authid(idauthid32);
    
    
format(vaultkey63"TIMEPLAYED%s"authid);
    
    
nvault_get(valutvaultkeyvaultdata63);
    
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(idauthid32);
    
    
format(vaultkey63"TIMEPLAYED%s"authid); 
    
format(vaultdata63"%d"PlayedTime); 
    
    
nvault_set(valutvaultkeyvaultdata);
    
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(valut0get_systime() - PRUNE_TIME);
    
nvault_close(valut);
}
#endif

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

#if defined NVAULT
public show_top15(id)
{
    new 
icount;
    static 
sort[33][2], maxPlayers;
    
    if(!
maxPlayersmaxPlayers get_maxplayers();
    
    for(
i=1;i<=maxPlayers;i++)
    {
        
sort[count][0] = i;
        
sort[count][1] = TotalPlayedTime[i] + (get_user_time(i1) / 60);
        
count++;
    }
    
    
SortCustom2D(sort,count,"stats_custom_compare");
    
    new 
motd[1024], len    
    
    len 
format(motd1023,"<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
(playersnum)
    
    new 
clamp(count,0,15)
    
    new 
name[32], player
    
    
for(new 0ba++)
    {
        
player sort[a][0]
        
        
get_user_name(playername31)        
        
len += format(motd[len], 1023-len,"%d %-22.22s %d^n"a+1namesort[a][1])
    }
    
    
len += format(motd[len], 1023-len,"</body></font></pre>")
    
show_motd(idmotd"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;



SPT1 08-28-2012 14:48

Re: Re : Played time script help, time not saved for offline players.
 
http://forums.alliedmods.net/showpos...26&postcount=5

lolness 08-28-2012 16:40

Re: Re : Played time script help, time not saved for offline players.
 
It says runtime error.c++, something like that :(

SPT1 08-28-2012 17:19

Re: Re : Played time script help, time not saved for offline players.
 
show the image

lolness 08-29-2012 05:58

Re: Re : Played time script help, time not saved for offline players.
 
1 Attachment(s)
see

SPT1 08-29-2012 06:09

Re: Re : Played time script help, time not saved for offline players.
 
type in google that error you may get the solution

Alka 08-29-2012 06:17

Re: Re : Played time script help, time not saved for offline players.
 
lol, seriously? Who the hell is Ricardo? This is my Played Time plugin with few variables renamed and version 3.3 instead of 1.3.

SPT1 08-29-2012 07:23

Re: Re : Played time script help, time not saved for offline players.
 
alka why don't you update your plugin
and make top15 for offline and online players?

EpicMonkey 08-29-2012 07:41

Re: Re : Played time script help, time not saved for offline players.
 
Quote:

Originally Posted by Alka (Post 1785933)
lol, seriously? Who the hell is Ricardo? This is my Played Time plugin with few variables renamed and version 3.3 instead of 1.3.

was about to point that out :3


All times are GMT -4. The time now is 05:43.

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