Raised This Month: $32 Target: $400
 8% 

Need some help with NVAULT


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
HBxander
Senior Member
Join Date: Jan 2011
Location: Behind you!
Old 11-14-2012 , 14:24   Need some help with NVAULT
Reply With Quote #1

Hey..

I got some problems with this code for my Ranking System, it should work with saving/loading function, but it just.. doesnt?

I've been trying like everything, but nothing's working..
I don't want MySQL, since I hate that, and I think nvault saving is better, but I just can't make it.

Heres my code:

PHP Code:
/* 
    Rank Mod for GamePark 
    
    Author: eNDex
    Decription: Ranking System for players ingame
    Version: 1.0
*/
#include < amxmodx >
#include < amxmisc >
#include < cstrike >
#include < nvault >
#include < nvault_util >
#include < colorchat >

#define PREFIX "^4[Ranking]^3"

#define NVAULT1_NAME "Rankingstats_test4"
#define NVAULT2_NAME "Rankingnames_test4"

new gKills 33 ]
new 
gDeaths 33 ]
new 
gSurvives 33 ]
new 
gSuicides 33 ]
new 
gPoint 33 ]

new 
gVaultgVaultNames
new gAuthID 33 ] [ 35 ]
new 
gHtml 3200 ]

new 
gCvarKillgCvarDeathgCvarSurvivegCvarSuicide
new CvarKillCvarDeathCvarSurviveCvarSuicide

const TOPRANKS 10
new gTopAuth 11 ] [ 35 ]
new 
gTopNames 11 ] [ 35 ]
new 
gTopPoints 11 

public 
plugin_init ( )
{
    
register_clcmd "say /rank""CmdSayRank" )
    
register_clcmd "say /top""CmdSayTop" )
    
register_clcmd "say /top10""CmdSayTop" )
    
register_clcmd "say /debug""CmdDebug" )
        
    
register_event "DeathMsg""DeathMsg""a" )
    
register_logevent "EventRoundEnd"2"1=Round_End" )
    
    
gVault nvault_open NVAULT1_NAME )
    
gVaultNames nvault_open NVAULT2_NAME )
    
    if ( 
gVault == INVALID_HANDLE )
        
set_fail_state "Vault1 returned Invalid Handle" )
    if ( 
gVaultNames == INVALID_HANDLE )
        
set_fail_state "Vault2 returned Invalid Handle" )
            
    
gCvarKill register_cvar "rank_kill""2" )
    
gCvarDeath register_cvar "rank_death""1" )
    
gCvarSurvive register_cvar "rank_survive""2" )
    
gCvarSuicide register_cvar "rank_suicide""2" )
    
    
CvarKill get_pcvar_num gCvarKill )
    
CvarDeath get_pcvar_num gCvarDeath )
    
CvarSurvive get_pcvar_num gCvarSurvive )
    
CvarSuicide get_pcvar_num gCvarSuicide )
    
    
CreateTop ( );
}

public 
CmdDebug id )
{
    
gPoint id ] += 100
    gKills 
id ] += 10
    gDeaths 
id ] += 5
    gSuicides 
id ] += 2
    gSurvives 
id ] += 1
    
    client_print 
idprint_chat"DEBUG" )
}

public 
plugin_end ( )
{
    
nvault_close gVault )
}

public 
client_authorized id )
{
    if ( !
is_user_bot id ) && !is_user_hltv id ) )
    {
        
get_user_authid idgAuthID id ], 31 )
        
        
Load id )
    }
    
}

public 
client_disconnect id )
{
    
Save id )
}

public 
DeathMsg ( )
{
    new 
killer read_data )
    new 
victim read_data )
    
    if ( 
victim != killer )
    {
        
gPoint killer ] += CvarKill
        gPoint 
victim ] -= CvarDeath
        gKills 
killer ] += 1
        gDeaths 
victim ] += 1
        
        Save 
killer )
        
Save victim )
    }
    else
    {
        
gPoint victim ] -= CvarSuicide
        gDeaths 
victim ] += 1
        
        Save 
victim )
    }
}

public 
EventRoundEnd ( )
{
    new 
hiderseekerhider_alive
    
    
for ( new 1<= get_maxplayers ( ); i++ )
    {
        if ( 
is_user_connected ) )
        {
            switch ( 
cs_get_user_team ) )
            {
                case 
CS_TEAM_CT:
                {
                    if ( !
seeker )
                    {
                        
seeker i
                    
}
                }
                case 
CS_TEAM_T:
                {
                    if ( !
hider )
                    {
                        
hider i
                        
                        
if ( !hider_alive && is_user_alive ) )
                        {
                            
hider_alive i
                        
}
                    }
                }
            }
            if ( 
seeker && hider && hider_alive )
            {
                break;
            }
        }
    }
    
    if ( !
hider || !seeker )
    {
        return;
    }
    
    new 
