AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   New Plugin Submissions (https://forums.alliedmods.net/forumdisplay.php?f=26)
-   -   Time played - First seen - Last seen ( Nvault & SQL ) (https://forums.alliedmods.net/showthread.php?t=336209)

Supremache 02-04-2022 07:59

Time played - First seen - Last seen ( Nvault & SQL )
 
Time played
https://img.shields.io/badge/Release...%2C%202022-red https://img.shields.io/badge/Last%20...%2C%202022-red

Table of contents:
DESCRIPTION
It for saves the time played of the player, first seen and last seen on the server.

https://i.ibb.co/FB8KY4v/TimeList.png
https://i.ibb.co/kVTw1Fj/Timeplayed.png
API
Full documentation can be found there, as well in include file:
Credits

Bugsy( nVault Array )
OciXCrom( CromChat )
CHANGELOG
Download Files ( https://www.gametracker.com/images/i...on16x16_gt.png Server using this plugin )
http://i.imgur.com/XzUpc.png DOWNLOAD SOURCE CODE

Supremache 02-05-2022 08:50

Re: Time played ( First seen & Last seen )
 
How to use the natives:

https://i.ibb.co/sWBKXxg/Timeplayednatives.png

Code:

#include <amxmodx>
#include <unixtime>
// #include <time> for using get_time_length

native get_time_played( id )
native get_first_seen( id )
native get_last_seen( id )

#if !defined client_print_color
    #define client_print_color client_print
    #define print_team_default print_chat
#endif

#if !defined MAX_FMT_LENGTH
    const MAX_FMT_LENGTH = 192
#endif

public plugin_init( )
{
    register_plugin( "Time Played: Test", "", "Supremache" )
    register_clcmd( "say /playedtime", "@TimePlayed" )
}

@TimePlayed( id )
{
        static szTime[ 64 ], iYear , iMonth , iDay , iHour , iMinute , iSecond;
        new iTime = get_time_played( id ), iFirst = get_first_seen( id ), iLast = get_last_seen( id );
   
        client_print_color( id, print_team_default, "^4[Time Played]^1 Your Time:^4 %s", get_time_length_ex( iTime ) );
        UnixToTime( iFirst , iYear , iMonth , iDay , iHour , iMinute , iSecond );
        client_print_color( id, print_team_default, "^4[Time Played]^1 Joined Date:^4 %s %d, %d at %02d:%02d:%02d", str_to_month( iMonth ) , iDay , iYear , iHour , iMinute , iSecond );
        format_time( szTime, charsmax( szTime ), "%m/%d/%Y %H:%M:%S", iLast )
        client_print_color( id, print_team_default, "^4[Time Played]^1 Last Seen:^4 %s", szTime );
}
   
get_time_length_ex( iTime )
{
        new szTime[ MAX_FMT_LENGTH ], iYear, iMonth, iWeek, iDay, iHour, iMinute, iSecond;
   
        iTime -= 31536000 * ( iYear = iTime / 31536000 )
        iTime -= 2678400 * ( iMonth = iTime / 2678400 )
        iTime -= 604800 * ( iWeek = iTime / 604800 )
        iTime -= 86400 * ( iDay = iTime / 86400 )
        iTime -= 3600 * ( iHour = iTime / 3600 )
        iTime -= 60 * ( iMinute = iTime / 60 )
        iSecond = iTime
       
        formatex( szTime, charsmax( szTime ), "%d Second", iSecond )
        if( iMinute ) format( szTime, charsmax( szTime ), "%d Minute %s", iMinute, szTime )
        if( iHour ) format( szTime, charsmax( szTime ), "%d Hour %s", iHour, szTime )
        if( iDay ) format( szTime, charsmax( szTime ), "%d Day %s", iDay, szTime )
        if( iWeek ) format( szTime, charsmax( szTime ), "%d Week %s", iWeek, szTime )
        if( iMonth ) format( szTime, charsmax( szTime ), "%d Month %s", iMonth, szTime )
        if( iYear ) format( szTime, charsmax( szTime ), "%d Year %s", iYear, szTime )
   
        return szTime;
}

str_to_month( iMonth )
{
        static szDate[ 32 ];
       
        switch( iMonth )
        {
                case 1: copy( szDate, charsmax( szDate ), "January" )
                case 2: copy( szDate, charsmax( szDate ), "February" )
                case 3: copy( szDate, charsmax( szDate ), "March" )
                case 4: copy( szDate, charsmax( szDate ), "April" )
                case 5: copy( szDate, charsmax( szDate ), "May" )
                case 6: copy( szDate, charsmax( szDate ), "June" )
                case 7: copy( szDate, charsmax( szDate ), "July" )
                case 8: copy( szDate, charsmax( szDate ), "August" )
                case 9: copy( szDate, charsmax( szDate ), "September" )
                case 10: copy( szDate, charsmax( szDate ), "October" )
                case 11: copy( szDate, charsmax( szDate ), "November" )
                case 12: copy( szDate, charsmax( szDate ), "December" )
        }
        return szDate;
}


bigdaddy424 02-05-2022 12:35

Re: Time played ( First seen & Last seen )
 
Can you explain the use of using a task instead of subtracting @disonnected get_systime() with the one from @putinserver

Supremache 02-05-2022 13:15

Re: Time played ( First seen & Last seen )
 
Quote:

Originally Posted by bigdaddy424 (Post 2770597)
Can you explain the use of using a task instead of subtracting @disonnected get_systime() with the one from @putinserver

Code:
It is check when the user connecting to the server
public client_putinserver( id ) {
 Load the data from nvault
        UseNvault( id, false )
 after loading the data check if this user has joined before or not and if he is not then read the current time
        if( !g_iPlayer[ id ][ First_Seen ] ) g_iPlayer[ id ][ First_Seen ] = get_systime( );
 I see this way is better than saves get_user_time so if i used that way it gonna be like this g_iPlayer[ id ][ Time_Played ] += get_user_time( id ) / 60 and i need to use this way everytime when return it
 But using task for check the time every second when connected to the server is faster and better
        set_task( 1.0, "DisplayTimePlayed", id + TASK_TIME_PLAYED, .flags = "b" ); // Faster than get_user_time     } } public client_disconnected( id ) {     if( !g_iPlayer[ id ][ bBot_HLTV ] )     {
 Read the current time every time when the user left the server
        g_iPlayer[ id ][ Last_Seen ] = get_systime( );         UseNvault( id, true ); // save the data
 Clear the data
        arrayset( g_iPlayer[ id ][ Name ], 0, sizeof( g_iPlayer[ ][ Name ] ) );         arrayset( g_iPlayer[ id ][ AuthID ], 0, sizeof( g_iPlayer[ ][ AuthID ] ) );         arrayset( g_iPlayer[ id ][ IP ], 0, sizeof( g_iPlayer[ ][ IP ] ) );         arrayset( g_iPlayer[ id ][ Time_Played ], 0, sizeof( g_iPlayer[ ][ Time_Played ] ) );         arrayset( g_iPlayer[ id ][ First_Seen ], 0, sizeof( g_iPlayer[ ][ First_Seen ] ) );         arrayset( g_iPlayer[ id ][ Last_Seen ], 0, sizeof( g_iPlayer[ ][ Last_Seen ] ) );         arrayset( g_iPlayer[ id ][ bBot_HLTV ], false, sizeof( g_iPlayer[ ][ bBot_HLTV ] ) );         remove_task( id + TASK_TIME_PLAYED );     } }

bigdaddy424 02-05-2022 13:39

Re: Time played ( First seen & Last seen )
 
Isn't this better that a looping task?
You got end var as current timeframe in seconds
Code:
public client_putinserver(){     new start = get_systime() } public client_disconnected(){     new end = get_systime()     end -= start }

Supremache 02-05-2022 14:00

Re: Time played ( First seen & Last seen )
 
Quote:

Originally Posted by bigdaddy424 (Post 2770603)
Isn't this better that a looping task?
You got end var as current timeframe in seconds
Code:
public client_putinserver(){     new start = get_systime() } public client_disconnected(){     new end = get_systime() // this will read time when the user get disconnected     end -= start // so i need to return the time played when user disconnected but if is it the first time for the user it will be like this 0 -= join time and i think you know what this mean }

You missed something read this again:
Quote:

I see this way is better than saves get_user_time so if i used that way it gonna be like this g_iPlayer[ id ][ Time_Played ] += get_user_time( id ) / 60 and i need to use this way everytime when return it
But using task for check the time every second when connected to the server is faster and better
Edit: There are some ways to get time played of the player
  1. This way: g_iPlayer[ id ][ Time_Played ] += get_user_time( id ) / 60
  2. The way that i used
  3. Your way, but you have an issue in your code it shuld be ( start -= end ) because if this is the first time player has connected to the server and tryed to check his time played will be like 0 -= start and this mean - num also with this way i gonna use get_systime() four times and this is not faster

bigdaddy424 02-10-2022 18:07

Re: Time played ( First seen & Last seen )
 
Why do you think that set_task is better and faster than get_user_time()
I think that these natives are made so it's easier for you to work around with player time saving and all that. The person who coded also went an extra mile by counting the time it takes to connect. How generous

Supremache 02-10-2022 19:18

Re: Time played ( First seen & Last seen )
 
Quote:

Originally Posted by bigdaddy424 (Post 2771085)
Why do you think that set_task is better and faster than get_user_time()
I think that these natives are made so it's easier for you to work around with player time saving and all that. The person who coded also went an extra mile by counting the time it takes to connect. How generous

I think check the time automatic when connected to the server is faster than using get_user_time, if i am not correct then tell me why and i will use this way:

PHP Code:

@TotalTimePlayedid )
{
    new 
iTotalTime g_iPlayerid ][ Time_Played ] += get_user_timeid ) / 60;
    
client_print_coloridprint_team_default"You total time played is %i"iTotalTime )



bigdaddy424 02-19-2022 17:44

Re: Time played ( First seen & Last seen )
 
There's a server that I play on that uses your plugin and apparently my time keeps resetting.
You ever had this issue before?

Supremache 02-19-2022 18:22

Re: Time played ( First seen & Last seen )
 
Quote:

Originally Posted by bigdaddy424 (Post 2771963)
There's a server that I play on that uses your plugin and apparently my time keeps resetting.
You ever had this issue before?

Furien ? If yes then I will tell you why it happened because they save the data using the name and I didn't check it while the player changed his name to a new name that has no time, so the time get reset , How i fixed this issue ? I added a code that checks when the player changes his name And before the change I save the data and after the change, I set the time to zero and add the code that load the data from the nvualt file.

Edit: Update soon.


All times are GMT -4. The time now is 06:54.

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