AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Get nVault Timestamp (https://forums.alliedmods.net/showthread.php?t=324373)

Shadows Adi 05-14-2020 09:38

Get nVault Timestamp
 
Hi,
Today I tried to get Timestamp from a nvault key.
Code:
PHP Code:

new iTimestamp szVal10 ], AuthID[33];
    
get_user_authid(idAuthIDcharsmax(AuthID))
        if(!
nvault_lookupg_Vault AuthIDszVal charsmaxszVal ) , iTimestamp )
        {
            
//do stuff
        
}
        else 
        {
            
client_print(idprint_team_default"You need to wait %02d hours until execute again!", (get_systime() - iTimestamp) );
            return 
PLUGIN_HANDLED;
        } 

This should get timeleft until the key got prune, but I get only this every second when I type the command to execute the code above:

PHP Code:

You need to wait 1 hours until execute again!
You need to wait 2 hours until execute again!
You need to wait 3 hours until execute again!
You need to wait 4 hours until execute again

I tried to use UnixTime Converter but nothing.

OciXCrom 05-14-2020 13:44

Re: Get nVault Timestamp
 
The timestamp is in seconds, not hours.
Show the code where you're writing/removing data to/from the vault.

Shadows Adi 05-14-2020 14:12

Re: Get nVault Timestamp
 
PHP Code:

public plugin_cfg()
{
   
g_Vault nvault_open("Data");
   if(
g_Vault == INVALID_HANDLE)
      
set_fail_state("Error opening nVault");
   
   
nvault_prune(g_Vault,0,get_systime() - ((60 60) * 24));
}

public 
plugin_end()
{
   
nvault_close(g_Vault);
}

public 
something(id)
{
        new 
iTimestamp szVal10 ], AuthID[33]
        
get_user_authid(idAuthIDcharsmax(AuthID))
        if(!
nvault_lookupg_Vault AuthIDszVal charsmaxszVal ) , iTimestamp ))
        {
            
nvault_setg_Vault AuthID"player_data" );
            
//do something
        
}
        else
        {
            
client_print(idprint_team_default"You need to wait %02d hours until execute again!", (get_systime() - iTimestamp) );
            return 
PLUGIN_HANDLED;
        }



Bugsy 05-14-2020 18:50

Re: Get nVault Timestamp
 
As OciXCrom told you, timestamps and get_systime() are in SECONDS.

Either do the math yourself to convert seconds to hours/minutes/seconds, or you can use the below with this include.

PHP Code:

new iTimestamp get_systime() - 198;
new 
iYears,iMonths,iDays,iHours,iMinutes,iSeconds;

timestamp_diffiTimestamp get_systime() , iYears,iMonths,iDays,iHours,iMinutes,iSeconds );    
server_print"Time Left: %d years, %d months, %d days, %d hours, %d minutes, %d seconds"iYears,iMonths,iDays,iHours,iMinutes,iSeconds ); 

Output
Code:


Time Left: 0 years, 0 months, 0 days, 0 hours, 3 minutes, 18 seconds



All times are GMT -4. The time now is 17:06.

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