CsTeams:winner CS_TEAM_CT
    
    
if ( hider_alive 
    {
        
winner CS_TEAM_T
        
        
for ( new id 1id <= get_maxplayers ( ); id++ )
        {
            if ( 
is_user_alive id ) && cs_get_user_team id ) == winner )
            {
                
gPoint id ] += CvarSurvive
                gSurvives 
id ] += 1
                
                Save 
id )
            }
        }
    }
}

Load id )
{
    static 
data 256 ], timestamp
    
if ( nvault_lookup gVaultgAuthID id ], datasizeof data ) - 1timestamp ) )
    {
        
LoadData iddata )
        return;
    }
    else
    {
        
gPoint id ] = 1000
        gKills 
id ] = 0
        gDeaths 
id ] = 0
        gSurvives 
id ] = 0
        gSuicides 
id ] = 0
    
}
}

LoadData iddata 256 ] )
{
    static 
num ]
    
    
strbreak datanumsizeof num ) - 1datasizeof data ) - )
    
gPoint id ] = str_to_num num )
    
    
strbreak datanumsizeof num ) - 1datasizeof data ) - )
    
gKills id ] = str_to_num num )
    
    
strbreak datanumsizeof num ) - 1datasizeof data ) - )
    
gDeaths id ] = str_to_num num )
    
    
strbreak datanumsizeof num ) - 1datasizeof data ) - )
    
gSurvives id ] = str_to_num num )
    
    
strbreak datanumsizeof num ) - 1datasizeof data ) - )
    
gSuicides id ] = str_to_num num )
}

Save id 
{
    if ( 
is_user_bot id ) )
        return;
    
    static 
data 256 ]
    new 
len formatex datasizeof data ) - 1"%i"gPoint id ] )
    
    
len += formatex data len ], sizeof data ) - len 1" %i"gKills id ] )
    
    
len += formatex data len ], sizeof data ) - len 1" %i"gDeaths id ] )
    
    
len += formatex data len ], sizeof data ) - len 1" %i"gSurvives id ] )
    
    
len += formatex data len ], sizeof data ) - len 1" %i"gSuicides id ] )
    
    
nvault_set gVaultgAuthID id ], data )
    
    new 
szName 32 ], szNameTemp 32 ]
    
get_user_name idszNamecharsmax szName ) )
    
formatex szNameTempcharsmax szNameTemp ), "%s"szName )
    
    
nvault_set gVaultNamesgAuthID id ], szNameTemp )
}

public 
CreateTop ( ) 
{
    new Array:
aNames, Array:aAuths, Array:aPoint
    
new iTotal SortTop aNamesaAuthsaPoint )
    
    new 
szName 156 ], szAuth 156 ]
    
    for ( new 
i010i++ )
    {
        if ( 
iTotal )
        {
            
ArrayGetString aNamesiszNamecharsmax szName ) )
            
ArrayGetString aAuthsiszAuthcharsmax szAuth ) )
            
replace_all szNamecharsmax szName ), "&""&amp;" )
            
replace_all szNamecharsmax szName ), "<""&lt;" )
            
replace_all szNamecharsmax szName ), ">""&gt;" )
            
formatex gTopNames ], charsmax gTopNames [ ] ), "%s"szName )
            
formatex gTopAuth ], charsmax gTopAuth [ ] ), "%s"szAuth )
            
            
gTopPoints ] = ArrayGetCell aPoint)
        }
    }
    
ArrayDestroy aNames )
    
ArrayDestroy aAuths )
    
ArrayDestroy aPoint )
    
    return 
PLUGIN_HANDLED
}

SortTop ( &Array:aNames, &Array:aAuths, &Array:aPoints )
{
    
aNames ArrayCreate 32 )
    
aAuths ArrayCreate 35 )
    
aPoints ArrayCreate )
    
    new 
hVault nvault_util_open NVAULT1_NAME )
    new 
gCount nvault_util_count hVault )
    new 
iPosszSteamID 35 ], szPoints 11 ], iTimeStampszName 32 ]
    
    for ( new 
0gCounti++ )
    {
        
iPos nvault_util_read hVaultiPosszSteamIDcharsmax szSteamID ), szPointscharsmax szPoints ), iTimeStamp )
        
        
nvault_get gVaultNamesszSteamIDszNamecharsmax szName ) )
        
        
ArrayPushString aNamesszName )
        
