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

Played Time Counter ( The problem of saving )


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
BerkayF
Junior Member
Join Date: Jun 2020
Old 07-18-2022 , 17:06   Played Time Counter ( The problem of saving )
Reply With Quote #1

The Problem of Saving

I am Using nVault as the Database
But I can't register the information!
If you can help me, I'll be happy


PHP Code:
/*
| =============================
| Generated by Berk
| Made in Turkey
| Keep It Ready
| =============================
*/

#include <amxmodx>
#include <amxmisc>
#include <zombieplague>
#include <nvault>

#define PLUGIN "Played Timer"
#define VERSION "BK TEAM - 4.0"
#define AUTHOR "Berk"

new played_time_second[33]
new 
played_time_minute[33]
new 
played_time_hour[33]
new 
played_time_day[33]

new 
p_Vault

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
}

public 
plugin_cfg()
{
    
p_Vault nvault_open("played_time")

    if ( 
p_Vault == INVALID_HANDLE )
        
set_fail_state"Error opening played_time nVault, file does not exist!" )
}

public 
played_time(id)
{
    
// It Will Be 1 Minute
    
if(played_time_second[id] != 60)
    {
        
played_time_second[id]++
    }
    
    
// It's Been 1 Minute
    
if(played_time_second[id] == 60)
    {
        
played_time_second[id] = 0
        played_time_minute
[id]++
    }
    
    
// It Will Be 1 Hour
    
if(played_time_minute[id] == 60)
    {
        
played_time_minute[id] = 0
        played_time_hour
[id]++
    }
    
    
// It Will Be 1 Day
    
if(played_time_hour[id] == 24)
    {
        
played_time_hour[id] = 0
        played_time_day
[id]++
    }
}

public 
played_hud(id)
{
    if(
is_user_alive(id))
    
set_hudmessage(802551500.010.1900.51.00.50.5)
    
show_hudmessage(id"[ Played Time System ]^n| Day: %i^n| Hour: %i^n| Minute: %i^n| Second: %i^n[ %s ]"played_time_day[id], played_time_hour[id], played_time_minute[id], played_time_second[id], VERSION)
}

public 
played_msg(id)
{
    new 
name[18]
    
get_user_name(idname17)
    
client_print(0print_chat"[Play Time] Name: %s | D: %i | H: %i | M: %i | S: %i"nameplayed_time_day[id], played_time_hour[id], played_time_minute[id], played_time_second[id] )
}

public 
client_putinserver(id)
{
    
set_task(1.0"played_hud"id__"b")
    
set_task(1.0"played_time"id__"b")
    
set_task(8.0"played_msg"id)
}

#if AMXX_VERSION_NUM < 183
public client_disconnect(id)
#else 
public client_disconnected(id)
#endif
{
    
SavePlayed(id)
    
    
played_time_day[id] = 0
    played_time_hour
[id] = 0
    played_time_minute
[id] = 0
    played_time_second
[id] = 0
    remove_task
(id);


public 
client_connect(id)
{
    
LoadPlayed(id)
}

SavePlayed(id)
{
    new 
szAuth[33];
    new 
szKey[64];
    
    
get_user_authid(id szAuth charsmax(szAuth))
    
formatex(szKey 63 "%s-ID" szAuth)
    
    new 
szData[256]
        
    
formatex(szData 255 "%i#%i#%i#%i" played_time_second[id], played_time_minute[id], played_time_hour[id], played_time_day[id])
    
    
nvault_pset(p_Vault szKey szData)
}

LoadPlayed(id)
{
    new 
szAuth[33];
    new 
szKey[40];
    
    
get_user_authid(id szAuth charsmax(szAuth))
    
formatex(szKey 63 "%s-ID" szAuth)
    
    new 
szData[256];
    
    
formatex(szData 255 "%i#%i#%i#%i" played_time_second[id], played_time_minute[id], played_time_hour[id], played_time_day[id])
    
    
nvault_get(p_VaultszKeyszData255)
    
    
replace_all(szData 255"#"" ")
    new 
day[32], hour[32], minute[32], second[32]
    
parse(szDatasecond31minute31hour31day31)
    
played_time_day[id] = str_to_num(day)
    
played_time_hour[id] = str_to_num(hour)
    
played_time_minute[id] = str_to_num(minute)
    
played_time_second[id] = str_to_num(second)

This way Saving
Code:
VALVE_XASH_9343ca513ad227f9f00ff-ID0#0#0#0#
HTML Code:
VALVE_XASH What is?
Xash3D FWGS
BerkayF is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-18-2022 , 23:15   Re: Played Time Counter ( The problem of saving )
Reply With Quote #2

1. Is it tracking time correctly during a connection and only failing to remember time on re-connect?
2. If 1 is yes, did you do some debugging to ensure your parse() is working correctly to assign the correct day/hour/minute/second values into the variables?
3. You can simplify this by instead using a unix timestamps and deriving the weeks/days/minutes/etc.. See the below plugin I quickly put together.

PHP Code:

#include <amxmodx>
#include <nvault>

new const Version[] = "0.1";

enum PlayerData
{
    
AuthID35 ],
    
ConnectTS,
    
TotalTime
}

new 
g_pdDataMAX_PLAYERS ][ PlayerData ];
new 
g_Vault;

