Raised This Month: $ Target: $400
 0% 

SQL or clientprefs - Store Times


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
TheUnderTaker
Senior Member
Join Date: Dec 2013
Location: Israel
Old 08-03-2015 , 15:45   SQL or clientprefs - Store Times
Reply With Quote #1

Hi guys,
Im not in my country yet and when i back i want to do something with times, can someone learn me how to store times? Do not give me links, explanation on pm or here.

Thanks.
__________________
SourcePawn, C# and C++ Programmer.

My plugin list
TheUnderTaker is offline
Benoist3012
Veteran Member
Join Date: Mar 2014
Location: CWave::ForceFinish()
Old 08-03-2015 , 15:48   Re: SQL or clientprefs - Store Times
Reply With Quote #2

If you are going to store times for more than 1 server then use sql else, you can use cookies depend on what you want to do.
__________________
Benoist3012 is offline
TheUnderTaker
Senior Member
Join Date: Dec 2013
Location: Israel
Old 08-03-2015 , 15:50   Re: SQL or clientprefs - Store Times
Reply With Quote #3

Quote:
Originally Posted by Benoist3012 View Post
If you are going to store times for more than 1 server then use sql else, you can use cookies depend on what you want to do.
Need on than 1 servers... But i can do it twice.
I know cookies but dont know how to store times.

Btw i need to know how i dont need method names..
__________________
SourcePawn, C# and C++ Programmer.

My plugin list

Last edited by TheUnderTaker; 08-03-2015 at 15:51.
TheUnderTaker is offline
Benoist3012
Veteran Member
Join Date: Mar 2014
Location: CWave::ForceFinish()
Old 08-03-2015 , 15:59   Re: SQL or clientprefs - Store Times
Reply With Quote #4

Quote:
Originally Posted by TheUnderTaker View Post
Need on than 1 servers... But i can do it twice.
I know cookies but dont know how to store times.

Btw i need to know how i dont need method names..
Well actually store time with cookies is easy. First you need to create the name
PHP Code:
Handle htimePlayed;
public 
void OnPluginStart()
{
    
hTimePlayed RegClientCookie("sm_time_played""Time played on the server"CookieAccess_Protected);
//CookieAccess_Protected this block anyone from modifying it
public OnClientDisconnect(client)
{
    if (!
IsValidClient(client)) return;
    
int time 0;
    
char oldtime[64];
    if (!
IsFakeClient(client) && AreClientCookiesCached(client))
    {
        
GetClientCookie(clienthTimePlayedoldtimesizeof(oldtime));
        
time StringToInt(oldtime);
        
time += TimePlayed[client]; //I let you create a timer and add up 1 each second
        
IntToString(timeoldtimesizeof(oldtime));
        
SetClientCookie(clienthTimePlayedoldtime);
    }

A little scrap of code for you
__________________

Last edited by Benoist3012; 08-03-2015 at 16:00.
Benoist3012 is offline
TheUnderTaker
Senior Member
Join Date: Dec 2013
Location: Israel
Old 08-06-2015 , 09:05   Re: SQL or clientprefs - Store Times
Reply With Quote #5

Quote:
Originally Posted by Benoist3012 View Post
Well actually store time with cookies is easy. First you need to create the name
PHP Code:
Handle htimePlayed;
public 
void OnPluginStart()
{
    
hTimePlayed RegClientCookie("sm_time_played""Time played on the server"CookieAccess_Protected);
//CookieAccess_Protected this block anyone from modifying it
public OnClientDisconnect(client)
{
    if (!
IsValidClient(client)) return;
    
int time 0;
    
char oldtime[64];
    if (!
IsFakeClient(client) && AreClientCookiesCached(client))
    {
        
GetClientCookie(clienthTimePlayedoldtimesizeof(oldtime));
        
time StringToInt(oldtime);
        
time += TimePlayed[client]; //I let you create a timer and add up 1 each second
        
IntToString(timeoldtimesizeof(oldtime));
        
SetClientCookie(clienthTimePlayedoldtime);
    }

A little scrap of code for you
What do you mean in
PHP Code:
time += TimePlayed[client]; //I let you create a timer and add up 1 each second 
what timer? If you can just do it yourself on the way you are replying(why not .-.) So it would be perfect
__________________
SourcePawn, C# and C++ Programmer.

My plugin list

Last edited by TheUnderTaker; 08-06-2015 at 09:08.
TheUnderTaker is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 08-06-2015 , 09:29   Re: SQL or clientprefs - Store Times
Reply With Quote #6

Don't use clientprefs for things that are not client preferences.
__________________
asherkin is offline
TheUnderTaker
Senior Member
Join Date: Dec 2013
Location: Israel
Old 08-06-2015 , 09:39   Re: SQL or clientprefs - Store Times
Reply With Quote #7

Quote:
Originally Posted by asherkin View Post
Don't use clientprefs for things that are not client preferences.
I just want for my private vip plugin store times in sql not else... Can you help :-)?
__________________
SourcePawn, C# and C++ Programmer.

My plugin list

Last edited by TheUnderTaker; 08-06-2015 at 09:39.
TheUnderTaker is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 08-06-2015 , 18:44   Re: SQL or clientprefs - Store Times
Reply With Quote #8

SQL - Using databases (MySQL, SQLite).


Here's example get client time when he disconnect.
GetClientTime(client)



And here is just example plugin to save client data each time when he disconnect.
Plugin code is not quite optimized but you see how it works.

There is sm_test command which print in your chat your spended time on server.
Spoiler
__________________
Do not Private Message @me

Last edited by Bacardi; 08-06-2015 at 18:47.
Bacardi is offline
DarkDeviL
SourceMod Moderator
Join Date: Apr 2012
Old 08-06-2015 , 22:52   Re: SQL or clientprefs - Store Times
Reply With Quote #9

Quote:
Originally Posted by Bacardi View Post
And here is just example plugin to save client data each time when he disconnect.
Plugin code is not quite optimized but you see how it works.

There is sm_test command which print in your chat your spended time on server.
Spoiler
You did mention it was an example, and not quite optimized, etc...

However, I'd still suggest that people re-write it to use threaded queries before using it.
__________________
Mostly known as "DarkDeviL".

Dropbox FastDL: Public folder will no longer work after March 15, 2017!
For more info, see the [SRCDS Thread], or the [HLDS Thread].
DarkDeviL is offline
TheUnderTaker
Senior Member
Join Date: Dec 2013
Location: Israel
Old 08-07-2015 , 03:50   Re: SQL or clientprefs - Store Times
Reply With Quote #10

Quote:
Originally Posted by Bacardi View Post
SQL - Using databases (MySQL, SQLite).


Here's example get client time when he disconnect.
GetClientTime(client)



And here is just example plugin to save client data each time when he disconnect.
Plugin code is not quite optimized but you see how it works.

There is sm_test command which print in your chat your spended time on server.
Spoiler
Wow! Thank you very much! I will try it, Btw I made a countdown plugin, Do you know how to make for example 120 seconds to 02:00? And it will count? I mean it will show mins, hours, days, not only seconds.
__________________
SourcePawn, C# and C++ Programmer.

My plugin list
TheUnderTaker 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 23:35.


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