AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   nVault won save, Please help :) (https://forums.alliedmods.net/showthread.php?t=92271)

JProReTaRD 05-12-2009 16:11

nVault won save, Please help :)
 
Hi, I followed a guide to nVault, but I can't seem to get it to save.
I checked the vault, but its empty.
I would really appreciate some help or guidance :)

These are the nVault functions in my plugin.
PHP Code:

public plugin_cfg()
{
    
//Open our vault and have g_Vault store the handle.
    
g_Vault nvault_open"hns-xp-mod" );
}

public 
plugin_end()
{
    
//Close the vault when the plugin ends (map change\server shutdown\restart)
    
nvault_closeg_Vault );
}

public 
client_authorized(id)
{
    
//Get the connecting users authid and store it in our global string array so it
    //will not need to be retrieved every time we want to do an nvault transaction.
    
get_user_authidid g_szAuthID[id] , 34 );
}

public 
SaveXP(id)
{
    
//Save a single item into the value of the entry.
    //Example: STEAM_0:0:1234 16000

    
new szXP[7];
    new 
szLevel[7];
    new 
szKey[40];

    
formatexszKey 39 "%s-%i-XP" g_szAuthID[id], PlayerClass[id] );
    
formatexszXP "%d" PlayerXP[id] );
    
    
nvault_setg_Vault ,szKey szXP );
    
    
formatexszKey 39 "%s-%i-Level" g_szAuthID[id], PlayerClass[id] );
    
formatexszLevel "%d" PlayerLevel[id] );
    
    
nvault_setg_Vault ,szKey szXP );

    
client_printid print_chat "* Your money was saved to vault" );
}

public 
LoadXP(id)
{
    new 
szKey[40];
    
formatexszKey 39 "%s-%i-XP" g_szAuthID[id], PlayerClass[id] );
    
PlayerXP[id] = nvault_getg_Vault szKey );
    
    
formatexszKey 39 "%s-%i-Level" g_szAuthID[id], PlayerClass[id] );
    
PlayerLevel[id] = nvault_getg_Vault szKey );

    
client_printid print_chat "* Your XP: %d and Level: %i was loaded." PlayerXP[id], PlayerLevel[id] );


Full Code:
PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fun>
#include <nvault>

#define CLASS_NOTHING 0
#define CLASS_JUMPER 1
#define CLASS_BHOPPER 2
#define CLASS_CHOPPER 3
#define CLASS_NOOB 4
// Etc... 
// Note: I made a "nothing" Jumper. This is the class that all new people will automaticly get.

#define MAXCLASSES 5
#define MAXLEVELS 15
// I set MAXCLASSES to 5, since we have 5 classes 

new PlayerClass[33];
new 
PlayerXP[33];
new 
PlayerLevel[33];
new 
g_Vault;            //Global var to hold our vault handle
new g_szAuthID[33][35];        //Global array to store auth ids of players

new const CLASSES[MAXCLASSES][] = {
     
"None",
     
"Jumper",
     
"BHopper",
     
"CHopper",
     
"Noob" 
}

new 
msgtext;

new const 
LEVELS[MAXLEVELS] = {
    
90,
    
180,
    
300,
    
450,
    
700,
    
1200,
    
1800,
    
2800,
    
4100,
    
5200,
    
6000,
    
6800,
    
8200,
    
10200,
    
12000
}; // Levels

public plugin_init() {
     
register_plugin("HNS - XP""1.0""By [JPro] ReTaRD [ToY]");
     
//I'll create a on/off cvar for the mod... You dont have to add this.
     
register_cvar("sv_hnsxpmod""1");
     
//Now we register the DeathMsg event. This is where we can add XP when you kill somebody.
     
register_event("DeathMsg""DeathMsg""a");
     
//Note that i registered it as "a"; global event
     //Now we register a "XP Per Kill" cvar...
     //Now I made 20 xp per kill.
     
register_cvar("xp_per_kill""15");
     
//Lets register a SaveXP toggle cvar.
     
register_cvar("SaveXP""1");
     
//Lets register a menu to choose Jumper with...
     
register_menucmd(register_menuid("menu_ChooseJumper"),1023,"DoChooseJumper");
     
//ResetHUD event.(Check if user has no class)
     
register_event("ResetHUD""ShowHUD""be");
     
//Something for ShowHUD... Will explain later.
     
msgtext get_user_msgid("StatusText");
     
//Lets make a "Change Jumper" cmd for players.
     //I just lead it to the change Jumper menu.
     //Ill get back to the menu later.
     
register_clcmd("/changeJumper""ChooseJumper");
     
register_clcmd("say /changeJumper""ChooseJumper");
     
register_clcmd("say_team /changeJumper""ChooseJumper");
}