public 
plugin_init() 
{
    
register_plugin"Time Played" Version "bugsy" );
    
    
g_Vault nvault_open"timeVault" );
    
    
register_clcmd"say /time" "ShowTime" );
}

public 
plugin_end() 
{
    
nvault_closeg_Vault );
}

public 
client_authorizedid )
{
    new 
szTime10 ] , iTS;
    
    
get_user_authidid g_pdDataid ][ AuthID ] , charsmaxg_pdData[][ AuthID ] ) );
    
    
g_pdDataid ][ ConnectTS ] = get_systime();
    
g_pdDataid ][ TotalTime ] = 0;
    
    if ( 
nvault_lookupg_Vault g_pdDataid ][ AuthID ] , szTime charsmaxszTime ) , iTS ) )
    {
        
g_pdDataid ][ TotalTime ] = str_to_numszTime );
    }
}

#if AMXX_VERSION_NUM >= 190 
public client_disconnectedid )
#else
public client_disconnectid )
#endif
{
    new 
szTime10 ] , iTime iTS;
    
    if ( 
nvault_lookupg_Vault g_pdDataid ][ AuthID ] , szTime charsmaxszTime ) , iTS ) )
    {
        
iTime str_to_numszTime );
    }
    
    
num_to_str( ( get_systime() - g_pdDataid ][ ConnectTS ] ) + iTime szTime charsmaxszTime ) );
    
nvault_setg_Vault g_pdDataid ][ AuthID ] , szTime );
}

public 
ShowTimeid )
{
    new 
iWeeks iDays iHours iMinutes iSeconds;
    
    
ConvertTimeStampg_pdDataid ][ TotalTime ] + ( get_systime() - g_pdDataid ][ ConnectTS ] ) , iWeeks iDays iHours iMinutes iSeconds );
    
client_printid print_chat "* Time played: %d weeks, %d days, %d hours, %d minutes, %d seconds" iWeeks iDays iHours iMinutes iSeconds );
}

ConvertTimeStampiTimestamp , &iWeeks , &iDays , &iHours , &iMinutes , &iSeconds )
{
    if ( 
iTimestamp >= 604800 )
    {
        
iWeeks iTimestamp 604800;
        
iTimestamp -= ( iWeeks 604800 );
    }
    
    if ( 
iTimestamp >= 86400 )
    {
        
iDays iTimestamp 86400;
        
iTimestamp -= ( iDays 86400 );
    }
    
    if ( 
iTimestamp >= 3600 )
    {
        
iHours = ( iTimestamp 3600 );
        
iTimestamp -= ( iHours 3600 );
    }
    
    if ( 
iTimestamp >= 60 )
    {
        
iMinutes = ( iTimestamp 60 );
        
iTimestamp -= ( iMinutes 60 );
    }
    
    
iSeconds iTimestamp;

__________________
Bugsy is offline
BerkayF
Junior Member
Join Date: Jun 2020
Old 07-19-2022 , 06:20   Re: Played Time Counter ( The problem of saving )
Reply With Quote #3

Quote:
Originally Posted by Bugsy View Post
1. Is it tracking time correctly during a connection and only failing to remember time on re-connect?
2. If 1 is yes, did you do some debugging to ensure your parse() is working correctly to assign the correct day/hour/minute/second values into the variables?
3. You can simplify this by instead using a unix timestamps and deriving the weeks/days/minutes/etc.. See the below plugin I quickly put together.

PHP Code:

#include <amxmodx>
#include <nvault>

new const Version[] = "0.1";

enum PlayerData
{
    
AuthID35 ],
    
ConnectTS,
    
TotalTime
}