ArrayPushString aAuthsszSteamID )
        
ArrayPushCell aPointsstr_to_num szPoints ) )
    }
    
    
nvault_util_close hVault )
    
    new 
iPoints
    
    
for ( new 0j< ( gCount ); i++ )
    {
        
iPoints ArrayGetCell aPoints)
        
        for ( 
1gCountj++ )
        {
            if ( 
iPoints ArrayGetCell aPoints) )
            {
                
ArraySwap aNamesi)
                
ArraySwap aAuthsi)
                
ArraySwap aPointsi)
                
                
i--;
                
                break;
            }
        }
    }
    
    return 
gCount
}

public 
CmdSayRank id )
{
    new Array:
aNames, Array:aAuths, Array:aPoints
    
new iTotal SortTop aNamesaAuthsaPoints )
    
    new 
gAuthID2 35 ], i
    
    
for ( 0iTotali++ )
    {
        
ArrayGetString aAuthsigAuthID2charsmax gAuthID2 ) )
        if ( 
equal gAuthID id ], gAuthID2 ) )
        {
            new 
szData 256 ], szPoints 11 ]
            
nvault_get gVaultgAuthID2szDatacharsmax szData ) )
                
            
parse szDataszPointscharsmax szPoints ) )
                
            
ColorChat idGREY"^4[Ranking]^3 Your rank is^4 %i^3 of^4 %i^3 with^4 %i^3 points^4 %i^3 kills(^4+%i^3)^4 %i^3 deaths(^4-%i^3)^4 %i^3 survives(^4+%i^3) and^4 %i^3 suicides(^4-%i^3)", ( ), iTotalstr_to_num szPoints ), gKills id ], (gKills id ] * CvarKill), gDeaths id ], (gDeaths id ] * CvarDeath ), gSurvives id ], (gSurvives id ] * CvarSurvive), gSuicides id ], (gSuicides id ] * CvarSuicide) )
        }
    }
    
    
ArrayDestroy aNames )
    
ArrayDestroy aAuths )
    
ArrayDestroy aPoints )
}

public 
CmdSayTop id )
{
    new 
iLen
    
    iLen 
formatex gHtml iLen ], charsmax gHtml ) - iLen"<STYLE>body{background:#212121;color:#d1d1d1;font-family:Arial}table{width:100%%;font-size:11px}</STYLE><table cellpadding=1 cellspacing=1 border=0>" )
    
iLen += formatex gHtml iLen ], charsmax gHtml ) - iLen"<tr bgcolor=#333333><th width=5%%><align=left font color=white> Rank <th width=10%%> Nick <th width=10%%> Steamid <th width=10%%> Total points" )
    
    for ( new 
0TOPRANKSi++ )
    {
        if ( 
== || == || == || == || == )
        {
            
iLen += formatex gHtml iLen ], charsmax gHtml ) - iLen,  "<tr align=left%s><td align=left><font color=white> %i. <td> %s <td> %s <td> %i"" bgcolor=#2b5b95", ( ), gTopNames ], gTopAuth ], gTopPoints ] )
        }
        else
        {
            
iLen += formatex gHtml iLen ], charsmax gHtml ) - iLen"<tr align=left%s><td align=left><font color=white> %i. <td> %s <td> %s <td> %i"" bgcolor=#333333", ( ), gTopNames ], gTopAuth ], gTopPoints ] )
        }
    }
    
    
iLen += formatex gHtml iLen ], charsmax gHtml ) - iLen"</table></body>" )
    
    
show_motd idgHtml"GamePark Ranking by eNDex" )
    
    return 
PLUGIN_HANDLED

__________________
Selling:

- PointMod for Hide And Seek - $20
- Private BlockMaker with Weapon Block And More - $50
- Achievements ( FFA GamePlay ) - $25

PM Me about Private Work!

Last edited by HBxander; 11-14-2012 at 14:25.
HBxander is offline
Torge
Veteran Member
Join Date: Oct 2011
Old 11-14-2012 , 14:33   Re: Need some help with NVAULT
Reply With Quote #2

Use FVault instead of nvault.
Torge is offline
HBxander
Senior Member
Join Date: Jan 2011
Location: Behind you!
Old 11-15-2012 , 09:38   Re: Need some help with NVAULT
Reply With Quote #3

