Raised This Month: $ Target: $400
 0% 

Three parameter matrix - nvault saving


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 07-08-2014 , 13:16   Three parameter matrix - nvault saving
Reply With Quote #1

Okay guys, it's about an upgrade menu. I have a variable - Level, which contains three parameters - upgrade type, team to upgrade and index. Well, I have problems with saving it into a nvaul. Tha strange thing is, that the first parameter (the HP upgrade) is not saving... The others are okay, but the first one is not saving... Also I want to say, that in the second loop with the "a", there is an error, but it's working. And if I change it to "a = 0", the error disappears, but the whole saving is not working... And I'm like mindblowing here, I don't know why this problem appears. Here is all I someone would need to see the situation.
PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <nvault>

#define PLUGIN "X"
#define VERSION "1.0"
#define AUTHOR "Flicker"

new TheVault

enum _
:UpgradeInfo
{
    
HP,
    
Armor,
    
Grenades,
    
NoFallDamage,
    
Respawn,
    
CritDmg
}

enum _:Teams
{
    
UN,
    
T,
    
CT,
    
SPEC
}

new 
Level[UpgradeInfo][Teams][33]

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
TheVault nvault_open("SaveUpgrades")
}

public 
client_disconnect(id)
    
SaveData(id)
    
public 
client_connect(id)
    
LoadData(id)

public 
SaveData(id)
{
    new 
authID[35]
    
get_user_authid(idauthIDcharsmax(authID))
    
    new 
Data[256]
    for(new 
iaUpgradeInfoi++)
    {
        for(
aTeamsa++)
        {
            
num_to_str(Level[i][a][id], Datacharsmax(Data))
            
nvault_set(TheVaultauthIDData)
        }
    }
    
    return 
PLUGIN_CONTINUE
}
    
    
public 
LoadData(id)
{
    new 
authID[35]
    
get_user_authid(idauthIDcharsmax(authID))
    
    new 
Data[256], Levels[32]
    for(new 
iaUpgradeInfoi++)
    {
        for(
aTeamsa++)
        {
        
            
num_to_str(Level[i][a][id], Datacharsmax(Data))
            
nvault_get(TheVaultauthIDDatacharsmax(Data))
        
            
parse(DataLevelscharsmax(Levels))
        
            
Level[i][a][id] = str_to_num(Levels)
        }
    }
    
    return 
PLUGIN_CONTINUE
    

And here is the line with the error
PHP Code:
for(aTeamsa++) 
And (dafuq) if I change it to
PHP Code:
for(0Teamsa++) 
the error disappears, but it's not working...
Any help appereciated.
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 07-08-2014 , 14:38   Re: Three parameter matrix - nvault saving
Reply With Quote #2

You're saving everything with the same key. I doubt that will work at all.

Code:
    for(new i, a; i < UpgradeInfo; i++)     {         for(a ; a < Teams; a++)
Using this will also not work. "a" is created outside of the scope of the second for-loop. Because you're never setting it to 0 again the second for-loop will not run more than once.
Here's an example to show you more clearly:
Code:
    for ( new i, j ; i < 3 ; i++ ) {         server_print("i: %d", i);         for ( ; j < 3 ; j++ ) {             server_print("j: %d", j);         }     }
Code:
i: 0
  j: 0
  j: 1
  j: 2
i: 1
i: 2
As you can see, the j loop runs only once, because it's never reset meaning the statement "j < 3" will return false.



And why you are getting that expression has no effect:
Code:
for ( a ; a < Teams ; a++ ) {     // Your code }
You can translate this to something like this:
Code:
a while ( a < Teams ) {     // Your code     a++; }
And of course, that a looks lonely there. Assuming you would not need to reset the variable a, you could've used something like this:
Code:
for ( ; a < Teams ; a++ ) {     // Your code }
But that is not the case, so it's irrelevant.

I'm assuming you stripped a lot of code before you posted.
__________________

Last edited by Black Rose; 07-08-2014 at 14:45.
Black Rose is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 07-08-2014 , 14:43   Re: Three parameter matrix - nvault saving
Reply With Quote #3

I attached the full code. It's about an upgrade system. And the only thing left is saving the level variable. So I just need to save it for the two teams and the upgrade types. I understood what you are saying, but this what you mentioned is working. The strange thing is that the first parameter of the upgrade items' enum (the frist parameter of the Level variable - HP) is not saving. Like the first value of 'i' is not saving and I can't understand why...
Attached Files
File Type: sma Get Plugin or Get Source (An_GoldMode_Upgrades.sma - 625 views - 7.8 KB)
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
SpeeDeeR
Veteran Member
Join Date: Mar 2010
Location: Bulgaria
Old 07-08-2014 , 15:47   Re: Three parameter matrix - nvault saving
Reply With Quote #4

You can see how Exolent did it in his Hns xp mod. I'm assuming its the same thing.
SpeeDeeR 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 21:17.


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