public 
plugin_cfg()
{
    
//Open our vault and have g_Vault store the handle.
    
g_Vault nvault_open"hns-xp-mod" );
}

public 
plugin_end()
{
    
//Close the vault when the plugin ends (map change\server shutdown\restart)
    
nvault_closeg_Vault );
}

public 
client_authorized(id)
{
    
//Get the connecting users authid and store it in our global string array so it
    //will not need to be retrieved every time we want to do an nvault transaction.
    
get_user_authidid g_szAuthID[id] , 34 );
}

public 
SaveXP(id)
{
    
//Save a single item into the value of the entry.
    //Example: STEAM_0:0:1234 16000

    
new szXP[7];
    new 
szLevel[7];
    new 
szKey[40];

    
formatexszKey 39 "%s-%i-XP" g_szAuthID[id], PlayerClass[id] );
    
formatexszXP "%d" PlayerXP[id] );
    
    
nvault_setg_Vault ,szKey szXP );
    
    
formatexszKey 39 "%s-%i-Level" g_szAuthID[id], PlayerClass[id] );
    
formatexszLevel "%d" PlayerLevel[id] );
    
    
nvault_setg_Vault ,szKey szXP );

    
client_printid print_chat "* Your money was saved to vault" );
}

public 
LoadXP(id)
{
    new 
szKey[40];
    
formatexszKey 39 "%s-%i-XP" g_szAuthID[id], PlayerClass[id] );
    
PlayerXP[id] = nvault_getg_Vault szKey );
    
    
formatexszKey 39 "%s-%i-Level" g_szAuthID[id], PlayerClass[id] );
    
PlayerLevel[id] = nvault_getg_Vault szKey );

    
client_printid print_chat "* Your XP: %d and Level: %i was loaded." PlayerXP[id], PlayerLevel[id] );
}

public 
client_connect(id)
{
    
//Only load their XP if our SaveXP cvar is 1.
    
if(get_cvar_num("SaveXP") == 1) {
       
         
LoadXP(id);

         
//Add a message if you want....
         
client_print(idprint_chat"[HNS XP Mod] XP Loaded!");
         
client_print(idprint_chat"[HNS XP Mod] You are a %s with level %s and %s XP"PlayerClass[id], PlayerLevel[id], PlayerXP[id]);
    }
}
 
public 
client_disconnect(id)
{
    
//Only save their XP if our SaveXP cvar is 1.
    
if(get_cvar_num("SaveXP") == 1) {
    
         
SaveXP(id);
    }
}
   
//Call it whatever you want...
public ChooseJumper(id)
{
    
SaveXP(id);
    new 
menu[192];
    
    
//Add keys for how many classes you have + exit key.
    
new keys MENU_KEY_0|MENU_KEY_1|MENU_KEY_2|MENU_KEY_3;

    
    
//Here we write the menu options..
    
format(menu191"HNS XP Mod: Choose a Jumper^n^n1. Jumper^n2. BHopper^n3. CHopper^n4. Noob^n^n0. Exit");
    
    
//We created a menu in plugin_init() and now we make the plugin know that its this menu it has to show.
    
show_menu(idkeysmenu, -1"menu_ChooseJumper");
    
    return 
PLUGIN_CONTINUE;
}
  
