AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Saving Xp and Level. (https://forums.alliedmods.net/showthread.php?t=127759)

SaM.ThE.MaN 05-24-2010 14:17

Saving Xp and Level.
 
Hi,

I am making a plugin and i am having a problem saving and loading xp and level. Here is the code i am using :
PHP Code:

 TO save 
public 
SaveXP(id)
{
    new 
authid[32]; 
    
get_user_authid(id,authid,31); 

    new 
vaultkey[64], vaultdata[64]; 

    
//Save their XP
    
format(vaultkey,63,"Level-%s-xp",authid); 
    
format(vaultdata,63,"%d",PlayerXP[id]); 
    
set_vaultdata(vaultkey,vaultdata); 

    
//Save their level
    
format(vaultkey,63,"Level-%s-level",authid); 
    
format(vaultdata,63,"%d",PlayerLevel[id]); 
    
set_vaultdata(vaultkey,vaultdata);


PHP Code:

 To load:
public 
LoadXP(id)
{
    new 
authid[32]; 
    
get_user_authid(id,authid,31); 

    new 
vaultkey[64], vaultdata[64]; 

     
//Load their XP
    
format(vaultkey,63,"Level-%s-xp",authid); 
    
get_vaultdata(vaultkey,vaultdata,63); 
    
PlayerXP[id] = str_to_num(vaultdata);   

    
//Load their level
    
format(vaultkey,63,"Level-%s-level",authid); 
    
get_vaultdata(vaultkey,vaultdata,63);
    
PlayerLevel[id] = str_to_num(vaultdata);  


But each time i close and open the server the info gets deleted, i want it to stay on for ever each time i connect open and close the server.
Help :D

drekes 05-24-2010 15:33

Re: Saving Xp and Level.
 
make sure you load on client_connect() and save on plugin_end()

Xellath 05-24-2010 15:37

Re: Saving Xp and Level.
 
Quote:

Originally Posted by drekes (Post 1190015)
make sure you load on client_connect() and save on client_disconnect()

Fixed.

Exolent[jNr] 05-24-2010 15:46

Re: Saving Xp and Level.
 
Quote:

Originally Posted by drekes (Post 1190015)
make sure you load on client_connect() and save on plugin_end()

Load on client_authorized().
Save on client_disconnect().

SaM.ThE.MaN 05-24-2010 16:29

Re: Saving Xp and Level.
 
i do have load on connecting and save on disconnecting,i can give u the full coding.

Exolent[jNr] 05-24-2010 16:34

Re: Saving Xp and Level.
 
Trying using NVault and see if that makes a difference.

SaM.ThE.MaN 05-24-2010 16:38

Re: Saving Xp and Level.
 
i do have load on connecting and save on disconnecting,i can give u the full coding.
I'm using nVault.

Exolent[jNr] 05-24-2010 16:48

Re: Saving Xp and Level.
 
Quote:

Originally Posted by SaM.ThE.MaN (Post 1189935)
PHP Code:

set_vaultdata(vaultkey,vaultdata); 

PHP Code:

get_vaultdata(vaultkey,vaultdata,63); 


That is not NVault.

SaM.ThE.MaN 05-25-2010 02:44

Re: Saving Xp and Level.
 
I have taken the save and load scrips from another tutorial.

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <vault>
#include <core>
#include <fun>

#define PLUGIN "Level Plugin"
#define VERSION "0.1"
#define AUTHOR "SaMThEMaN"

new PlayerXP[33]
new 
PlayerLevel[33]

new const 
LEVELS[6] = 
{
    
1
    
2
    
4
    
8,
    
16,
    
32
}

new 
msgtext

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_cvar("sv_Leveler""1")
    
register_event("DeathMsg""DeathMsg""a"
    
register_clcmd("say /level""Level")
    
register_clcmd("say_team /level""Level")
    
register_cvar("XP_per_kill""1")
}

public 
Level(id)
{
client_print(idprint_chat"^x04[Leveler] You are level %d and you have  %d XP"PlayerLevel[id], PlayerXP[id])
}

public 
SaveXP(id)
{
    new 
authid[32]; 
    
get_user_authid(id,authid,31); 

    new 
vaultkey[64], vaultdata[64]; 

    
format(vaultkey,63,"Plvl-%s-xp",authid); 
    
format(vaultdata,63,"%d",PlayerXP[id]); 
    
set_vaultdata(vaultkey,vaultdata); 

    
format(vaultkey,63,"Plvl-%s-level",authid); 
    
format(vaultdata,63,"%d",PlayerLevel[id]); 
    
set_vaultdata(vaultkey,vaultdata);


public 
LoadXP(id)
{
    new 
authid[32]; 
    
get_user_authid(id,authid,31); 

    new 
vaultkey[64], vaultdata[64];

    
format(vaultkey,63,"Plvl-%s-xp",authid); 
    
get_vaultdata(vaultkey,vaultdata,63); 
    
PlayerXP[id] = str_to_num(vaultdata);   

    
format(vaultkey,63,"Plvl-%s-level",authid); 
    
get_vaultdata(vaultkey,vaultdata,63);
    
PlayerLevel[id] = str_to_num(vaultdata);  


public 
client_connect(id)
{
    if(
get_cvar_num("SaveXP") == 1) {
       
         
LoadXP(id)

         
client_print(idprint_chat"[Leveler] XP Loaded!")
         
client_print(idprint_chat"[Leveler] You are level %d and %d XP"PlayerLevel[id], PlayerXP[id])
    }
}

public 
client_disconnect(id)
{
    if(
get_cvar_num("SaveXP") == 1) {
    
         
SaveXP(id)
    }
}

public 
DeathMsg()
{
if(
get_cvar_num("sv_Leveler") == 0
{
return 
PLUGIN_HANDLED
}
    new 
attacker read_data(1)

    
PlayerXP[attacker] += get_cvar_num("XP_per_kill")

    if(
PlayerXP[attacker] >= LEVELS[PlayerLevel[attacker]]) {
    
PlayerLevel[attacker] += 1

    client_print
(attackerprint_chat"[Leveler] Congratulations! You are now level [%d]!"PlayerLevel[attacker])
    if(
get_cvar_num("SaveXP") == 1) {
 
             
SaveXP(attacker)
         }
         
ShowHUD(attacker)
    }   
    
ShowHUD(attacker)
    
    return 
PLUGIN_CONTINUE
}

public 
ShowHUD(id)    

    new 
HUD[51
    
    
//This is the stuff that will actually show in game.
    
format(HUD50"Level: %d XP: %d"PlayerLevel[id], PlayerXP[id]) 

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



JaGareN 05-25-2010 04:44

Re: Saving Xp and Level.
 
Quote:

Originally Posted by SaM.ThE.MaN (Post 1190451)
I have taken the save and load scrips from another tutorial.

At the top :arrow:
PHP Code:

#include <nvault> 

somewhere in the plugin :arrow:
PHP Code:

new gVault

In plugin_init :arrow:
PHP Code:

gVault nvault_open("YourModName"); 

In plugin_end :arrow:
PHP Code:

nvault_close(gVault); 

In your Save function :arrow:
PHP Code:

nvault_set(gVault,vaultkey,vaultdata); 

In your Load function :arrow:
PHP Code:

nvault_get(gVault,vaultkey,vaultdata,63); 



All times are GMT -4. The time now is 05:19.

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