Quote:
Originally Posted by Torge View Post
Use FVault instead of nvault.
The guides I found says that You can't use FVault for strings?

But I don't know, I've never used FVault, a guide would be great (:
__________________
Selling:

- PointMod for Hide And Seek - $20
- Private BlockMaker with Weapon Block And More - $50
- Achievements ( FFA GamePlay ) - $25

PM Me about Private Work!
HBxander is offline
simanovich
AlliedModders Donor
Join Date: Jun 2012
Location: Israel
Old 11-15-2012 , 16:54   Re: Need some help with NVAULT
Reply With Quote #4

fvault is better

I don't think that fvault doen't support strings
__________________
simanovich is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 11-15-2012 , 18:24   Re: Need some help with NVAULT
Reply With Quote #5

It works for me. I recommend using sql even if you hate it.
If you don't understand what is going on in your plugin, then why don't you check it like this:
PHP Code:
Load id )
{
    static 
data 256 ], timestamp
    
if ( nvault_lookup gVaultgAuthID id ], datasizeof data ) - 1timestamp ) )
    {
        
// DEBUG
        
new name[32]
        
get_user_name(idname31)
        
log_amx("Load %s: %s"namedata)
        
LoadData iddata )
        
log_amx("Loaded %s: %d %d %d %d %d"namegPoint id ], gKills id ], gDeaths id ], gSurvives id ], gSuicides id ])
        return;
    }
    else
    {
        
gPoint id ] = 1000
        gKills 
id ] = 0
        gDeaths 
id ] = 0
        gSurvives 
id ] = 0
        gSuicides 
id ] = 0
        
// DEBUG
        
new name[32]
        
get_user_name(idname31)
        
log_amx("Setting default %s: %d %d %d %d %d"namegPoint id ], gKills id ], gDeaths id ], gSurvives id ], gSuicides id ])
    }
}

Save id 
{
    
//code...
    
    
nvault_set gVaultgAuthID id ], data )
    
// DEBUG
    
new name[32]
    
get_user_name(idname31)
    
log_amx("Save %s: %s"namedata)
    
    
//code...

__________________
Impossible is Nothing

Last edited by Sylwester; 11-15-2012 at 18:25.
Sylwester is offline
HBxander
Senior Member
Join Date: Jan 2011
Location: Behind you!
Old 11-16-2012 , 09:55   Re: Need some help with NVAULT
Reply With Quote #6

Quote:
Originally Posted by Sylwester View Post
It works for me. I recommend using sql even if you hate it.
If you don't understand what is going on in your plugin, then why don't you check it like this:
PHP Code:
Load id )
{
    static 
data 256 ], timestamp
    
if ( nvault_lookup gVaultgAuthID id ], datasizeof data ) - 1timestamp ) )
    {
        
// DEBUG
        
new name[32]
        
get_user_name(idname31)
        
log_amx("Load %s: %s"namedata)
        
LoadData iddata )
        
log_amx("Loaded %s: %d %d %d %d %d"namegPoint id ], gKills id ], gDeaths id ], gSurvives id ], gSuicides id ])
        return;
    }
    else
    {
        
gPoint id ] = 1000
        gKills 
id ] = 0
        gDeaths 
id ] = 0
        gSurvives 
id ] = 0
        gSuicides 
id ] = 0
        
// DEBUG
        
new name[32]
        
get_user_name(idname31)
        
log_amx("Setting default %s: %d %d %d %d %d"namegPoint id ], gKills id ], gDeaths id ], gSurvives id ], gSuicides id ])
    }
}

Save id 
{
    
//code...
    
    
nvault_set gVaultgAuthID id ], data )
    
// DEBUG
    
new name[32]
    
get_user_name(idname31)
    
log_amx("Save %s: %s"namedata)
    
    
//code...

Could you maybe edit my code, so it's with MySQL then? - You are a bit better than I am I guess, so it'll be great if you could help me..
__________________
Selling:

- PointMod for Hide And Seek - $20
- Private BlockMaker with Weapon Block And More - $50
- Achievements ( FFA GamePlay ) - $25

PM Me about Private Work!
HBxander is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 11-16-2012 , 17:36   Re: Need some help with NVAULT
Reply With Quote #7

If you like the nVault style of coding, use this: http://forums.alliedmods.net/showthread.php?t=146849

Then you don't have to deal with all the queries yourself.
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 11-16-2012 , 18:18   Re: Need some help with NVAULT
Reply With Quote #8

sql vault is not using threaded queries...
__________________
Impossible is Nothing
Sylwester 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 07:50.


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