public 
DoChooseJumper(idkey)
{
    
// Remeber that the keys starts on 0...
    
if(key == 0) {
       
         
//Lets check if the player allready has Jumper...
         
if(PlayerClass[id] == CLASS_JUMPER) {
         
              
//Make a message here if you want...
              
client_print(idprint_chat"[HNS XP Mod] You are already a Jumper! Choose something else!");
              
              
//Open the menu again...
              
ChooseJumper(id);
              
              
//Exit...
              
return PLUGIN_HANDLED;
         }        

         
//Now, if the player didnt have Jumper allready, we'll set his class to jumper.
         
PlayerClass[id] = CLASS_JUMPER;
         
         
//Make a message if you want...
         
client_print(idprint_chat"[HNS XP Mod] You are now a Jumper!");
    }        
    
    
//Im doing the same on all other buttons...
         
    
if(key == 1) {
         
         if(
PlayerClass[id] == CLASS_BHOPPER) {
              
              
client_print(idprint_chat"[HNS XP Mod] You are already a BHopper! Choose something else!");
              
ChooseJumper(id);
              return 
PLUGIN_HANDLED;
         }
                   
         
PlayerClass[id] = CLASS_BHOPPER
         client_print
(idprint_chat"[HNS XP Mod] You are now a BHopper!");
    }
    
    if(
key == 2) {
         
         if(
PlayerClass[id] == CLASS_CHOPPER) {
              
              
client_print(idprint_chat"[HNS XP Mod] You are already a CHopper! Choose something else!");
              
ChooseJumper(id);
              return 
PLUGIN_HANDLED;
         }
                   
         
PlayerClass[id] = CLASS_CHOPPER;
         
client_print(idprint_chat"[HNS XP Mod] You are now a CHopper!");
    }    

    if(
key == 3) {
         
         if(
PlayerClass[id] == CLASS_NOOB) {
              
              
client_print(idprint_chat"[HNS XP Mod] You are already a Noob! Choose something else!");
              
ChooseJumper(id);
              return 
PLUGIN_HANDLED;
         }
                   
         
PlayerClass[id] = CLASS_NOOB;
         
client_print(idprint_chat"[HNS XP Mod] You are now a Noob!");
    }
      
    
//Show new HUD after picking class.
    //Ill get back to this later...
    
LoadXP(id);
    
ShowHUD(id);
    return 
PLUGIN_HANDLED;
}

public 
ResetHUD(id) {
     
//Lets check if "sv_hnsxpmod" is on. If its off, we'll stop the function.
     
if(get_cvar_num("sv_hnsxpmod") == 0) {
    return 
PLUGIN_HANDLED;
     }
     
//Lets check if the player has no Jumper.
     
if(PlayerClass[id] == CLASS_NOTHING) {
    
//If the player doesnt have a Jumper;
    //Open the choose Jumper menu for him.
    
ChooseJumper(id);
    return 
PLUGIN_HANDLED;
     }
     return 
PLUGIN_HANDLED;
}
  
public 
DeathMsg() //Note that i only had (), and not (id)
{
    
//Lets check if "sv_hnsxpmod" is on. If its off, we'll stop the function.
    
if(get_cvar_num("sv_hnsxpmod") == 0) {
         return 
PLUGIN_HANDLED;
    }
    
    
//Now we create a "attacker" varriable. So the XP will be given to the killer, and not all players on the server.
    
new attacker read_data(1);
    
    
//Now the plugin will check if the attacker doesnt have a class, and if he doesnt, the function will stop.
    
if(PlayerClass[attacker] == CLASS_NOTHING) {
         return 
PLUGIN_HANDLED;
    }
    
    
//Now lets see if the attacker allready has level 6, and doesnt need more XP, and if he is, stop the function.
    //You can remove this if you want, and let the player get as much XP he want. But we wont get more than level 6 anyway.
    
if(PlayerLevel[attacker] == MAXLEVELS) {
         return 
PLUGIN_HANDLED;
    }
    
    
//Now we can add XP to the attacker.        
    
PlayerXP[attacker] += get_cvar_num("XP_per_kill"); //Add the amout of XP you have on the "XP_per_kill" cvar.
    
    //Now we check if the attacker has enough XP for a new level. And if he has, we add it.
    
if(PlayerXP[attacker] >= LEVELS[PlayerLevel[attacker]]) {
     
         
//Add his level...
         
PlayerLevel[attacker] += 1;
         
         
//Now you can make a "congratualtions" message if you want...
         
client_print(attackerprint_chat"[HNS XP Mod] Congratulations! You are now level %i!"PlayerLevel[attacker]);
         
         
//Lets save his XP every time he gets a level incase the server crashes or something. So they wont loose it all.
         
if(get_cvar_num("SaveXP") == 1) {
 
              
SaveXP(attacker);
         }


         
//Show His New Level on the HUD message.
         //Ill get back to this later...
         
ShowHUD(attacker);
    }   
    
    
//Show new HUD if you didnt get level too. (To show the new XP)
    //Ill get back to this later...
    
ShowHUD(attacker);
    
    return 
PLUGIN_CONTINUE;
}
  
