Thread: [Solved] Level XP System
View Single Post
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 11-22-2016 , 03:41   Re: Level XP System
Reply With Quote #8

Quote:
Originally Posted by edon1337 View Post
I copied it from another code. I'm still confused. Can you post the exact code because i'm confused from your comments, also you didn't use "vaultkey" anywhere.
Ok, let my explain ... when you save in nvault, nvault.inc CREATE private files where to save ... in dava/vault ok ?

Why people using prefixses or sufixes ? like LEVELMOD_%S for keys .. why ? Because that's how we save in old times when we was using the normal vault, vault.inc NOT nvault.inc, because Vault.inc don't create private files, all of the plugins wich use vault.inc save all the keys and data in vault.ini from vault.

To do not mix them we using prefixes or specials symbols , Just thiink if they are five plugins wich all using keys as name, one saving models, one frags, one deaths.

"Craxor" "1"
"Craxor "Vip.mdl"
"Craxor" "0"

wich is imposibile, Nvault create separate files so you can use put directly the name as a key or steamid (better) because only one plugin wich use nvault will create a private file for that plugin wich use nvault.

nvault_open( "VaultName" );


Ok ... now ? How Nvault Save ...

You will use nvault natives to save inside of the vault file, the syntax is like that:

"Key" , "Data" , "Timpestamp"

Ignore timestamp and other stuffs if you're begginer, focus only on key / data.

So, let me tell you logicaly: You're saving a KEY , and each key have own DATA, but the key is one wich you use to retrive the data.

In your case the key is SteamID and data is Level and Xp, will save both of them as a single string and parse them into 2 args:

PHP Code:
public SaveData(id)  
{  
    new 
AuthID[35
    
get_user_authid(id,AuthIDcharsmaxAuthID ) );  
    
    new 
vaultdata[64];  

    
format(vaultdatacharsmaxvaultdata ),"%i %i",g_PlayerXP[id],g_PlayerLevel[id]);  
    
    
nvault_setvaultAuthIdvaultdata ); 
    return 
PLUGIN_CONTINUE  
}  



public 
LoadDataid )
{

    
/////        We create 2 variables to insert Xp and and level
    /////    Data is look like "level xp"
    /////    Let's say the user have level 1 and 0 xp, and his name is "Craxor"
    /////    (key -> ) "Craxor"  (Data-> ) "1 0"    , you should use Nvault Edito to open vault files, will be more easy.
   
    
new LevelArg[11], XpArg[11];
    
///////////////////////////



    ///// Here as you see we get User Steam Id ( wich is the key )
    
new AuthId[35];
    
get_user_authididAuthIDcharsmaxAuthID ) );
)
    
///// We create a empty string variable, and we FORMAT IT with The data User

    
new DataBuffer[64];


    
///// All we need is the Vault Id , the key ( wich is Steam not name, sorry .., and a empty string to format it )

    
nvault_getvaultAuthIdDataBuffercharsmaxDataBuffer ) );


    
///// We parse/split the string into 2 arg.
    
parseDataBufferXpArgcharsmaxXpArg ), LevelArgcharsmaxLevelArg ) );


    
///// We set the player level/xp and convert the strings into numbers.    
    
g_PlayerLeve[id] = str_to_numLevelArg );
    
g_PlayerXP[id] = str_to_numXpArg );

    return 
PLUGIN_HANDLED;    

But in any case, for multiple info like this i would use nvault utility.

If you have any question for proper understand, ask.


Edit: About your natives:

Code:
public native_set_user_xp(id, amount) {     g_PlayerXP[id] = amount

You do not format them correct, when you register natives, they aren't like stocks, you neet to use othe natives to call each parameter, like that:

Code:
public native_set_user_xp(Index, Params) {     g_PlayerXP[ get_param(1) ] = get_param(2)
__________________
Project: Among Us

Last edited by Craxor; 11-22-2016 at 04:04.
Craxor is offline
Send a message via ICQ to Craxor