AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Save level based on class (XP Mod) (https://forums.alliedmods.net/showthread.php?t=143761)

GXLZPGX 11-24-2010 14:03

Save level based on class (XP Mod)
 
I noticed in the XP mod tutorial by Flyeni6, it only saves their level.

PHP Code:

public SaveData(id

    
// get the players steam id. We need this because we are saving by steam id 
    
new AuthID[35get_user_authid(id,AuthID,34
    new 
vaultkey[64],vaultdata[256
    
// format wat is going to be in the animal mod vault file 
    
format(vaultkey,63,"%s-Mod",AuthID
    
format(vaultdata,255,"%i#%i#",PlayerXP[id],PlayerLevel[id]) 
    
// save the data 
    
nvault_set(g_vault,vaultkey,vaultdata
    return 
PLUGIN_CONTINUE 


So no matter what class they are, they're level will always be the same. How can I save seperate levels for each class?

Exolent[jNr] 11-24-2010 16:06

Re: Save level based on class (XP Mod)
 
Combine SteamID and the class name, then use that for the nvault key.

GXLZPGX 11-24-2010 16:36

Re: Save level based on class (XP Mod)
 
Quote:

Originally Posted by Exolent[jNr] (Post 1355932)
Combine SteamID and the class name, then use that for the nvault key.

Thanks ;)

Another thing is, there are two classes, and the first class (warriors), get two types of stats, strength and dexterity, and the second class (assassins) has agility and transparency. How would I save those seperately as well?

Exolent[jNr] 11-24-2010 16:38

Re: Save level based on class (XP Mod)
 
SteamID + class name + stat name = stat value

GXLZPGX 11-24-2010 16:44

Re: Save level based on class (XP Mod)
 
Quote:

Originally Posted by Exolent[jNr] (Post 1355957)
SteamID + class name + stat name = stat value

Not exactly asking you to do it for me, but could you explain that a bit better? How would I configure the vault key?

PHP Code:

public Save_Data(id)
{
    new 
AuthID[35]
    
get_user_authidid,AuthID,34 
    
    new 
VaultKey[64], VaultData[256]
    
    
format(VaultKey63"%s-wva-%i-class"AuthIDpub_Class[id])
    
format(VaultData255"%i#%i#"pub_Experience[id], pub_Level[id]) 
    
    
nvault_set(g_VaultVaultKeyVaultData



Exolent[jNr] 11-24-2010 16:51

Re: Save level based on class (XP Mod)
 
Well if you're one of those people that likes to have multiple values in an nvault entry then that method is fine.
I personally like using 1 value per key so I can just use nvault_get() to return the integer.

GXLZPGX 11-24-2010 16:53

Re: Save level based on class (XP Mod)
 
Quote:

Originally Posted by Exolent[jNr] (Post 1355973)
Well if you're one of those people that likes to have multiple values in an nvault entry then that method is fine.
I personally like using 1 value per key so I can just use nvault_get() to return the integer.

Well I've never used nvault any other way. Care to show an example?

Exolent[jNr] 11-24-2010 17:00

Re: Save level based on class (XP Mod)
 
Here's an example of how I would've done the code in your first post.

PHP Code:

public SaveData(id

    new 
AuthID[35]
    
get_user_authid(id,AuthID,34)
    
    new 
vaultkey[64], vaultdata[11]
    
formatex(vaultkey,63,"%s-xp",AuthID)
    
num_to_str(PlayerXP[id],vaultdata,10)
    
nvault_set(g_vault,vaultkeyvaultdata)
    
    
formatex(vaultkey,63,"%s-level",AuthID)
    
num_to_str(PlayerLevel[id],vaultdata,10)
    
nvault_set(g_vault,vaultkeyvaultdata)


PHP Code:

public LoadData(id)
{
    new 
AuthID[35]
    
get_user_authid(id,AuthID,34)
    
    new 
vaultkey[64]
    
formatex(vaultkey,63,"%s-xp",AuthID)
    
PlayerXP[id] = nvault_get(g_vault,vaultkey)
    
    
formatex(vaultkey,63,"%s-level",AuthID)
    
PlayerLevel[id] = nvault_get(g_vault,vaultkey)



GXLZPGX 11-24-2010 17:03

Re: Save level based on class (XP Mod)
 
Quote:

Originally Posted by Exolent[jNr] (Post 1355986)
Here's an example of how I would've done the code in your first post.

PHP Code:

public SaveData(id

    new 
AuthID[35]
    
get_user_authid(id,AuthID,34)
    
    new 
vaultkey[64], vaultdata[11]
    
formatex(vaultkey,63,"%s-xp",AuthID)
    
num_to_str(PlayerXP[id],vaultdata,10)
    
nvault_set(g_vault,vaultkeyvaultdata)
    
    
formatex(vaultkey,63,"%s-level",AuthID)
    
num_to_str(PlayerLevel[id],vaultdata,10)
    
nvault_set(g_vault,vaultkeyvaultdata)


PHP Code:

public LoadData(id)
{
    new 
AuthID[35]
    
get_user_authid(id,AuthID,34)
    
    new 
vaultkey[64]
    
formatex(vaultkey,63,"%s-xp",AuthID)
    
PlayerXP[id] = nvault_get(g_vault,vaultkey)
    
    
formatex(vaultkey,63,"%s-level",AuthID)
    
PlayerLevel[id] = nvault_get(g_vault,vaultkey)



Well the way I see it, if I used your method, then no matter what class the person is, their level would stay the same. So now we're back to the reason why I created the topic.

Exolent[jNr] 11-24-2010 17:06

Re: Save level based on class (XP Mod)
 
Quote:

Originally Posted by GXLZPGX (Post 1355991)
Well the way I see it, if I used your method, then no matter what class the person is, their level would stay the same. So now we're back to the reason why I created the topic.

I told you that it was an example based on the code in your first post.
All you have to do is add the class name to the level key (and the xp key if you have xp per class).


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

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