AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help with nvault-find max value (https://forums.alliedmods.net/showthread.php?t=152772)

lis_16 03-13-2011 16:24

Help with nvault-find max value
 
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.

Exolent[jNr] 03-15-2011 09:13

Re: Help with nvault-find max value
 
Read the nvault and compare for the highest value.

https://forums.alliedmods.net/showthread.php?t=139584

lis_16 03-15-2011 11:47

Re: Help with nvault-find max value
 
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]

Exolent[jNr] 03-15-2011 16:51

Re: Help with nvault-find max value
 
Quote:

Originally Posted by lis_16 (Post 1433669)
Is that ok?

Close enough, but pozycja is never used.

Quote:

Originally Posted by lis_16 (Post 1433669)
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.

lis_16 03-15-2011 17:49

Re: Help with nvault-find max value
 
But how can I walk through all entries in vault? Is it possible to use for or while? How to if yes.

Emp` 03-15-2011 19:27

Re: Help with nvault-find max value
 
Quote:

Originally Posted by lis_16 (Post 1433849)
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] (Post 1433604)


lis_16 03-16-2011 06:25

Re: Help with nvault-find max value
 
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 );





All times are GMT -4. The time now is 14:37.

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