Raised This Month: $ Target: $400
 0% 

nVault won save, Please help :)


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
JProReTaRD
Member
Join Date: May 2009
Location: Denmark, KBH
Old 05-12-2009 , 16:11   nVault won save, Please help :)
Reply With Quote #1

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;


Last edited by JProReTaRD; 05-12-2009 at 16:13.
JProReTaRD is offline
 



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 01:36.


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