AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Level XP System (https://forums.alliedmods.net/showthread.php?t=290692)

edon1337 11-20-2016 15:20

Level XP System
 
-delete-

Depresie 11-20-2016 17:04

Re: Level XP System
 
You have no idea what you wrote there... i'm wondering how it works at all...
Cannot help you right now, but search a tutorial on task ids around the forums, it looks like you have no idea how to set a task and remove it

edon1337 11-21-2016 08:14

Re: Level XP System
 
Quote:

Originally Posted by Depresie (Post 2471580)
You have no idea what you wrote there... i'm wondering how it works at all...
Cannot help you right now, but search a tutorial on task ids around the forums, it looks like you have no idea how to set a task and remove it

I saw lots of tutorials but still not sure. As I don't have an Online server right now, it's kinda hard for me so I posted here. I edited the post, if you don't understand this time, then, you need to improve your English.

Craxor 11-21-2016 08:17

Re: Level XP System
 
PHP Code:

public SaveData(id)  
{  
    new 
AuthID[35
    
get_user_authid(id,AuthID,34)  
    new 
vaultkey[64],vaultdata[256]  
     
    
// WHY ? AuthId already is a string.
    // Why the sufix "-Mod" ? Is not VAULT, It is nvault, it create private files for each VAULT man.

    //format(vaultkey,63,"%s-Mod",AuthID)  


   //  You don't need to separate them with '#' put both of the them and use parse();
    
format(vaultdata,255,"%i#%i#",g_PlayerXP[id],g_PlayerLevel[id])  
    

 
    
//nvault_set(vault,vaultkey,vaultdata)  
     
nvault_setvaultAuthIDvaultdata);
    return 
PLUGIN_CONTINUE  



edon1337 11-21-2016 14:48

Re: Level XP System
 
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.

Depresie 11-21-2016 16:58

Re: Level XP System
 
Idk if the saving/loading functions are correct, but you surely messed up when it comes to player ids and tasks...

edon1337 11-21-2016 18:54

Re: Level XP System
 
Quote:

Originally Posted by Depresie (Post 2471799)
Idk if the saving/loading functions are correct, but you surely messed up when it comes to player ids and tasks...

Yeah, I have.

Craxor 11-22-2016 03:41

Re: Level XP System
 
Quote:

Originally Posted by edon1337 (Post 2471772)
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)

edon1337 11-22-2016 05:32

Re: Level XP System
 
Thank You, there was some small typos in your nVault code but I fixed it, Also about the natives, I honestly knew that i needed to use get_param but somebody told me my method was ok so I skipped it. Edited my post.

Craxor 11-22-2016 06:18

Re: Level XP System
 
About natives - > Who told you that? Did you test it ?

Btw, in my code the only wrong thing is that i use format() insteand of formatex().

Anyway, my no#1 advice is to take 'each' native from nvault.inc and try to study each one in part to understand in a deep way how it works, take time, is not easy at the beginning.

However, your code works now on testing?

Edit: Also you should call SaveData(id) in client_disconnect and LoadData in client_authorized.


nvault_open native and rest of stuff from plugin_cfg() you can safety use in plugin_init() even if is same you don't need to do that there, just for sake of my dear <3 .



from levelsay: new name[33], change 33 to 32. and you have lloooot of things to change but i have no more time, sorry :D


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

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