Raised This Month: $ Target: $400
 0% 

[SOLVED] Saving upgrades with nVault


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 10-25-2015 , 11:00   [SOLVED] Saving upgrades with nVault
Reply With Quote #1

I'm trying to save the player's upgrades with nVault.

PHP Code:
new g_iUpgrades[33][33
PHP Code:
new const g_szUpgrades[][] = {
    
"Increase Alien Speed""2130""Your ^3Alien running speed ^1is now ^4increased",
    
"Additional Alien Health""2650""You will now get more ^3health points ^1as an ^4Alien",
    
"Additional predator Health""3200""You will now get more ^3health points ^1as a ^4Predator",
    
"Decrease Scream Cooldown""750""You can now ^3scream ^1more often",
    
"Unlock Ultra Classes""5000""You now have access to the ^3Ultra Classes^1"

PHP Code:
public SaveData(idszAuthId[35])
{
    new 
szVaultKey[64], szVaultData[256]
    
format(szVaultKeycharsmax(szVaultKey), "%s"szAuthId)
    
    for(new 
0sizeof(g_szUpgrades) - 2+= 3)
        
add(szVaultDatacharsmax(szVaultData), "%i#"g_iUpgrades[id][i])
    
    
nvault_set(g_VaultszVaultKeyszVaultData)
    return 
PLUGIN_CONTINUE
}

LoadData(id)
{
    new 
szAuthId[35], szVaultKey[64], szVaultData[256]
    
get_user_authid(idszAuthIdcharsmax(szAuthId))
    
format(szVaultKeycharsmax(szVaultKey), "%s"szAuthId)
    
    for(new 
0sizeof(g_szUpgrades) - 2+= 3)
        
add(szVaultDatacharsmax(szVaultData), "%i#"g_iUpgrades[id][i])
    
    
nvault_get(g_VaultszVaultKeyszVaultDatacharsmax(szVaultData))
    
replace_all(szVaultDatacharsmax(szVaultData), "#"" ")
    
    
/* The "fun" part starts here */
    
new szUpgrades[32]
    
    for(new 
0sizeof(g_szUpgrades) - 2+= 3)
    {
        
parse(szVaultDataszUpgrades1)
        
g_iUpgrades[id][i] = str_to_num(szUpgrades[i])
    }
    
/* This code doesn't work */
    
    
return PLUGIN_CONTINUE

PHP Code:
stock set_upgrade(idiUpgrade)
    
g_iUpgrades[id][iUpgrade] = 1

stock is_upgraded
(idiUpgrade)
    return 
g_iUpgrades[id][iUpgrade
I'm used to saving things with only one number, but I have no idea how to save a value that has two arrays - g_iUpgrades[id][iUpgrade]. The "iUpgrade" is the upgrade's ID, according to "g_szUpgrades", so it can be 0, 3, 6, 9, 12... Is this even a good way of saving the upgrades?

Last edited by OciXCrom; 10-27-2015 at 15:43.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-25-2015 , 11:13   Re: Saving upgrades with nVault
Reply With Quote #2

Could use a bitsum to record each players upgrade status and then store the resulting numerical value to nvault.

So you would have 5 upgrades as you do in your list. If the player has upgrades 1 and 3, their bitsum would look like 00000101 [1<<0 OR 1<<2] which is equal to "5". I can write this for you later.
__________________

Last edited by Bugsy; 10-25-2015 at 11:13.
Bugsy is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 10-25-2015 , 11:25   Re: Saving upgrades with nVault
Reply With Quote #3

Thank you, I would appreciate it. I'm not familiar with bitsums yet. Also, would adding an upgrade in the future affect the saved data?
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-25-2015 , 12:40   Re: Saving upgrades with nVault
Reply With Quote #4

It would have no impact. This method allows up to 32 updates. If you really needed more it could be accomplished
__________________
Bugsy is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 10-25-2015 , 13:22   Re: Saving upgrades with nVault
Reply With Quote #5

Good, I won't need that many.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Depresie
Veteran Member
Join Date: Nov 2013
Old 10-25-2015 , 13:34   Re: Saving upgrades with nVault
Reply With Quote #6

im wondering, if you are trying to create abilities that can be upgraded multiple times, for example upgrade health to lvl 2, lvl 3 etc how should the array be written?
Depresie is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 10-25-2015 , 13:37   Re: Saving upgrades with nVault
Reply With Quote #7

That probably won't change much, because now if you have an upgrade, the array is g_iUpgrade[id][iUpgrade] = 1, so for the next level it would just be equal to 2.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-25-2015 , 15:35   Re: Saving upgrades with nVault
Reply With Quote #8

So does each of your 5 upgrades in your original post have multiple levels, or is it just a yes/no for each?
__________________
Bugsy is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 10-25-2015 , 15:57   Re: Saving upgrades with nVault
Reply With Quote #9

It's only yes/no.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-25-2015 , 17:04   Re: Saving upgrades with nVault
Reply With Quote #10

Untested

Edit: Added load\save data on authorized\disconnect.
PHP Code:

#include <amxmodx>
#include <nvault>

new const szVersion[] = "0.1";

const 
MAXPLAYERS 32;

enum UpgradeTypes
{
    
utIncAlienSpeed,
    
utAddAlienHealth,
    
utAddPredHealth,
    
utDecrScreamCooldown,
    
utUnlockUltraClasses
}

enum UpgradeInfo
{
    
szDescription64 ],
    
iValue,
    
szMessage64 ]
}

new const 
g_UpgradesUpgradeTypes ][ UpgradeInfo ] = 
{
    { 
"Increase Alien Speed" 2130 "Your ^3Alien running speed ^1is now ^4increased" } ,
    { 
"Additional Alien Health" 2650 "You will now get more ^3health points ^1as an ^4Alien" } ,
    { 
"Additional predator Health" 3200 "You will now get more ^3health points ^1as a ^4Predator" } ,
    { 
"Decrease Scream Cooldown" 750 "You can now ^3scream ^1more often" } ,
    { 
"Unlock Ultra Classes" 5000 "You now have access to the ^3Ultra Classes^1" }
};

new 
g_PlayerUpgradesMAXPLAYERS ];
new 
g_szAuthIDMAXPLAYERS ][ 34 ];
new 
g_Vault;

