AlliedModders

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

bwgrubbs1 07-15-2007 22:38

nVault
 
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 07-16-2007 00:39

Re: nVault
 
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")     } }

P34nut 07-16-2007 04:33

Re: nVault
 
nvault_lookup will do that I guess

_Master_ 07-16-2007 06:43

Re: nVault
 
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...

bwgrubbs1 07-16-2007 12:06

Re: nVault
 
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)     } }

Pinatz 05-30-2009 06:53

Re: nVault
 
May somebody create a tutorial about Nvault and sorting in Nvault?

alan_el_more 05-30-2009 07:05

Re: nVault
 
http://forums.alliedmods.net/showthread.php?t=91503

Pinatz 05-30-2009 18:59

Re: nVault
 
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.

Bugsy 05-30-2009 22:02

Re: nVault
 
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()

fysiks 05-30-2009 22:23

Re: nVault
 
Quote:

Originally Posted by Pinatz (Post 838358)
rank of a specific entry

Apparently this is too vague because there is no "rank" of data in the "list".


All times are GMT -4. The time now is 21:31.

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