Raised This Month: $ Target: $400
 0% 

Help with nvault-find max value


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lis_16
Senior Member
Join Date: Feb 2008
Old 03-13-2011 , 16:24   Help with nvault-find max value
Reply With Quote #1

Can anyone write a code searching max value from whole nvault?

This is my save data function:

PHP Code:
public Save(id){
    new 
name[35]
    
get_user_name(id,name,34)
    new 
vaultdata[256];
    new 
vaultkey[64];
    
format(vaultkey,63,"%s-nik",name);
    
format(vaultdata,255,"%i#%i#",level[id], punkty[id]) 
    
nvault_set(g_Vault,vaultkey,vaultdata);
    

I want set +1 level to player who has the most punkty-value and reset all punkty-value to all keys, is that possible? This is a kind of xp mod but i want add +1 lvl to a player who have the most punkty collected in one day fe. At 24:00 find player who has the most punkty and add him +1 lvl, reset all punkty for all players. Next day they must collect punkty and at 24:00 again find player who has the most punkty and add him +1 lvl etc.
lis_16 is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 03-15-2011 , 09:13   Re: Help with nvault-find max value
Reply With Quote #2

Read the nvault and compare for the highest value.

https://forums.alliedmods.net/showthread.php?t=139584
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
lis_16
Senior Member
Join Date: Feb 2008
Old 03-15-2011 , 11:47   Re: Help with nvault-find max value
Reply With Quote #3

PHP Code:
public dodaj_levele(){
    new 
iPos szKey32 ] , szVal64 ], wartosc[33], maksimum=0dummy[33], pozycjaiTimeStamp
    
new iVault nvault_util_open("uciekinier");
    new 
iCount nvault_util_countiVault );
    for ( new 
iCurrent iCurrent <= iCount iCurrent++ )
    {
        
iPos nvault_util_readiVault iPos szKey charsmaxszKey ) , szVal charsmaxszVal ), iTimeStamp);
        
replace_all(szVal43"#"," ")
        
parse(szValdummy32wartosc32)
        new 
maksimum_czas=str_to_num(wartosc)
        if(
maksimum_czas>maksimum){
            
pozycja=iCurrent
            maksimum
=maksimum_czas
        
}
     }
    
nvault_util_closeiVault );


Is that ok? And another question. How can i reset all second part of value from a key? I mean:

PHP Code:
 format(vaultdata,255,"%i#%i#",level[id], punkty[id]) 
How to reset %i-punkty[id]
lis_16 is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 03-15-2011 , 16:51   Re: Help with nvault-find max value
Reply With Quote #4

Quote:
Originally Posted by lis_16 View Post
Is that ok?
Close enough, but pozycja is never used.

Quote:
Originally Posted by lis_16 View Post
And another question. How can i reset all second part of value from a key? I mean:

PHP Code:
 format(vaultdata,255,"%i#%i#",level[id], punkty[id]) 
How to reset %i-punkty[id]
Read the data, and format the vault data again but use 0 for that data instead of the real value.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
lis_16
Senior Member
Join Date: Feb 2008
Old 03-15-2011 , 17:49   Re: Help with nvault-find max value
Reply With Quote #5

But how can I walk through all entries in vault? Is it possible to use for or while? How to if yes.
lis_16 is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 03-15-2011 , 19:27   Re: Help with nvault-find max value
Reply With Quote #6

Quote:
Originally Posted by lis_16 View Post
But how can I walk through all entries in vault? Is it possible to use for or while? How to if yes.
Quote:
Originally Posted by Exolent[jNr] View Post
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
lis_16
Senior Member
Join Date: Feb 2008
Old 03-16-2011 , 06:25   Re: Help with nvault-find max value
Reply With Quote #7

I see now ;]

Is that correct?




PHP Code:
public plugin_init() {
    
g_Vault=nvault_open("uciekinier")
}

public 
dodaj_levele(){
    new 
iPos szKey32 ] , szVal64 ], wartosc[33], maksimum=0dummy[33], pozycjaiTimeStamp
    
new iVault nvault_util_open("uciekinier");
    new 
iCount nvault_util_countiVault );
    for ( new 
iCurrent iCurrent <= iCount iCurrent++ )
    {
        
iPos nvault_util_readiVault iPos szKey charsmaxszKey ) , szVal charsmaxszVal ), iTimeStamp);
        
replace_all(szVal43"#"," ")
        
parse(szValdummy32wartosc32)
        new 
maksimum_czas=str_to_num(wartosc)
        if(
maksimum_czas>maksimum){
            
pozycja=iCurrent
            maksimum
=maksimum_czas
        
}
     }
     
    for( new 
iCurrent iCurrent <= iCount iCurrent++ )
    {
        
iPos nvault_util_readiVault iPos szKey charsmaxszKey ) , szVal charsmaxszVal ), iTimeStamp);
        if(
pozycja==iCurrent){
            new 
lew[33]
            new 
vaultdata[256];
            new 
vaultkey[64];
            
replace_all(szVal43"#"," ")
            
parse(szVallew32wartosc32)
            
format(vaultkey,63,"%s",szKey);
            
format(vaultdata,255,"%i#0#",str_to_num(lew)+1
            
nvault_set(g_Vault,vaultkey,vaultdata);
        }
        else{
            new 
lew[33]
            new 
vaultdata[256];
            new 
vaultkey[64];
            
replace_all(szVal43"#"," ")
            
parse(szVallew32wartosc32)
            
format(vaultkey,63,"%s",szKey);
            
format(vaultdata,255,"%i#0#",str_to_num(lew)) 
            
nvault_set(g_Vault,vaultkey,vaultdata);
        }
    }

            
        
    
nvault_util_closeiVault );


lis_16 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 14:37.


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