Raised This Month: $12 Target: $400
 3% 

Time played - First seen - Last seen ( Nvault & SQL )


Post New Thread Reply   
 
Thread Tools Display Modes
Plugin Info:     Modification:   Counter-Strike        Category:   Statistical       
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 02-04-2022 , 07:59   Time played - First seen - Last seen ( Nvault & SQL )
Reply With Quote #1

Time played


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



API
Full documentation can be found there, as well in include file:
Credits

Bugsy( nVault Array )
OciXCrom( CromChat )
CHANGELOG
Download Files ( Server using this plugin )
DOWNLOAD SOURCE CODE
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.

Last edited by Supremache; 05-16-2022 at 09:21. Reason: New Updates v1.1.2
Supremache is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 02-05-2022 , 08:50   Re: Time played ( First seen & Last seen )
Reply With Quote #2

How to use the natives:



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;
}
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.

Last edited by Supremache; 04-18-2022 at 09:37.
Supremache is offline
bigdaddy424
Senior Member
Join Date: Oct 2021
Location: Jupiter
Old 02-05-2022 , 12:35   Re: Time played ( First seen & Last seen )
Reply With Quote #3

Can you explain the use of using a task instead of subtracting @disonnected get_systime() with the one from @putinserver
bigdaddy424 is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 02-05-2022 , 13:15   Re: Time played ( First seen & Last seen )
Reply With Quote #4

Quote:
Originally Posted by bigdaddy424 View Post
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 );     } }
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.

Last edited by Supremache; 02-05-2022 at 13:30.
Supremache is offline
bigdaddy424
Senior Member
Join Date: Oct 2021
Location: Jupiter
Old 02-05-2022 , 13:39   Re: Time played ( First seen & Last seen )
Reply With Quote #5

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 }
bigdaddy424 is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 02-05-2022 , 14:00   Re: Time played ( First seen & Last seen )
Reply With Quote #6

Quote:
Originally Posted by bigdaddy424 View Post
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
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.

Last edited by Supremache; 02-05-2022 at 15:32.
Supremache is offline
bigdaddy424
Senior Member
Join Date: Oct 2021
Location: Jupiter
Old 02-10-2022 , 18:07   Re: Time played ( First seen & Last seen )
Reply With Quote #7

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
bigdaddy424 is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 02-10-2022 , 19:18   Re: Time played ( First seen & Last seen )
Reply With Quote #8

Quote:
Originally Posted by bigdaddy424 View Post
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 )

__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.

Last edited by Supremache; 02-10-2022 at 20:43.
Supremache is offline
bigdaddy424
Senior Member
Join Date: Oct 2021
Location: Jupiter
Old 02-19-2022 , 17:44   Re: Time played ( First seen & Last seen )
Reply With Quote #9

There's a server that I play on that uses your plugin and apparently my time keeps resetting.
You ever had this issue before?
bigdaddy424 is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 02-19-2022 , 18:22   Re: Time played ( First seen & Last seen )
Reply With Quote #10

Quote:
Originally Posted by bigdaddy424 View Post
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.
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.

Last edited by Supremache; 02-19-2022 at 18:31.
Supremache is offline
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 00:49.


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