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

Plugin calculating hours played...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
CsIosefin
Senior Member
Join Date: Aug 2009
Old 01-05-2010 , 08:59   Plugin calculating hours played...
Reply With Quote #1

Hi,
I know there are plugin "Time Played" Mr Alka's, but I want something similar but much simpler (not that I be with other stuff, if not used ...)
What I was I calculate time spent on your server (all, after all saved each reconecare be named).
What I want, when you order in chat "/ h" appears like "your accumulated hours are: 1 hour 22 minute 33 seconds."
Do you guys that can do something simple and good? Waiting for a reply, thanks.
CsIosefin is offline
Old 01-05-2010, 10:06
AppStore
This message has been deleted by AppStore. Reason: bug
CsIosefin
Senior Member
Join Date: Aug 2009
Old 01-06-2010 , 09:31   Re: Plugin calculating hours played...
Reply With Quote #2

Up!
CsIosefin is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 01-06-2010 , 09:36   Re: Plugin calculating hours played...
Reply With Quote #3

Read the rules, you have to wait 15 days from your last posts. Be patient and learn the pawn. Also you have posted in the wrong forum, since you are not willing to learn, you should have posted in the request section.
__________________
Arkshine is offline
Dygear
SourceMod Donor
Join Date: Apr 2004
Location: Levittown, NY
Old 01-11-2010 , 23:55   Re: Plugin calculating hours played...
Reply With Quote #4

Code:
new Int:time = get_user_time(id); new Int:h = (time / 3600) % 60; new Int:m = ((time - (h * 3600)) / 60) % 60; new Int:s = time - ((h * 3600) + (m * 60)); client_print(id, print_chat, "Has been playing for %d hours, %d minutes, %d seconds", h, m, s);
__________________
Dygear is offline
Send a message via AIM to Dygear Send a message via MSN to Dygear Send a message via Skype™ to Dygear
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 01-12-2010 , 01:12   Re: Plugin calculating hours played...
Reply With Quote #5

not tested:
PHP Code:
#include <amxmodx>
#include <nvault>

new g_auth[33][24]
new 
g_time_played[33]
new 
g_connect_time[33]
new 
g_db_name[] = "time_played"

public plugin_init(){
    
register_plugin("Player Time Played""1.0""Sylwester")
    
register_clcmd("say /h""show_time")
}

public 
show_time(id){
    if(
g_time_played[id] == -1){
        
client_print(idprint_chat"Server was unable to retrieve your time played.")
        return
    }
    new 
time()-g_connect_time[id]+g_time_played[id]
    new 
t/3600
    
new t/60%60
    
new t%60
    client_print
(idprint_chat"Your total time played is: %d hour%s %d minute%s %d second%s.",
    
hh==1?"":"s"mm==1?"":"s"ss==1?"":"s")
}

public 
client_connect(id)
    
g_auth[id][0] = '^0'
    
public client_putinserver(id)
    
g_connect_time[id] = time()

public 
client_authorized(id){
    
get_user_authid(idg_auth[id], 23)
    new 
nv_hnd nvault_open(g_db_name)
    if(
nv_hnd == INVALID_HANDLE){
        
log_amx("Failed to open nVault %s."g_db_name)
        
g_time_played[id] = -1
        
return
    }
    new 
data[10], ts
    
if(!nvault_lookup(nv_hndg_auth[id], data9ts))
        
g_time_played[id] = 0
    
else
        
g_time_played[id] = str_to_num(data)
    
nvault_close(nv_hnd)
}