public 
ShowHUD(id)    

    new 
HUD[51];
    
    
//This is the stuff that will actually show in game.
    
format(HUD50"[%s]Level: %i XP: %i Next level: %i say /changeJumper to change Jumper class"CLASSES[PlayerClass[id]], PlayerLevel[id], PlayerXP[id], LEVELS[PlayerLevel[id]]);

    
message_begin(MSG_ONEmsgtext, {0,0,0}, id);
    
write_byte(0);
    
write_string(HUD);
    
message_end();
    return;



Dr.G 05-12-2009 16:57

Re: nVault won save, Please help :)
 
når jeg har brugt nvault åbner jeg og lukker den i hver funktion.

quick example idk if it will help ya:

PHP Code:

public load_noscope_killsindex )
{
 new 
Vault nvault_opentop_kills_vault )
 new 
Key64 ], Value64 ], Steam32 ]
 
 
get_user_authidindexSteamsizeof Steam 1  )
 
formatexKeysizeof Key 1"%s-%s:"Steamtop_kills_vault )
 
 
nvault_getVaultKeyValuesizeof Value )
 
nvault_closeVault )
 
 
g_noscope_counterindex ] = str_to_numValue )



Bugsy 05-12-2009 19:29

Re: nVault won save, Please help :)
 
Quote:

Originally Posted by JProReTaRD (Post 826410)
Hi, I followed a guide to nVault, but I can't seem to get it to save.
I checked the vault, but its empty.
I would really appreciate some help or guidance :)

When did you check your vault for data and what did you use to check it?

If you check the vault immediately after using a set command then you will not see the entry in your vault file. You must either do a map-change or restart the server for the data to get written to the vault file.

nVault is very simple to use; as long as your nvault file opens without error then your data should be getting written with nvault_set\nvault_pset. If you have any questions feel free to ask.

Look at the 2nd nvault_set, you need to change the szXP variable to szLevel and possibly PlayerClass[] to something else. Someone was copy and pasting :grrr:
PHP Code:

    formatexszKey 39 "%s-%i-XP" g_szAuthID[id], PlayerClass[id] );
    
formatexszXP "%d" PlayerXP[id] );
    
    
nvault_setg_Vault ,szKey szXP );
    
    
formatexszKey 39 "%s-%i-Level" g_szAuthID[id], PlayerClass[id] );  //Change variables?
    
formatexszLevel "%d" PlayerLevel[id] );
    
    
nvault_setg_Vault ,szKey szXP ); //Change szXP to szLevel? 


JProReTaRD 05-13-2009 12:07

Re: nVault won save, Please help :)
 
Ty for a good answer, but it doesn't work. :cry:

Quote:

Originally Posted by Bugsy (Post 826501)
When did you check your vault for data and what did you use to check it?

If you check the vault immediately after using a set command then you will not see the entry in your vault file. You must either do a map-change or restart the server for the data to get written to the vault file.

nVault is very simple to use; as long as your nvault file opens without error then your data should be getting written with nvault_set\nvault_pset. If you have any questions feel free to ask.

Look at the 2nd nvault_set, you need to change the szXP variable to szLevel and possibly PlayerClass[] to something else. Someone was copy and pasting :grrr:
PHP Code:

    formatexszKey 39 "%s-%i-XP" g_szAuthID[id], PlayerClass[id] );
    
formatexszXP "%d" PlayerXP[id] );
    
    
nvault_setg_Vault ,szKey szXP );
    
    
formatexszKey 39 "%s-%i-Level" g_szAuthID[id], PlayerClass[id] );  //Change variables?
    
formatexszLevel "%d" PlayerLevel[id] );
    
    
nvault_setg_Vault ,szKey szXP ); //Change szXP to szLevel? 



I checked after restart and mapchange, but there is nothing. (I use nVault-editor)

Actually, I did copy-paste from nVault tutorial bc I though, then it would work :P - and it's on purpose that its PlayerClass[id] both times, bc it should save xp and level for a certain class :) and ty for correcting my szXP :P

I really need some help :| and I would really appreciate if you could take a look at my code and correct it - or guide me like you did in this post :)

Regards
ReTaRD

Bugsy 05-13-2009 18:37

Re: nVault won save, Please help :)
 
