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

[REQ] Online time counter


Post New Thread Reply   
 
Thread Tools Display Modes
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 05-04-2016 , 09:22   Re: [REQ] Online time counter
Reply With Quote #11

This have been mention before... I mention it again.
SQL or clientprefs - Store Times
Quote:
Originally Posted by asherkin View Post
Don't use clientprefs for things that are not client preferences.
So note to new plugin developers, this is bad example.

Quote:
Originally Posted by Arkarr View Post
Not tested, but should work ;) !
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <clientprefs>
#include <multicolors>

#define PLUGIN_AUTHOR "Arkarr"
#define PLUGIN_VERSION "1.00"

Handle COOKIE_playtime INVALID_HANDLE;

int seconds[MAXPLAYERS+1];

public 
Plugin myinfo 
{
    
name "[ANY] Playtime",
    
author PLUGIN_AUTHOR,
    
description "Show how much time a player spent time on the server.",
    
version PLUGIN_VERSION,
    
url "http://www.sourcemod.net"
};

public 
void OnPluginStart()
{
    
COOKIE_playtime RegClientCookie("sm_playetime_seconds""Store the number of seconds spent on the server."CookieAccess_Private);
    
CreateTimer(1.0TMR_IncreaseSeconds_TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
    
    
RegConsoleCmd("sm_playtime"CMD_PlayeTime"Display the time played in the server.");
    
    for(new 
MaxClients0; --i)
    {
        if(!
AreClientCookiesCached(i))
            continue;
            
        
OnClientCookiesCached(i);
    }
}

public 
void OnClientCookiesCached(int client)
{
    
char cookieValue[10];
    
GetClientCookie(clientCOOKIE_playtimecookieValuesizeof(cookieValue));
    
seconds[client] = StringToInt(cookieValue);
}

public 
Action CMD_PlayeTime(int clientint args)
{
    if(
client == 0)
        return 
Plugin_Handled;
    
    
int houres 0;
    
int minutes seconds[client] / 60;
    
    while(
minutes 60)
    {
        
houres++;
        
minutes -= 60;        
    }
    
    
CPrintToChatAll("{green}%N{default} played %i houres and %i minutes in this server !"clienthouresminutes);    
    
    return 
Plugin_Handled;
}

public 
void OnClientDisconnect(client)
{
    
char cookieValue[10];
    
IntToString(seconds[client], cookieValuesizeof(cookieValue));
    
SetClientCookie(clientCOOKIE_playtimecookieValue);    
}

public 
Action TMR_IncreaseSeconds(Handle timer)
{
    for(new 
MaxClients0; --i)
    {
        if(
IsValidClient(i))
        {
            
seconds[i]++;
        }
    }
}
    
stock bool IsValidClient(client)
{
    if(
client <= ) return false;
    if(
client MaxClients) return false;
    if(!
IsClientConnected(client)) return false;
    return 
IsClientInGame(client);

Donate if you enjoy my work !
__________________
Do not Private Message @me
Bacardi is offline
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 05-04-2016 , 09:54   Re: [REQ] Online time counter
Reply With Quote #12

Oh. Well... Thanks for pointing this out. I didn't know it. Although it doesn't sounds bad to me. Why would you setup a database just for this kind of things ? Should I have used text file instead ? This sounds even worse. Somebody could help me ?
__________________
Want to check my plugins ?
Arkarr is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 05-04-2016 , 10:12   Re: [REQ] Online time counter
Reply With Quote #13

...you can also use already exist database. Just create new table.
Quote:
Originally Posted by Arkarr View Post
Oh. Well... Thanks for pointing this out. I didn't know it. Although it doesn't sounds bad to me. Why would you setup a database just for this kind of things ? Should I have used text file instead ? This sounds even worse. Somebody could help me ?
__________________
Do not Private Message @me
Bacardi is offline
Advanced Deal
New Member
Join Date: May 2016
Old 05-04-2016 , 17:19   Re: [REQ] Online time counter
Reply With Quote #14

So I get this when trying to compile.
Advanced Deal is offline
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 05-05-2016 , 04:22   Re: [REQ] Online time counter
Reply With Quote #15

Quote:
Originally Posted by Bacardi View Post
...you can also use already exist database. Just create new table.
I don't think hijacking database is a good practice either. I will search for a better solution... But right now, it looks like we have to create a 'general' database to store some values from different plugins ? Doesn't looks good to me.
Quote:
Originally Posted by Advanced Deal View Post
So I get this when trying to compile.
Don't use my plugin, it's considered as bad.
__________________
Want to check my plugins ?
Arkarr is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 05-05-2016 , 17:19   Re: [REQ] Online time counter
Reply With Quote #16

...it's not hijacking if database locate in your server files or is your "property" in mysql host. And as long as you create unique table name then it's allright.


Here example, I tried make it work so it use temporary connections to local database (Sourcemod SQLite only).
Maybe either not perfect example but works somehow.

...dam, can't post source code. Cloud system give block

here *.sp

updated
added server command to clear database table
sm_playtime_empty_table
Attached Files
File Type: sp Get Plugin or Get Source (test.sp - 170 views - 3.9 KB)
__________________
Do not Private Message @me

Last edited by Bacardi; 05-05-2016 at 17:45.
Bacardi 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 23:14.


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