AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   SQL or clientprefs - Store Times (https://forums.alliedmods.net/showthread.php?t=268029)

TheUnderTaker 08-03-2015 15:45

SQL or clientprefs - Store Times
 
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.

Benoist3012 08-03-2015 15:48

Re: SQL or clientprefs - Store Times
 
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.

TheUnderTaker 08-03-2015 15:50

Re: SQL or clientprefs - Store Times
 
Quote:

Originally Posted by Benoist3012 (Post 2328004)
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..

Benoist3012 08-03-2015 15:59

Re: SQL or clientprefs - Store Times
 
Quote:

Originally Posted by TheUnderTaker (Post 2328007)
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

TheUnderTaker 08-06-2015 09:05

Re: SQL or clientprefs - Store Times
 
Quote:

Originally Posted by Benoist3012 (Post 2328010)
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 :)

asherkin 08-06-2015 09:29

Re: SQL or clientprefs - Store Times
 
Don't use clientprefs for things that are not client preferences.

TheUnderTaker 08-06-2015 09:39

Re: SQL or clientprefs - Store Times
 
Quote:

Originally Posted by asherkin (Post 2329616)
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 :-)?

Bacardi 08-06-2015 18:44

Re: SQL or clientprefs - Store Times
 
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

DarkDeviL 08-06-2015 22:52

Re: SQL or clientprefs - Store Times
 
Quote:

Originally Posted by Bacardi (Post 2329806)
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.

TheUnderTaker 08-07-2015 03:50

Re: SQL or clientprefs - Store Times
 
Quote:

Originally Posted by Bacardi (Post 2329806)
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.


All times are GMT -4. The time now is 23:35.

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