Raised This Month: $ Target: $400
 0% 

Saving Xp and Level.


Post New Thread Closed Thread   
 
Thread Tools Display Modes
Author Message
SaM.ThE.MaN
Senior Member
Join Date: Jan 2010
Old 05-24-2010 , 14:17   Saving Xp and Level.
#1

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
SaM.ThE.MaN is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 05-24-2010 , 15:33   Re: Saving Xp and Level.
#2

make sure you load on client_connect() and save on plugin_end()
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
Xellath
Veteran Member
Join Date: Dec 2007
Location: Sweden
Old 05-24-2010 , 15:37   Re: Saving Xp and Level.
#3

Quote:
Originally Posted by drekes View Post
make sure you load on client_connect() and save on client_disconnect()
Fixed.
__________________
Achievements API - a simple way for you to create your OWN custom achievements!
Xellath is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 05-24-2010 , 15:46   Re: Saving Xp and Level.
#4

Quote:
Originally Posted by drekes View Post
make sure you load on client_connect() and save on plugin_end()
Load on client_authorized().
Save on client_disconnect().
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
SaM.ThE.MaN
Senior Member
Join Date: Jan 2010
Old 05-24-2010 , 16:29   Re: Saving Xp and Level.
#5

i do have load on connecting and save on disconnecting,i can give u the full coding.
SaM.ThE.MaN is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 05-24-2010 , 16:34   Re: Saving Xp and Level.
#6

Trying using NVault and see if that makes a difference.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
SaM.ThE.MaN
Senior Member
Join Date: Jan 2010
Old 05-24-2010 , 16:38   Re: Saving Xp and Level.
#7

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

Last edited by Alka; 05-24-2010 at 16:45.
SaM.ThE.MaN is offline
Old 05-24-2010, 16:43
SaM.ThE.MaN
This message has been deleted by Alka. Reason: Black Berry xD
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 05-24-2010 , 16:48   Re: Saving Xp and Level.
#9

Quote:
Originally Posted by SaM.ThE.MaN View Post
PHP Code:
set_vaultdata(vaultkey,vaultdata); 
PHP Code:
get_vaultdata(vaultkey,vaultdata,63); 
That is not NVault.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
SaM.ThE.MaN
Senior Member
Join Date: Jan 2010
Old 05-25-2010 , 02:44   Re: Saving Xp and Level.
#10

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

SaM.ThE.MaN is offline
Closed Thread



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 05:19.


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