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

show Players play time in hours and minutes


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Vechta
Veteran Member
Join Date: Jun 2010
Old 09-05-2010 , 11:37   show Players play time in hours and minutes
Reply With Quote #1

Whats the best way to show Players play time in hours and minutes (saveable by nvault) ?
Vechta is offline
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 09-05-2010 , 11:44   Re: Stupid question number 2 :D
Reply With Quote #2

Catch the time on connect with a variable, then use the time they left to determine how long they were in the server.

Code:
new Float:connect[33] new total_time[33] public client_connect( id )     connect[id] = get_gametime() public client_disconnect( id )     total_time[id] = floatround( get_gametime() - connect[id] ) // total_time[id] holds the seconds the player was in the server // ( total_time[id] / 60 ) would hold the minutes // ( ( total_time[id] / 60 ) / 60 ) would hold the hours.
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
Vechta
Veteran Member
Join Date: Jun 2010
Old 09-05-2010 , 11:48   Re: Stupid question number 2 :D
Reply With Quote #3

sorry for stupid question but can you give me example how i can save it and show it in chat? xD
Vechta is offline
SpeeDeeR
Veteran Member
Join Date: Mar 2010
Location: Bulgaria
Old 09-05-2010 , 11:53   Re: Stupid question number 2 :D
Reply With Quote #4

https://forums.alliedmods.net/showthread.php?t=91503 asnwers all your questions
And putting it in chat differs for when do you want to put it.When client is connecting,when he is put in server or with command to see his own playtime.
SpeeDeeR is offline
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 09-05-2010 , 12:10   Re: Stupid question number 2 :D
Reply With Quote #5

Untested.

Code:
#include <amxmodx> #include <nvault> new Float:connect[33] new total_time[33] new vHandle new vAuthKey[33][35] public plugin_init() {     register_clcmd( "test", "CmdTest" )         vHandle = nvault_open( "timevault" ) } public plugin_end()     nvault_close( vHandle ) public client_connect( id ) {     connect[id] = get_gametime()         get_user_authid( id, vAuthKey[id], 34 ) } public client_disconnect( id )     SaveData( id )     public CmdTest( id ) {     CalcTotal( id )         new total = total_time[id] // since we'll be using total_time a lot and this is faster         client_print( id, print_chat, "Time In Seconds: %i", total )         // sorry for the ugliness here, ask me if you have any questions     new Hours = floatround( ( ( total / 60.0 ) / 60 ), floatround_floor )     new Minutes = floatround( ( total / 60.0 ), floatround_floor ) - ( Hours * 60 )     new Seconds = total - ( Hours * 60 ) - ( Minutes * 60 )         client_print( id, print_chat, "Standard Time Format: %i hrs, %i mins, and %i secs.", Hours, Minutes, Seconds ) }     CalcTotal( id ) {     total_time[id] = floatround( get_gametime() - connect[id] )     total_time[id] += nvault_get( vHandle, vAuthKey[id] ) } SaveData( id ) {     CalcTotal( id )         nvault_pset( vHandle, vAuthKey[id], total_time[id] ) }
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
Vechta
Veteran Member
Join Date: Jun 2010
Old 09-05-2010 , 12:28   Re: Stupid question number 2 :D
Reply With Quote #6

Thank you, i will test it later
Vechta is offline
platzpatrone
Veteran Member
Join Date: Apr 2007
Location: Germany
Old 09-05-2010 , 12:31   Re: Stupid question number 2 :D
Reply With Quote #7

also change the topic title pls to a title that made searching
easier like: show Players play time in hours and minutes
or something else.
platzpatrone is offline
Vechta
Veteran Member
Join Date: Jun 2010
Old 09-05-2010 , 12:37   Re: show Players play time in hours and minutes
Reply With Quote #8

Done.
Vechta is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 09-05-2010 , 12:50   Re: show Players play time in hours and minutes
Reply With Quote #9

Why don't use get_user_time et get_time_lengh ?

PHP Code:
#include <amxmodx>
#include <nvault>
#include <time>

#define VERSION "0.0.1"
#define PLUGIN "Played Time"

#define MAX_PLAYERS        32

new g_iVault

new g_szSteamId[MAX_PLAYERS+1][32]
new 
g_iLastPlayedTime[MAX_PLAYERS+1]

public 
plugin_init()
{
    
register_plugin(PLUGINVERSION"ConnorMcLeod")
    
register_dictionary("time.txt")

    
g_iVault nvault_open("played_time")

    
register_clcmd("say /playtime""ClientCommand_PlayedTime")
}

public 
plugin_end()
{
    
nvault_closeg_iVault )
}

public 
client_authorizedid )
{
    
get_user_authid(idg_szSteamId[id], charsmax(g_szSteamId[]))

    new 
szTime[32]
    
nvault_get(g_iVaultg_szSteamId[id], szTimecharsmax(szTime))
    
g_iLastPlayedTime[id] = str_to_num(szTime)
}

get_user_total_playtimeid )
{
    return 
g_iLastPlayedTime[id] + get_user_time(id)
}

public 
ClientCommand_PlayedTimeid )
{
    new 
szTime[128]
    
get_time_length(idget_user_total_playtimeid ), timeunit_secondsszTimecharsmax(szTime))
    
client_printidprint_chat"Played time : %s"szTime )
}

public 
client_disconnectid )
{
    new 
szTime[32]
    
formatex(szTimecharsmax(szTime), "%d"get_user_total_playtimeid ))
    
nvault_set(g_iVaultg_szSteamId[id], szTime)

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Vechta
Veteran Member
Join Date: Jun 2010
Old 09-05-2010 , 13:16   Re: show Players play time in hours and minutes
Reply With Quote #10

Quote:
Originally Posted by ConnorMcLeod View Post
Why don't use get_user_time et get_time_lengh ?

PHP Code:
#include <amxmodx>
#include <nvault>
#include <time>

#define VERSION "0.0.1"
#define PLUGIN "Played Time"

#define MAX_PLAYERS        32

new g_iVault

new g_szSteamId[MAX_PLAYERS+1][32]
new 
g_iLastPlayedTime[MAX_PLAYERS+1]

public 
plugin_init()
{
    
register_plugin(PLUGINVERSION"ConnorMcLeod")
    
register_dictionary("time.txt")

    
g_iVault nvault_open("played_time")

    
register_clcmd("say /playtime""ClientCommand_PlayedTime")
}

public 
plugin_end()
{
    
nvault_closeg_iVault )
}

public 
client_authorizedid )
{
    
get_user_authid(idg_szSteamId[id], charsmax(g_szSteamId[]))

    new 
szTime[32]
    
nvault_get(g_iVaultg_szSteamId[id], szTimecharsmax(szTime))
    
g_iLastPlayedTime[id] = str_to_num(szTime)
}

get_user_total_playtimeid )
{
    return 
g_iLastPlayedTime[id] + get_user_time(id)
}

public 
ClientCommand_PlayedTimeid )
{
    new 
szTime[128]
    
get_time_length(idget_user_total_playtimeid ), timeunit_secondsszTimecharsmax(szTime))
    
client_printidprint_chat"Played time : %s"szTime )
}

public 
client_disconnectid )
{
    new 
szTime[32]
    
formatex(szTimecharsmax(szTime), "%d"get_user_total_playtimeid ))
    
nvault_set(g_iVaultg_szSteamId[id], szTime)

Does this code print time in hours and minutes?
Vechta 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 03:31.


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