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

nVault Tutorial


Post New Thread Reply   
 
Thread Tools Display Modes
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 02-11-2012 , 15:46   Re: nVault
Reply With Quote #31

Code:
/* Prunes a specific key in the vault if it is within the given timestampps  * This will not erase values set with pset  */ stock nvault_prune_key(vault, const key[], start, end) {     new timestamp;     if(nvault_lookup(vault, key, "", 0, timestamp) && timestamp > 0 && (start <= timestamp <= end)) {         nvault_remove(vault, key);         return 1;     }         return 0; }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Infernuz
Member
Join Date: May 2011
Old 02-16-2012 , 12:10   Re: nVault
Reply With Quote #32

What's the point of nvault_touch if it only updates timestamp? I would as well want it to update my data.

Do I have to first make a check if data exists and only then use nvault_set? (Finds first and replaces the data after)
Or does nvault_set do it automatically without creating a new record?

Nothing is mentioned if nvault_set updates or not.

Just interested.

Last edited by Infernuz; 02-16-2012 at 12:24. Reason: Correction
Infernuz is offline
Send a message via ICQ to Infernuz
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 02-16-2012 , 12:28   Re: nVault
Reply With Quote #33

Quote:
Originally Posted by Infernuz View Post
What's the point of nvault_touch if it only updates timestamp? I would as well want it to update my data.
Use nvault_set() to update your data and the timestamp will update, too.

Quote:
Originally Posted by Infernuz View Post
Do I have to first make a check if data exists and only then use nvault_set? (Finds first and replaces the data after)
Or does nvault_set do it automatically without creating a new record?

Nothing is mentioned if nvault_set updates or not.
Well the whole point of "keys" are that they are unique in the vault.
If it were to create new entries instead of updating, those keys would not be unique.
So the answer is: yes, nvault_set() updates the data if it already exists.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 02-18-2012 , 11:35   Re: nVault
Reply With Quote #34

Thanks for the stock exolent. However, how should I check if the days expired, and then prune that key for the user? A general pruning doesn't work, since I don't know how to do that with your stock. Right now I have this:

PHP Code:
        new szDeathKey[41]
        
        
formatex(szDeathKeycharsmax(szDeathKey), "%s_DEATH"g_szAuthID[id])
    
        
//check here the days expired, and if so, prune that key
        
nvault_prune_key(g_score_vaultszDeathKeyget_systime(), 86400 get_pcvar_num(amx_death_expire_days)) 
Is that right like that?
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-18-2012 , 12:41   Re: nVault
Reply With Quote #35

Quote:
Originally Posted by bibu View Post
Is there a function to prune only one key in a vault file? For example the scores in the example plugin.
There is a score key for every player so there will not only be one score key. If you are referring to deleting all players 'score' key then no, the native 'prune' function works only with the timestamp. You will need to use the nvault utility include and delete keys containing "score".
__________________
Bugsy is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 02-18-2012 , 13:07   Re: nVault
Reply With Quote #36

See my post in #34. It just only for one player and does work IMO.
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-18-2012 , 13:56   Re: nVault
Reply With Quote #37

Sorry about that bibu, I didn't see page 2 for some reason and that this has already been resolved. Exolents function will do just fine, the only thing I think you have wrong is the window of time for pruning entries. Correct me if I'm wrong, I'm a little rusty.

PHP Code:
nvault_prune_key(g_score_vaultszDeathKeyget_systime(), 86400 get_pcvar_num(amx_death_expire_days)) 
Start: get_sys_time() = Now
End: 86400 * days = Days to remove in seconds (which is days starting from 01/01/1970 or w\e).

Should be

Start: 0 (01/01/1970)
End: get_systime() - ( get_pcvar_num( amx_death_expire_days ) * 86400 ) ) (Now - X days)
__________________

Last edited by Bugsy; 02-18-2012 at 13:57.
Bugsy is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 02-18-2012 , 17:22   Re: nVault
Reply With Quote #38

Bugsy I am thinking abit wrong and couldn't really understand your explanation. Could you rephrase that?
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 02-18-2012 , 19:33   Re: nVault
Reply With Quote #39

Quote:
Originally Posted by bibu View Post
Could you rephrase that?
Change
PHP Code:
nvault_prune_key(g_score_vaultszDeathKeyget_systime(), 86400 get_pcvar_num(amx_death_expire_days)) 
to
PHP Code:
nvault_prune_key(g_score_vaultszDeathKey0get_systime() - (86400 get_pcvar_num(amx_death_expire_days))) 
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 02-18-2012 at 22:47.
Exolent[jNr] is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-18-2012 , 19:42   Re: nVault
Reply With Quote #40

Quote:
Originally Posted by Exolent[jNr] View Post
Change
PHP Code:
nvault_prune_key(g_score_vaultszDeathKeyget_systime(), 86400 get_pcvar_num(amx_death_expire_days)) 
to
PHP Code:
nvault_prune_key(g_score_vaultszDeathKey0get_systime() + (86400 get_pcvar_num(amx_death_expire_days))) 
That will delete all entries. start=0 with end=get_systime() would delete all; in addition you are adding excess days onto now which says delete everything from the start of time until 15 days from now. Change + to - and it is good, as I posted in #37.

Quote:
Originally Posted by bibu View Post
Bugsy I am thinking abit wrong and couldn't really understand your explanation. Could you rephrase that?
When you prune, you are deleting entries that have a time stamp that falls within Start and End range. So for start time you use 0 (beginning of Epoch time) and for the end date you use now minus the number of days for expired entries. A timestamp is the number of seconds that have elapsed since 01/01/70 (IIRC), so the lower the number, the older the time is from now. Suppose you wanted to delete items that are older than 15 days:

0 < 17 day old entry to delete < 15 days from now
0 < 1328148921(now minus 17 days) < 1328321721(now minus 15 days)

Here's some math:

Start = 0

Calculate End time value (Now - 15 days)
  • Now = 1329610846
  • 15 Days = 1296000
  • 1329610846 - 1296000 = 1328314846

Outdated entry example to delete (17 days old, Now - 17 days)
  • 17 Days = 1468800
  • 1329610846 - 1468800 = 1328142046

Delete this 17 day old entry since:
0(Start) < 1328142046(17 day old entry) < 1328314846(now - 15 days)

So what you want is this:
PHP Code:
nvault_prune_keyg_score_vault szDeathKey get_systime() - ( 86400 get_pcvar_numamx_death_expire_days ) ) ) 
__________________

Last edited by Bugsy; 02-18-2012 at 21:21.
Bugsy 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 03:46.


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