Raised This Month: $ Target: $400
 0% 

nVault


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
bwgrubbs1
Senior Member
Join Date: Sep 2006
Old 07-15-2007 , 22:38   nVault
Reply With Quote #1

Is there a way to detect if someone already exists in an nVault and if they do to write over their old data...

Here is my example. I have a Top 10 on my server, people beat the map, bhop or kz in a certain time lets say

TOP 10 Climbers
# || name || time || checks saved || go checks used
1 || John || 3:16 || 5 || 20
2 || Sally || 3:18 || 9 || 5
3 || Paul || 4:00 || 0 || 0

Now lets say that Sally is jumping again...she beats her old time of 3:18 with a time of 3:05 and using no checks, is there a way to delete her old data from the nVault and update it with the new data so the top 10 reads

TOP 10 Climbers
# || name || time || checks saved || go checks used
1 || Sally || 3:05 || 0 || 0
2 || John || 3:16 || 5 || 20
3 || Paul || 4:00 || 0 || 0
bwgrubbs1 is offline
bwgrubbs1
Senior Member
Join Date: Sep 2006
Old 07-16-2007 , 00:39   Re: nVault
Reply With Quote #2

Srry also here is a look at code i am using for top 10

Code:
public topten_update(id) {     new szvault[64], szmap[32], kreedztime     get_mapname(szmap,32)     format(szvault,64,"bhop_%s",szmap)     new time = getusertime(id)     new vault = nvault_open(szvault) // Now we have to sort the new list :o     if(vault != -1) {         new szkey[8]         for(new i=1;i<=10;i++) {             new szreturn[128]             new arg1[32], arg2[8]             format(szkey,8,"%d",i)             nvault_get(vault,szkey,szreturn,128)             if(parse(szreturn,arg1,32,arg2,8) == 0 || getusertime(id) < str_to_num(arg2))             {                 if(getusertime(id) < str_to_num(arg2))                     nvault_remove(vault, szreturn)                 else {                     new sznew[128], szname[32]                     get_user_name(id,szname,32)                     format(sznew,128,"^"%s^" ^"%d^" ^"%d^" ^"%d^" ^"%d^"",szname,time,timer[id-1][TMR_CPSCNT],timer[id-1][TMR_GCSCNT],timer[id-1][TMR_BOOSTS])                     if(i < 10) {                         for(new x=10;x>i;x--) {                             new sztemp[128], sztempkey[8]                             format(sztempkey,8,"%d",x-1)                             nvault_get(vault,sztempkey,sztemp,128)                                                     if(!equal(sztemp,"")) {                                 format(sztempkey,8,"%d",x)                                 nvault_pset(vault,sztempkey,sztemp)                             }                         }                     }                     nvault_pset(vault,szkey,sznew)                                     if(i == 1)                         client_print(0,print_chat,"[KZ] Congratulations, %s has a new record !",szname)                                         break                 }             }         }         nvault_close(vault)     } }

Code:
public topten_show(id) {     new motd[2048]     new szvault[64], szmap[32]     get_mapname(szmap,32)     format(szvault,64,"bhop_%s",szmap)         new vault = nvault_open(szvault)     if(vault != -1) {         add(motd,2048,"<html><head><style>")         add(motd,2048,"body { background-color:#000000; font-family:Tahoma; font-size:10px; color:#FFFFFF; }")         add(motd,2048,".tabel { border-style:solid; border-width:1px; border-color:#FFFFFF; font-family:Tahoma; font-size:10px; color:#FFFFFF; }")         add(motd,2048,".header { background-color:#292929; font-family:Tahoma; font-size:10px; color:#FFFFFF; font-weight:800; }")         add(motd,2048,"</style></head><body>")         add(motd,2048,"<br><br><table border=0 cellspacing=0 cellpadding=1 width=90% align=center class=tabel>")                 add(motd,2048,"<tr><td class=header>#</td><td class=header>Name</td><td class=header>Time</td><td class=header>Check Points Saved</td><td class=header>Go checks Used</td><td class=header>Boosts Used</td></tr>")         new szkey[8]         for(new i=1;i<=10;i++) {             new szreturn[128]             format(szkey,8,"%d",i)             nvault_get(vault,szkey,szreturn,128)                         new arg1[32], arg2[8], arg3[8], arg4[8], arg5[8]             if(parse(szreturn,arg1,32,arg2,8,arg3,8,arg4,8,arg5,8) != 0) {                 new sztime[32]                 new imin, kreedztime = str_to_num(arg2)                 if((kreedztime / 60.0) >= 1) {                     imin = floatround(kreedztime / 60.0,floatround_floor)                     kreedztime -= (floatround(kreedztime / 60.0,floatround_floor) * 60)                 }                 format(sztime,32,"%d minutes and %d seconds",imin,kreedztime)                 add(motd,2048,"<tr><td>")                 add(motd,2048,szkey)                 add(motd,2048,"</td><td>")                 add(motd,2048,arg1)                 add(motd,2048,"</td><td>")                 add(motd,2048,sztime)                 add(motd,2048,"</td><td>")                 add(motd,2048,arg3)                 add(motd,2048,"</td><td>")                 add(motd,2048,arg4)                 add(motd,2048,"</td><td>")                 add(motd,2048,arg5)                 add(motd,2048,"</td></tr>")             }         }                 nvault_close(vault)                 add(motd,2048,"</table></body></html>")         show_motd(id,motd,"KZ TOP 10")     } }
bwgrubbs1 is offline
P34nut
AMX Mod X Beta Tester
Join Date: Feb 2006
Location: Netherlands
Old 07-16-2007 , 04:33   Re: nVault
Reply With Quote #3

nvault_lookup will do that I guess
__________________
All you need to change the world is one good lie and a river of blood
P34nut is offline
_Master_
Senior Member
Join Date: Dec 2006
Old 07-16-2007 , 06:43   Re: nVault
Reply With Quote #4

AFAIK nvault overwrites old data with the current value if the key is the same. Psets are also affected.
I could be wrong about this...
_Master_ is offline
bwgrubbs1
Senior Member
Join Date: Sep 2006
Old 07-16-2007 , 12:06   Re: nVault
Reply With Quote #5

Could you possibly show me this in action, because i have tried a lot of different combinations here, specifically in this area of the code.

Code:
public topten_update(id) {     new szvault[64], szmap[32], kreedztime     get_mapname(szmap,32)     format(szvault,64,"bhop_%s",szmap)     new time = getusertime(id)     new vault = nvault_open(szvault) // Now we have to sort the new list :o     if(vault != -1) {         new szkey[8]         for(new i=1;i<=10;i++) {             new szreturn[128]             new arg1[32], arg2[8]             format(szkey,8,"%d",i)             nvault_get(vault,szkey,szreturn,128)             if(parse(szreturn,arg1,32,arg2,8) == 0 || getusertime(id) < str_to_num(arg2))             {                 if(getusertime(id) < str_to_num(arg2)) // if their new time is better than time in vault                     nvault_remove(vault, szreturn) // trying to remove old data                 else { //Where do i incorporate nvault_lookup ???                     new sznew[128], szname[32]                     get_user_name(id,szname,32)                     format(sznew,128,"^"%s^" ^"%d^" ^"%d^" ^"%d^" ^"%d^"",szname,time,timer[id-1][TMR_CPSCNT],timer[id-1][TMR_GCSCNT],timer[id-1][TMR_BOOSTS])                     if(i < 10) {                         for(new x=10;x>i;x--) {                             new sztemp[128], sztempkey[8]                             format(sztempkey,8,"%d",x-1)                             nvault_get(vault,sztempkey,sztemp,128)                                                     if(!equal(sztemp,"")) {                                 format(sztempkey,8,"%d",x)                                 nvault_pset(vault,sztempkey,sztemp)                             }                         }                     }                     nvault_pset(vault,szkey,sznew)                                     if(i == 1)                         client_print(0,print_chat,"[KZ] Congratulations, %s has a new record !",szname)                                         break                 }             }         }         nvault_close(vault)     } }
bwgrubbs1 is offline
Pinatz
Member
Join Date: Dec 2008
Old 05-30-2009 , 06:53   Re: nVault
Reply With Quote #6

May somebody create a tutorial about Nvault and sorting in Nvault?
__________________
Pinatz is offline
alan_el_more
Veteran Member
Join Date: Jul 2008
Location: amxmodx-es.com
Old 05-30-2009 , 07:05   Re: nVault
Reply With Quote #7

http://forums.alliedmods.net/showthread.php?t=91503
__________________
alan_el_more is offline
Pinatz
Member
Join Date: Dec 2008
Old 05-30-2009 , 18:59   Re: nVault
Reply With Quote #8

Thanks for the link but there is nothing about how to sort a nvault-based list.
And I donīt know how to get the rank of a specific entry within the list.
__________________
Pinatz is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-30-2009 , 22:23   Re: nVault
Reply With Quote #9

Quote:
Originally Posted by Pinatz View Post
rank of a specific entry
Apparently this is too vague because there is no "rank" of data in the "list".
__________________
fysiks is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-30-2009 , 22:02   Re: nVault
Reply With Quote #10

nvault_lookup() returns true if data exists for the key. That is all you need to do to check if data exists.

PHP Code:
if ( nvault_lookupiVault "thekey" szData maxlen timestamp ) )
{
    
//data exists, overwrite if needed
}
else
{
    
//no data exists for specified key

The same is true for nvault_get()
__________________
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 21:31.


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