public 
client_disconnect(id){
    if(
g_auth[id][0] == '^0' || g_time_played[id] == -1)
        return
    new 
nv_hnd nvault_open(g_db_name)
    new 
data[10]
    
formatex(data9"%d"time()-g_connect_time[id]+g_time_played[id])
    
nvault_set(nv_hndg_auth[id], data)
    
nvault_close(nv_hnd)

__________________
Impossible is Nothing
Sylwester is offline
Dygear
SourceMod Donor
Join Date: Apr 2004
Location: Levittown, NY
Old 01-12-2010 , 22:41   Re: Plugin calculating hours played...
Reply With Quote #6

PHP Code:
    $h $time 3600;
    
$m $time 60 60;
    
$s $time 60
Beautiful code, Sylwester. Casting to int solves the rounding issue, and that's done by the %d modifier.
__________________
Dygear is offline
Send a message via AIM to Dygear Send a message via MSN to Dygear Send a message via Skype™ to Dygear
Dygear
SourceMod Donor
Join Date: Apr 2004
Location: Levittown, NY
Old 01-13-2010 , 14:08   Re: Plugin calculating hours played...
Reply With Quote #7

My answer in 21 lines of code.

Code:
#include <amxmodx> #define getSeconds(%1)  (%1 % 60) #define getMinutes(%1)  (%1 / 60 % 60) #define getHours(%1)    (%1 / 3600) #define getPlural(%1)   ((%1 != 1) ? "s" : "") public plugin_init() {     register_plugin("Play Time", "1.0", "Dygear");     register_clcmd("say /h", "getPlayTime"); } public getPlayTime(id) {     new time = get_user_time(id);     new h = getHours(time), i = getMinutes(time), s = getSeconds(time);     client_print(         id, print_chat,         "Your accumulated hours are: %d hour%s %d minute%s and %d second%s.",         h, getPlural(h), i, getPlural(i), s, getPlural(s)     ); }

Code:
Welcome to the AMX Mod X 1.8.1-300 Compiler.
Copyright (c) 1997-2006 ITB CompuPhase, AMX Mod X Team

Header size:            204 bytes
Code size:              596 bytes
Data size:              468 bytes
Stack/heap size:      16384 bytes; estimated max. usage=40 cells (160 bytes)
Total requirements:   17652 bytes
Done.
__________________
Dygear is offline
Send a message via AIM to Dygear Send a message via MSN to Dygear Send a message via Skype™ to Dygear
g_often
Senior Member
Join Date: Jan 2010
Location: In your mind
Old 01-13-2010 , 18:18   Re: Plugin calculating hours played...
Reply With Quote #8

Quote:
Originally Posted by Dygear View Post
My answer in 21 lines of code.

Code:
#include <amxmodx> #define getSeconds(%1)&nbsp;&nbsp;&nbsp;&nbsp;(%1 % 60) #define getMinutes(%1)&nbsp;&nbsp;&nbsp;&nbsp;(%1 / 60 % 60) #define getHours(%1)&nbsp;&nbsp;&nbsp;&nbsp;(%1 / 3600) #define getPlural(%1)&nbsp;&nbsp;&nbsp;&nbsp;((%1 != 1) ? "s" : "") public plugin_init() { &nbsp;&nbsp;&nbsp;&nbsp;register_plugin("Play Time", "1.0", "Dygear");
&nbsp;&nbsp;&nbsp;&nbsp;register_clcmd("say /h", "getPlayTime");
} public getPlayTime(id) { &nbsp;&nbsp;&nbsp;&nbsp;new time = get_user_time(id);
&nbsp;&nbsp;&nbsp;&nbsp;new h = getHours(time), i = getMinutes(time), s = getSeconds(time);
&nbsp;&nbsp;&nbsp;&nbsp;client_print( &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;id, print_chat, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;"Your accumulated hours are: %d hour%s %d minute%s and %d second%s.",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;h, getPlural(h), i, getPlural(i), s, getPlural(s) &nbsp;&nbsp;&nbsp;&nbsp;);
}



Code:
Welcome to the AMX Mod X 1.8.1-300 Compiler.
Copyright (c) 1997-2006 ITB CompuPhase, AMX Mod X Team

Header size:            204 bytes
Code size:              596 bytes
Data size:              468 bytes
Stack/heap size:      16384 bytes; estimated max. usage=40 cells (160 bytes)
Total requirements:   17652 bytes
Done.

nice code! this work perfectly.
g_often is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 01-13-2010 , 20:19   Re: Plugin calculating hours played...
Reply With Quote #9

It may be perfect, but it doesn't do what the thread author has requested.
He wants to save the time in a way that when the client reconnects his time is recovered.
Sylwester code seems to work just fine.
Seta00 is offline
g_often
Senior Member
Join Date: Jan 2010
Location: In your mind
Old 01-13-2010 , 20:48   Re: Plugin calculating hours played...
Reply With Quote #10

PHP Code:
#include <amxmodx>

public plugin_init() register_clcmd("say /h","GetTime")

public 
GetTime(id){
    new 
time  get_user_time(id)
    new 
time 3600time 60 60time 60
    
    client_print
(idprint_chat"Time Playing: Hours %d, Minutes: %d, Seconds: %d",h,m,s)

this work too, but... i don't understend very well for wath is the symbol "%", example

PHP Code:
time 60 
g_often 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 00:10.


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