public 
plugin_init() 
{
    
register_plugin"Upgrade Example" szVersion "bugsy" );

    if ( ( 
g_Vault nvault_open"upgrades" ) ) == INVALID_HANDLE )
        
set_fail_state"Error opening nvault" );
}

public 
plugin_end()
{
    
nvault_closeg_Vault );
}

public 
client_authorizedid )
{
    
get_user_authidid g_szAuthIDid ] , charsmaxg_szAuthID[] ) );
    
LoadUpgradesid );
}

public 
client_disconnectid )
{
    
SaveUpgradesid );
}

public 
AddUpgradeiPlayer UpgradeTypes:utUpgrade )
{
    
g_PlayerUpgradesiPlayer ] |= ( << _:utUpgrade );
    
    
client_printiPlayer print_chat "%s upgrade added: %s" g_UpgradesutUpgrade ][ szDescription ] , g_UpgradesutUpgrade ][ szMessage ] );
}

public 
RemoveUpgradeiPlayer UpgradeTypes:utUpgrade )
{
    
g_PlayerUpgradesiPlayer ] &= ~( << _:utUpgrade );
    
    
client_printiPlayer print_chat "%s upgrade has been removed" g_UpgradesutUpgrade ][ szDescription ] );
}

public 
ClearUpgradesiPlayer UpgradeTypes:utUpgrade )
{
    
g_PlayerUpgradesiPlayer ] = _:0;
    
    
client_printiPlayer print_chat "All upgrades have been removed" );
}

public 
bool:PlayerHasUpgradeiPlayer UpgradeTypes:utUpgrade )
{
    return 
bool:!!( g_PlayerUpgradesiPlayer ] & ( << _:utUpgrade ) );
}

public 
SaveUpgradesid )
{
    new 
szVal12 ];
    
    
num_to_strg_PlayerUpgradesid ] , szVal charsmaxszVal ) );
    
nvault_setg_Vault g_szAuthIDid ] , szVal );
}

public 
LoadUpgradesid )
{
    
g_PlayerUpgradesid ] = nvault_getg_Vault g_szAuthIDid ] );

__________________

Last edited by Bugsy; 10-26-2015 at 16:45.
Bugsy is offline
Reply



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 22:14.


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