new 
g_pdDataMAX_PLAYERS ][ PlayerData ];
new 
g_Vault;

public 
plugin_init() 
{
    
register_plugin"Time Played" Version "bugsy" );
    
    
g_Vault nvault_open"timeVault" );
    
    
register_clcmd"say /time" "ShowTime" );
}

public 
plugin_end() 
{
    
nvault_closeg_Vault );
}

public 
client_authorizedid )
{
    new 
szTime10 ] , iTS;
    
    
get_user_authidid g_pdDataid ][ AuthID ] , charsmaxg_pdData[][ AuthID ] ) );
    
    
g_pdDataid ][ ConnectTS ] = get_systime();
    
g_pdDataid ][ TotalTime ] = 0;
    
    if ( 
nvault_lookupg_Vault g_pdDataid ][ AuthID ] , szTime charsmaxszTime ) , iTS ) )
    {
        
g_pdDataid ][ TotalTime ] = str_to_numszTime );
    }
}

#if AMXX_VERSION_NUM >= 190 
public client_disconnectedid )
#else
public client_disconnectid )
#endif
{
    new 
szTime10 ] , iTime iTS;
    
    if ( 
nvault_lookupg_Vault g_pdDataid ][ AuthID ] , szTime charsmaxszTime ) , iTS ) )
    {
        
iTime str_to_numszTime );
    }
    
    
num_to_str( ( get_systime() - g_pdDataid ][ ConnectTS ] ) + iTime szTime charsmaxszTime ) );
    
nvault_setg_Vault g_pdDataid ][ AuthID ] , szTime );
}

public 
ShowTimeid )
{
    new 
iWeeks iDays iHours iMinutes iSeconds;
    
    
ConvertTimeStampg_pdDataid ][ TotalTime ] + ( get_systime() - g_pdDataid ][ ConnectTS ] ) , iWeeks iDays iHours iMinutes iSeconds );
    
client_printid print_chat "* Time played: %d weeks, %d days, %d hours, %d minutes, %d seconds" iWeeks iDays iHours iMinutes iSeconds );
}

ConvertTimeStampiTimestamp , &iWeeks , &iDays , &iHours , &iMinutes , &iSeconds )
{
    if ( 
iTimestamp >= 604800 )
    {
        
iWeeks iTimestamp 604800;
        
iTimestamp -= ( iWeeks 604800 );
    }
    
    if ( 
iTimestamp >= 86400 )
    {
        
iDays iTimestamp 86400;
        
iTimestamp -= ( iDays 86400 );
    }
    
    if ( 
iTimestamp >= 3600 )
    {
        
iHours = ( iTimestamp 3600 );
        
iTimestamp -= ( iHours 3600 );
    }
    
    if ( 
iTimestamp >= 60 )
    {
        
iMinutes = ( iTimestamp 60 );
        
iTimestamp -= ( iMinutes 60 );
    }
    
    
iSeconds iTimestamp;


A perfect code
You are an expert pawn coder
You've written things that I can't think of
Thanks
BerkayF is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 07-19-2022 , 15:59   Re: Played Time Counter ( The problem of saving )
Reply With Quote #4

Check this: https://forums.alliedmods.net/showthread.php?t=336209
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.
Supremache 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:11.


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