No problem, Retard (chuckle)

I don't think it's an issue with nVault as it is really hard to screw up nvault code.

I would do some debugging with the other parts of your plugin that actually call the nvault_set(). Have you checked server console and\or logs to make sure the plugin isn't throwing any errors?

PHP Code:

new iVault nvault_open"test" );

if ( 
iVault == INVALID_HANDLE )
    
set_fail_state"nvault error" );

nvault_setiVault "key" "data" );

nvault_closeiVault ); 


JProReTaRD 05-14-2009 03:06

Re: nVault won save, Please help :)
 
What did you call me? :twisted: (Just kidding)

I checked the console and there are no errors (I have it on debug mode).

I have already tried to debug, but with no luck, that's why I ask for help from geniouses like you :P


Regards
ReTaRD

Bugsy 05-14-2009 10:10

Re: nVault won save, Please help :)
 
I just did a test using your code and it is saving. You should consider saving all of a players data in 1 vault entry instead of multiple.

PlayerClass[id] will always be 0 when a player first connects so any value you intended on being there for loading is not. If you need to store player class then you may need another vault entry [using the current way] or if you change to use 1 vault entry just include PlayerClass[] in the saved data.
Code:
public LoadXP(id) {     new szKey[40];     formatex( szKey , 39 , "%s-%i-XP" , g_szAuthID[id], PlayerClass[id] );     PlayerXP[id] = nvault_get( g_Vault , szKey );         formatex( szKey , 39 , "%s-%i-Level" , g_szAuthID[id], PlayerClass[id] );     PlayerLevel[id] = nvault_get( g_Vault , szKey );     client_print( id , print_chat , "* Your XP: %d and Level: %i was loaded." , PlayerXP[id], PlayerLevel[id] ); }

As you can see, data is being saved using your code:
http://img.photobucket.com/albums/v2...ona/nvault.jpg

JProReTaRD 05-14-2009 11:19

Re: nVault won save, Please help :)
 
Thank you for your help, but I am really noob to this Pawn thing :P

I need to save xp and lvl to playerclasses of steamID. (Like Warcraft mod)
Ie.

Steam:0:0:342423525-CLASS_BHOPPER-XP 302
Steam:0:0:342423525-CLASS_BHOPPER-Level 3

Steam:0:0:342423525-CLASS_BHOPPER-XP 120
Steam:0:0:342423525-CLASS_BHOPPER-Level 1


And That is what I don't know how to do :(
And is "*.vault" located in "data/" or "data/vault/" ?

I am very sorry for all those noob requests and questions :P


Regards
ReTaRD

Bugsy 05-14-2009 11:22

Re: nVault won save, Please help :)
 
data/vault/hns-xp-mod.vault

That is fine but you need to think of the logic here. You are trying to use PlayerClass[id] to load data when a player connects. This value will ALWAYS be 0 so you need some other method of storing class. Think of it this way, when the player disconnects it will save PlayerClass as you wish: STEAMID-2-XP but then you try to load it using PlayerClass [this value will be 0 on a newly connecting player] when the player re-connects, your nvault_get key will be STEAMID-0-XP. See how this method will not work?

You should also set all player variables to 0 on disconnect so they aren't accidentally used for the next player that connects in that slot.

Consider saving data in this format. When the player connects, you just parse out the data and assign it to the appropriate variables.

Key=STEAM_0:0:12345
Data=90:1:1 [XP, level, class]

PHP Code:

formatexszData 10 "%d:%d:%d" iXP[id] , iLevel[id], iClass[id] );
nvault_setg_Vault g_szAuthID[id] , szData ); 


JProReTaRD 05-14-2009 12:35

Re: nVault won save, Please help :)
 
Why do you write iXP[id] when I already have PlayerXP[id] ? :|
I feel very stupid atm :P

And if you do this:
Key=STEAM_0:0:12345
Data=90:1:1 [XP, level, class]

Then it can't save xp to one class then another, right? :?

I would think more like:

Key=STEAM_0:0:12345-Class1
Data=90:1:1 [XP, level]
Key=STEAM_0:0:12345-Class2
Data=90:1:1 [XP, level]


I can see the 0 problem, but it will not loadXP() until a class is picked and then the PlayerClass[id] won't be 0 - Right?


Regards
ReTaRD


All times are GMT -4. The time now is 01:35.

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